Skip to content

Commit

Permalink
log new crc32 for each block after writing
Browse files Browse the repository at this point in the history
  • Loading branch information
BarkovBG committed Mar 28, 2024
1 parent 58a8bb3 commit 7411368
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@ func migrateDiskInParallel(

dstZoneNBSClient := testcommon.NewNbsClient(t, ctx, dstZoneID)
err := dstZoneNBSClient.ValidateCrc32(
ctx,
params.DiskID,
diskSize,
srcCrc32,
Expand All @@ -394,6 +395,7 @@ func migrateDiskInParallel(
} else {
// All migrations are cancelled. Check that src disk is not affected.
err := srcZoneNBSClient.ValidateCrc32(
ctx,
params.DiskID,
diskSize,
srcCrc32,
Expand Down Expand Up @@ -458,6 +460,7 @@ func successfullyMigrateEmptyDisk(

dstZoneNBSClient := testcommon.NewNbsClient(t, ctx, params.DstZoneID)
err = dstZoneNBSClient.ValidateCrc32(
ctx,
params.DiskID,
diskSize,
srcCrc32,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ func TestDiskServiceCreateDiskFromImageWithForceNotLayered(t *testing.T) {

nbsClient := testcommon.NewNbsClient(t, ctx, "zone-a")
err = nbsClient.ValidateCrc32(
ctx,
diskID,
testcommon.GetRawImageSize(t),
testcommon.GetRawImageCrc32(t),
Expand Down Expand Up @@ -307,6 +308,7 @@ func TestDiskServiceCreateDisksFromImageWithConfiguredPool(t *testing.T) {

diskID := fmt.Sprintf("%v%v", t.Name(), i)
err = nbsClient.ValidateCrc32(
ctx,
diskID,
imageSize,
imageCrc32,
Expand Down Expand Up @@ -442,7 +444,7 @@ func testCreateDiskFromIncrementalSnapshot(
crc32, blocksCrc32, err := nbsClient.CalculateCrc32(diskID1, diskSize)
require.NoError(t, err)

err = nbsClient.ValidateCrc32(diskID2, diskSize, crc32, blocksCrc32)
err = nbsClient.ValidateCrc32(ctx, diskID2, diskSize, crc32, blocksCrc32)
require.NoError(t, err)

testcommon.CheckConsistency(t, ctx)
Expand Down Expand Up @@ -540,10 +542,10 @@ func TestDiskServiceCreateDiskFromSnapshot(t *testing.T) {
require.NoError(t, err)
require.Equal(t, float64(1), diskMeta.Progress)

err = nbsClient.ValidateCrc32(diskID1, diskSize, crc32, blocksCrc32)
err = nbsClient.ValidateCrc32(ctx, diskID1, diskSize, crc32, blocksCrc32)
require.NoError(t, err)

err = nbsClient.ValidateCrc32(diskID2, diskSize, crc32, blocksCrc32)
err = nbsClient.ValidateCrc32(ctx, diskID2, diskSize, crc32, blocksCrc32)
require.NoError(t, err)

testcommon.CheckConsistency(t, ctx)
Expand Down Expand Up @@ -622,10 +624,10 @@ func TestDiskServiceCreateDiskFromImage(t *testing.T) {
err = internal_client.WaitOperation(ctx, client, operation.Id)
require.NoError(t, err)

err = nbsClient.ValidateCrc32(diskID1, diskSize, crc32, blocksCrc32)
err = nbsClient.ValidateCrc32(ctx, diskID1, diskSize, crc32, blocksCrc32)
require.NoError(t, err)

err = nbsClient.ValidateCrc32(diskID2, diskSize, crc32, blocksCrc32)
err = nbsClient.ValidateCrc32(ctx, diskID2, diskSize, crc32, blocksCrc32)
require.NoError(t, err)

testcommon.CheckConsistency(t, ctx)
Expand Down Expand Up @@ -754,13 +756,13 @@ func TestDiskServiceCreateDiskFromSnapshotOfOverlayDisk(t *testing.T) {
err = internal_client.WaitOperation(ctx, client, operation.Id)
require.NoError(t, err)

err = nbsClient.ValidateCrc32(diskID1, imageSize, crc32, blocksCrc32)
err = nbsClient.ValidateCrc32(ctx, diskID1, imageSize, crc32, blocksCrc32)
require.NoError(t, err)

err = nbsClient.ValidateCrc32(diskID2, imageSize, crc32, blocksCrc32)
err = nbsClient.ValidateCrc32(ctx, diskID2, imageSize, crc32, blocksCrc32)
require.NoError(t, err)

err = nbsClient.ValidateCrc32(diskID3, imageSize, crc32, blocksCrc32)
err = nbsClient.ValidateCrc32(ctx, diskID3, imageSize, crc32, blocksCrc32)
require.NoError(t, err)

testcommon.CheckConsistency(t, ctx)
Expand Down Expand Up @@ -1147,6 +1149,7 @@ func TestDiskServiceCreateEncryptedDiskFromSnapshot(t *testing.T) {
require.ErrorContains(t, err, "encryption mode should be the same")

err = nbsClient.ValidateCrc32WithEncryption(
ctx,
diskID1,
diskSize,
encryptionDesc,
Expand All @@ -1155,6 +1158,7 @@ func TestDiskServiceCreateEncryptedDiskFromSnapshot(t *testing.T) {
)
require.NoError(t, err)
err = nbsClient.ValidateCrc32WithEncryption(
ctx,
diskID2,
diskSize,
encryptionDesc,
Expand Down
24 changes: 23 additions & 1 deletion cloud/disk_manager/internal/pkg/facade/testcommon/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,14 @@ func FillEncryptedDisk(
if err != nil {
return 0, []uint32{}, 0, err
}

logging.Debug(
ctx,
"%v block with index %v crc32 now is %v",
diskID,
startIndex+uint64(blockIndex),
blockAcc.Sum32(),
)
blocksCrc32 = append(blocksCrc32, blockAcc.Sum32())
}
}
Expand Down Expand Up @@ -476,10 +484,11 @@ func GoWriteRandomBlocksToNbsDisk(
dice := rand.Intn(2)

var err error
blockAcc := crc32.NewIEEE()
data := make([]byte, blockSize)

switch dice {
case 0:
data := make([]byte, blockSize)
rand.Read(data)
if bytes.Equal(data, zeroes) {
logging.Debug(ctx, "rand generated all zeroes")
Expand All @@ -493,6 +502,19 @@ func GoWriteRandomBlocksToNbsDisk(
if err != nil {
return err
}

_, err = blockAcc.Write(data)
if err != nil {
return err
}

logging.Debug(
ctx,
"%v block with index %v crc32 now is %v",
diskID,
blockIndex,
blockAcc.Sum32(),
)
}

return nil
Expand Down

0 comments on commit 7411368

Please sign in to comment.