Skip to content

Commit

Permalink
Revert "Remove OldHashSector in PDisk (ydb-platform#6465)" (ydb-platf…
Browse files Browse the repository at this point in the history
…orm#9232)

Co-authored-by: Vlad Kuznecov <va-kuznecov@nebius.com>
  • Loading branch information
va-kuznecov and Vlad Kuznecov authored Sep 16, 2024
1 parent 8561c6b commit 946e6a2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
19 changes: 18 additions & 1 deletion ydb/core/blobstorage/pdisk/blobstorage_pdisk_crypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,19 @@ namespace NPDisk {

class TPDiskHashCalculator : public THashCalculator {
public:
ui64 OldHashSector(const ui64 sectorOffset, const ui64 magic, const ui8 *sector,
const ui32 sectorSize) {
REQUEST_VALGRIND_CHECK_MEM_IS_DEFINED(&sectorOffset, sizeof sectorOffset);
REQUEST_VALGRIND_CHECK_MEM_IS_DEFINED(&magic, sizeof magic);
REQUEST_VALGRIND_CHECK_MEM_IS_DEFINED(sector, sectorSize - sizeof(ui64));

THashCalculator::Clear();
THashCalculator::Hash(&sectorOffset, sizeof sectorOffset);
THashCalculator::Hash(&magic, sizeof magic);
THashCalculator::Hash(sector, sectorSize - sizeof(ui64));
return THashCalculator::GetHashResult();
}

template<class THasher>
ui64 T1ha0HashSector(const ui64 sectorOffset, const ui64 magic, const ui8 *sector,
const ui32 sectorSize) {
Expand All @@ -31,7 +44,11 @@ class TPDiskHashCalculator : public THashCalculator {

bool CheckSectorHash(const ui64 sectorOffset, const ui64 magic, const ui8 *sector,
const ui32 sectorSize, const ui64 sectorHash) {
return sectorHash == T1ha0HashSector<TT1ha0NoAvxHasher>(sectorOffset, magic, sector, sectorSize);
// On production servers may be two versions.
// If by default used OldHash version, then use it first
// If by default used T1ha0NoAvx version, then use it
return sectorHash == T1ha0HashSector<TT1ha0NoAvxHasher>(sectorOffset, magic, sector, sectorSize)
|| sectorHash == OldHashSector(sectorOffset, magic, sector, sectorSize);
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ void TSectorRestorator::Restore(ui8 *source, const ui64 offset, const ui64 magic
(ErasureDataParts, ErasureDataParts),
(Sector, i),
(ReadHash, sectorFooter->Hash),
(CalculatedOldHash, hasher.OldHashSector(sectorOffset, magic, sectorData, Format.SectorSize)),
(CalculatedT1ha0NoAvxHash, hasher.T1ha0HashSector<TT1ha0NoAvxHasher>(sectorOffset, magic, sectorData, Format.SectorSize)),
(SectorOffset, sectorOffset),
(chunkIdx, sectorOffset / (ui64)Format.ChunkSize),
Expand Down
5 changes: 4 additions & 1 deletion ydb/core/blobstorage/pdisk/blobstorage_pdisk_util_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,14 +356,17 @@ 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 = 1; i < sectors.Size(); ++i) {
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;
Expand Down

0 comments on commit 946e6a2

Please sign in to comment.