Skip to content

Commit

Permalink
Merge 746fe13 into 065294c
Browse files Browse the repository at this point in the history
  • Loading branch information
va-kuznecov authored Sep 16, 2024
2 parents 065294c + 746fe13 commit 8339d7d
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 38 deletions.
13 changes: 12 additions & 1 deletion ydb/core/blobstorage/pdisk/blobstorage_pdisk_crypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@ namespace NPDisk {
////////////////////////////////////////////////////////////////////////////

class TPDiskHashCalculator : public THashCalculator {
bool UseT1ha0Hasher;

public:
// T1ha0 hash is default for current version, but old hash is used to test backward compatibility
TPDiskHashCalculator(bool useT1ha0Hasher = true)
: UseT1ha0Hasher(useT1ha0Hasher)
{}

ui64 OldHashSector(const ui64 sectorOffset, const ui64 magic, const ui8 *sector,
const ui32 sectorSize) {
REQUEST_VALGRIND_CHECK_MEM_IS_DEFINED(&sectorOffset, sizeof sectorOffset);
Expand Down Expand Up @@ -39,7 +46,11 @@ class TPDiskHashCalculator : public THashCalculator {

ui64 HashSector(const ui64 sectorOffset, const ui64 magic, const ui8 *sector,
const ui32 sectorSize) {
return T1ha0HashSector<TT1ha0NoAvxHasher>(sectorOffset, magic, sector, sectorSize);
if (UseT1ha0Hasher) {
return T1ha0HashSector<TT1ha0NoAvxHasher>(sectorOffset, magic, sector, sectorSize);
} else {
return OldHashSector(sectorOffset, magic, sector, sectorSize);
}
}

bool CheckSectorHash(const ui64 sectorOffset, const ui64 magic, const ui8 *sector,
Expand Down
78 changes: 41 additions & 37 deletions ydb/core/blobstorage/pdisk/blobstorage_pdisk_util_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,22 +331,24 @@ void TestPayloadOffset(ui64 firstSector, ui64 lastSector, ui64 currentSector, ui
TSectorsWithData sectors(format.SectorSize, LogErasureDataParts + 1);
constexpr ui64 magic = 0x123951924;
ui64 nonce = 1;
for (ui32 i = 0; i < LogErasureDataParts + 1; ++i) {
memset(sectors[i].Begin(), 0, sectors[i].Size());
sectors[i].SetCanary();
auto *footer = sectors[i].GetDataFooter();
footer->Version = PDISK_DATA_VERSION;
footer->Nonce = nonce++;
NPDisk::TPDiskHashCalculator hasher;
if (i < LogErasureDataParts) {
ui64 offset = format.SectorSize * i;
footer->Hash = hasher.HashSector(offset, magic, sectors[i].Begin(), sectors[i].Size());
for (ui32 useT1haHash = 0; useT1haHash < 2; ++useT1haHash) {
for (ui32 i = 0; i < LogErasureDataParts + 1; ++i) {
memset(sectors[i].Begin(), 0, sectors[i].Size());
sectors[i].SetCanary();
auto *footer = sectors[i].GetDataFooter();
footer->Version = PDISK_DATA_VERSION;
footer->Nonce = nonce++;
NPDisk::TPDiskHashCalculator hasher(useT1haHash);
if (i < LogErasureDataParts) {
ui64 offset = format.SectorSize * i;
footer->Hash = hasher.HashSector(offset, magic, sectors[i].Begin(), sectors[i].Size());
}
}
TSectorRestorator restorator(false, LogErasureDataParts, true, format);
restorator.Restore(sectors.Data(), 0, magic, 0, 0);
UNIT_ASSERT_C(restorator.GoodSectorCount == LogErasureDataParts + 1,
"restorator.GoodSectorCount# " << restorator.GoodSectorCount);
}
TSectorRestorator restorator(false, LogErasureDataParts, true, format);
restorator.Restore(sectors.Data(), 0, magic, 0, 0);
UNIT_ASSERT_C(restorator.GoodSectorCount == LogErasureDataParts + 1,
"restorator.GoodSectorCount# " << restorator.GoodSectorCount);
}

Y_UNIT_TEST(SectorRestoratorOldNewHash) {
Expand All @@ -356,30 +358,32 @@ void TestPayloadOffset(ui64 firstSector, ui64 lastSector, ui64 currentSector, ui
const ui64 magic = 0x123951924;
const ui64 offset = format.SectorSize * 17;
ui64 nonce = 1;
for (ui32 i = 0; i < sectors.Size(); ++i) {
memset(sectors[i].Begin(), 13, sectors[i].Size());
sectors[i].SetCanary();
auto *footer = sectors[i].GetDataFooter();
footer->Version = PDISK_DATA_VERSION;
footer->Nonce = nonce++;
NPDisk::TPDiskHashCalculator hasher;
switch (i) {
case 0:
footer->Hash = hasher.OldHashSector(offset, magic, sectors[i].Begin(), sectors[i].Size());
break;
case 1:
footer->Hash = hasher.T1ha0HashSector<TT1ha0NoAvxHasher>(offset, magic, sectors[i].Begin(), sectors[i].Size());
break;
case 2:
footer->Hash = hasher.HashSector(offset, magic, sectors[i].Begin(), sectors[i].Size());
break;
default:
UNIT_ASSERT(false);
for (ui32 useT1haHash = 0; useT1haHash < 2; ++useT1haHash) {
for (ui32 i = 0; i < sectors.Size(); ++i) {
memset(sectors[i].Begin(), 13, sectors[i].Size());
sectors[i].SetCanary();
auto *footer = sectors[i].GetDataFooter();
footer->Version = PDISK_DATA_VERSION;
footer->Nonce = nonce++;
NPDisk::TPDiskHashCalculator hasher(useT1haHash);
switch (i) {
case 0:
footer->Hash = hasher.OldHashSector(offset, magic, sectors[i].Begin(), sectors[i].Size());
break;
case 1:
footer->Hash = hasher.T1ha0HashSector<TT1ha0NoAvxHasher>(offset, magic, sectors[i].Begin(), sectors[i].Size());
break;
case 2:
footer->Hash = hasher.HashSector(offset, magic, sectors[i].Begin(), sectors[i].Size());
break;
default:
UNIT_ASSERT(false);
}
TSectorRestorator restorator(false, 1, false, format);
restorator.Restore(sectors[i].Begin(), offset, magic, 0, 0);
UNIT_ASSERT_C(restorator.GoodSectorCount == 1, "i# " << i
<< " GoodSectorCount# " << restorator.GoodSectorCount);
}
TSectorRestorator restorator(false, 1, false, format);
restorator.Restore(sectors[i].Begin(), offset, magic, 0, 0);
UNIT_ASSERT_C(restorator.GoodSectorCount == 1, "i# " << i
<< " GoodSectorCount# " << restorator.GoodSectorCount);
}
}

Expand Down

0 comments on commit 8339d7d

Please sign in to comment.