Skip to content

Commit

Permalink
fix incorrect cookie choosing
Browse files Browse the repository at this point in the history
  • Loading branch information
kruall committed Feb 6, 2024
1 parent ab4b0a4 commit b96502c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 14 deletions.
4 changes: 4 additions & 0 deletions ydb/core/base/blobstorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -1468,6 +1468,10 @@ struct TEvBlobStorage {
}
}

static ui8 BlobPlacementKind(const TLogoBlobID &blob) {
return blob.Hash() % BaseDomainsCount;
}

static bool GetBlobIdWithSamePlacement(const TLogoBlobID &originalId, TLogoBlobID *patchedId,
ui32 bitsForBruteForce, ui32 originalGroupId, ui32 currentGroupId)
{
Expand Down
4 changes: 2 additions & 2 deletions ydb/core/blobstorage/dsproxy/mock/model.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,11 @@ namespace NFake {
// TODO(kruall): check bad diffs
TString buffer = TString::Uninitialized(data.Buffer.GetSize());
auto originalBuffer = data.Buffer.GetContiguousSpan();
memcpy(buffer.begin(), originalBuffer.data(), buffer.size());
memcpy(buffer.Detach(), originalBuffer.data(), buffer.size());
for (ui32 diffIdx = 0; diffIdx < msg->DiffCount; ++diffIdx) {
auto &diff = msg->Diffs[diffIdx];
auto diffBuffer = diff.Buffer.GetContiguousSpan();
memcpy(buffer.begin() + diff.Offset, diffBuffer.data(), diffBuffer.size());
memcpy(buffer.Detach() + diff.Offset, diffBuffer.data(), diffBuffer.size());
}


Expand Down
23 changes: 12 additions & 11 deletions ydb/core/keyvalue/keyvalue_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -765,15 +765,18 @@ TLogoBlobID TKeyValueState::AllocateLogoBlobId(ui32 size, ui32 storageChannelIdx
return id;
}

TLogoBlobID TKeyValueState::AllocatePatchedLogoBlobId(ui32 size, ui32 storageChannelIdx, ui64 originalGroupId, ui64 currentGroupId, ui64 requestUid) {
TLogoBlobID TKeyValueState::AllocatePatchedLogoBlobId(ui32 size, ui32 storageChannelIdx, TLogoBlobID originalBlobId, ui64 requestUid) {
ui32 generation = ExecutorGeneration;
TLogoBlobID id(TabletId, generation, NextLogoBlobStep, storageChannelIdx, size, NextLogoBlobCookie);
TEvBlobStorage::TEvPatch::GetBlobIdWithSamePlacement(id, &id, TLogoBlobID::MaxCookie, originalGroupId, currentGroupId);
if (id.Cookie() < TLogoBlobID::MaxCookie) {
NextLogoBlobCookie = id.Cookie() + 1;
} else {
Step();
}
TLogoBlobID id;
using TEvPatch = TEvBlobStorage::TEvPatch;
do {
id = TLogoBlobID(TabletId, generation, NextLogoBlobStep, storageChannelIdx, size, NextLogoBlobCookie);
if (NextLogoBlobCookie < TLogoBlobID::MaxCookie) {
NextLogoBlobCookie++;
} else {
Step();
}
} while (TEvPatch::BlobPlacementKind(id) != TEvPatch::BlobPlacementKind(originalBlobId));
Y_ABORT_UNLESS(!CollectOperation || THelpers::GenerationStep(id) >
THelpers::TGenerationStep(CollectOperation->Header.GetCollectGeneration(), CollectOperation->Header.GetCollectStep()));
++InFlightForStep[id.Step()];
Expand Down Expand Up @@ -3082,9 +3085,7 @@ void TKeyValueState::RegisterRequestActor(const TActorContext &ctx, THolder<TInt

auto fixPatch = [&](TIntermediate::TPatch& patch) {
Y_ABORT_UNLESS(patch.PatchedBlobId.TabletID() == 0);
ui64 originalGroupId = info->GroupFor(patch.OriginalBlobId.Channel(), patch.OriginalBlobId.Generation());
ui64 patchedGroupId = info->GroupFor(patch.PatchedBlobId.Channel(), patch.PatchedBlobId.Generation());
patch.PatchedBlobId = AllocatePatchedLogoBlobId(patch.PatchedBlobId.BlobSize(), patch.PatchedBlobId.Channel(), originalGroupId, patchedGroupId, intermediate->RequestUid);
patch.PatchedBlobId = AllocatePatchedLogoBlobId(patch.PatchedBlobId.BlobSize(), patch.PatchedBlobId.Channel(), patch.OriginalBlobId, intermediate->RequestUid);
ui32 newRefCount = ++RefCounts[patch.PatchedBlobId];
Y_ABORT_UNLESS(newRefCount == 1);
intermediate->RefCountsIncr.emplace_back(patch.PatchedBlobId, true);
Expand Down
2 changes: 1 addition & 1 deletion ydb/core/keyvalue/keyvalue_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ class TKeyValueState {

void Step();
TLogoBlobID AllocateLogoBlobId(ui32 size, ui32 storageChannelIdx, ui64 requestUid);
TLogoBlobID AllocatePatchedLogoBlobId(ui32 size, ui32 storageChannelIdx, ui64 originalGroupId, ui64 currentGroupId, ui64 requestUid);
TLogoBlobID AllocatePatchedLogoBlobId(ui32 size, ui32 storageChannelIdx, TLogoBlobID originalBlobId, ui64 requestUid);
TIntrusivePtr<TCollectOperation>& GetCollectOperation() {
return CollectOperation;
}
Expand Down

0 comments on commit b96502c

Please sign in to comment.