diff --git a/ydb/core/blobstorage/pdisk/blobstorage_pdisk_crypto.h b/ydb/core/blobstorage/pdisk/blobstorage_pdisk_crypto.h index d82291cd20a1..5eec0c63e14b 100644 --- a/ydb/core/blobstorage/pdisk/blobstorage_pdisk_crypto.h +++ b/ydb/core/blobstorage/pdisk/blobstorage_pdisk_crypto.h @@ -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(§orOffset, sizeof sectorOffset); @@ -39,7 +46,11 @@ class TPDiskHashCalculator : public THashCalculator { ui64 HashSector(const ui64 sectorOffset, const ui64 magic, const ui8 *sector, const ui32 sectorSize) { - return T1ha0HashSector(sectorOffset, magic, sector, sectorSize); + if (UseT1ha0Hasher) { + return T1ha0HashSector(sectorOffset, magic, sector, sectorSize); + } else { + return OldHashSector(sectorOffset, magic, sector, sectorSize); + } } bool CheckSectorHash(const ui64 sectorOffset, const ui64 magic, const ui8 *sector, diff --git a/ydb/core/blobstorage/pdisk/blobstorage_pdisk_util_ut.cpp b/ydb/core/blobstorage/pdisk/blobstorage_pdisk_util_ut.cpp index b2eb928db9c9..243f2b8a09e9 100644 --- a/ydb/core/blobstorage/pdisk/blobstorage_pdisk_util_ut.cpp +++ b/ydb/core/blobstorage/pdisk/blobstorage_pdisk_util_ut.cpp @@ -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) { @@ -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(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(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); } }