Skip to content

Commit 07d38e3

Browse files
authored
Return usefull unit tests removed in commit 'Remove KIKIMR_PDISK_ENABLE_T1HA_HASH_WRITING' (#9326)
1 parent 6befac2 commit 07d38e3

File tree

2 files changed

+53
-38
lines changed

2 files changed

+53
-38
lines changed

ydb/core/blobstorage/pdisk/blobstorage_pdisk_crypto.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,14 @@ namespace NPDisk {
1111
////////////////////////////////////////////////////////////////////////////
1212

1313
class TPDiskHashCalculator : public THashCalculator {
14+
bool UseT1ha0Hasher;
15+
1416
public:
17+
// T1ha0 hash is default for current version, but old hash is used to test backward compatibility
18+
TPDiskHashCalculator(bool useT1ha0Hasher = true)
19+
: UseT1ha0Hasher(useT1ha0Hasher)
20+
{}
21+
1522
ui64 OldHashSector(const ui64 sectorOffset, const ui64 magic, const ui8 *sector,
1623
const ui32 sectorSize) {
1724
REQUEST_VALGRIND_CHECK_MEM_IS_DEFINED(&sectorOffset, sizeof sectorOffset);
@@ -39,7 +46,11 @@ class TPDiskHashCalculator : public THashCalculator {
3946

4047
ui64 HashSector(const ui64 sectorOffset, const ui64 magic, const ui8 *sector,
4148
const ui32 sectorSize) {
42-
return T1ha0HashSector<TT1ha0NoAvxHasher>(sectorOffset, magic, sector, sectorSize);
49+
if (UseT1ha0Hasher) {
50+
return T1ha0HashSector<TT1ha0NoAvxHasher>(sectorOffset, magic, sector, sectorSize);
51+
} else {
52+
return OldHashSector(sectorOffset, magic, sector, sectorSize);
53+
}
4354
}
4455

4556
bool CheckSectorHash(const ui64 sectorOffset, const ui64 magic, const ui8 *sector,

ydb/core/blobstorage/pdisk/blobstorage_pdisk_util_ut.cpp

Lines changed: 41 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -331,22 +331,24 @@ void TestPayloadOffset(ui64 firstSector, ui64 lastSector, ui64 currentSector, ui
331331
TSectorsWithData sectors(format.SectorSize, LogErasureDataParts + 1);
332332
constexpr ui64 magic = 0x123951924;
333333
ui64 nonce = 1;
334-
for (ui32 i = 0; i < LogErasureDataParts + 1; ++i) {
335-
memset(sectors[i].Begin(), 0, sectors[i].Size());
336-
sectors[i].SetCanary();
337-
auto *footer = sectors[i].GetDataFooter();
338-
footer->Version = PDISK_DATA_VERSION;
339-
footer->Nonce = nonce++;
340-
NPDisk::TPDiskHashCalculator hasher;
341-
if (i < LogErasureDataParts) {
342-
ui64 offset = format.SectorSize * i;
343-
footer->Hash = hasher.HashSector(offset, magic, sectors[i].Begin(), sectors[i].Size());
334+
for (ui32 useT1haHash = 0; useT1haHash < 2; ++useT1haHash) {
335+
for (ui32 i = 0; i < LogErasureDataParts + 1; ++i) {
336+
memset(sectors[i].Begin(), 0, sectors[i].Size());
337+
sectors[i].SetCanary();
338+
auto *footer = sectors[i].GetDataFooter();
339+
footer->Version = PDISK_DATA_VERSION;
340+
footer->Nonce = nonce++;
341+
NPDisk::TPDiskHashCalculator hasher(useT1haHash);
342+
if (i < LogErasureDataParts) {
343+
ui64 offset = format.SectorSize * i;
344+
footer->Hash = hasher.HashSector(offset, magic, sectors[i].Begin(), sectors[i].Size());
345+
}
344346
}
347+
TSectorRestorator restorator(false, LogErasureDataParts, true, format);
348+
restorator.Restore(sectors.Data(), 0, magic, 0, 0);
349+
UNIT_ASSERT_C(restorator.GoodSectorCount == LogErasureDataParts + 1,
350+
"restorator.GoodSectorCount# " << restorator.GoodSectorCount);
345351
}
346-
TSectorRestorator restorator(false, LogErasureDataParts, true, format);
347-
restorator.Restore(sectors.Data(), 0, magic, 0, 0);
348-
UNIT_ASSERT_C(restorator.GoodSectorCount == LogErasureDataParts + 1,
349-
"restorator.GoodSectorCount# " << restorator.GoodSectorCount);
350352
}
351353

352354
Y_UNIT_TEST(SectorRestoratorOldNewHash) {
@@ -356,30 +358,32 @@ void TestPayloadOffset(ui64 firstSector, ui64 lastSector, ui64 currentSector, ui
356358
const ui64 magic = 0x123951924;
357359
const ui64 offset = format.SectorSize * 17;
358360
ui64 nonce = 1;
359-
for (ui32 i = 0; i < sectors.Size(); ++i) {
360-
memset(sectors[i].Begin(), 13, sectors[i].Size());
361-
sectors[i].SetCanary();
362-
auto *footer = sectors[i].GetDataFooter();
363-
footer->Version = PDISK_DATA_VERSION;
364-
footer->Nonce = nonce++;
365-
NPDisk::TPDiskHashCalculator hasher;
366-
switch (i) {
367-
case 0:
368-
footer->Hash = hasher.OldHashSector(offset, magic, sectors[i].Begin(), sectors[i].Size());
369-
break;
370-
case 1:
371-
footer->Hash = hasher.T1ha0HashSector<TT1ha0NoAvxHasher>(offset, magic, sectors[i].Begin(), sectors[i].Size());
372-
break;
373-
case 2:
374-
footer->Hash = hasher.HashSector(offset, magic, sectors[i].Begin(), sectors[i].Size());
375-
break;
376-
default:
377-
UNIT_ASSERT(false);
361+
for (ui32 useT1haHash = 0; useT1haHash < 2; ++useT1haHash) {
362+
for (ui32 i = 0; i < sectors.Size(); ++i) {
363+
memset(sectors[i].Begin(), 13, sectors[i].Size());
364+
sectors[i].SetCanary();
365+
auto *footer = sectors[i].GetDataFooter();
366+
footer->Version = PDISK_DATA_VERSION;
367+
footer->Nonce = nonce++;
368+
NPDisk::TPDiskHashCalculator hasher(useT1haHash);
369+
switch (i) {
370+
case 0:
371+
footer->Hash = hasher.OldHashSector(offset, magic, sectors[i].Begin(), sectors[i].Size());
372+
break;
373+
case 1:
374+
footer->Hash = hasher.T1ha0HashSector<TT1ha0NoAvxHasher>(offset, magic, sectors[i].Begin(), sectors[i].Size());
375+
break;
376+
case 2:
377+
footer->Hash = hasher.HashSector(offset, magic, sectors[i].Begin(), sectors[i].Size());
378+
break;
379+
default:
380+
UNIT_ASSERT(false);
381+
}
382+
TSectorRestorator restorator(false, 1, false, format);
383+
restorator.Restore(sectors[i].Begin(), offset, magic, 0, 0);
384+
UNIT_ASSERT_C(restorator.GoodSectorCount == 1, "i# " << i
385+
<< " GoodSectorCount# " << restorator.GoodSectorCount);
378386
}
379-
TSectorRestorator restorator(false, 1, false, format);
380-
restorator.Restore(sectors[i].Begin(), offset, magic, 0, 0);
381-
UNIT_ASSERT_C(restorator.GoodSectorCount == 1, "i# " << i
382-
<< " GoodSectorCount# " << restorator.GoodSectorCount);
383387
}
384388
}
385389

0 commit comments

Comments
 (0)