Skip to content

Commit

Permalink
issue-1922: properly tracking BlobsCount to guarantee the BlobsCount …
Browse files Browse the repository at this point in the history
…<= real blob count in range property (#2017)
  • Loading branch information
qkrorlqr authored Oct 15, 2024
1 parent 44229e0 commit c4f1132
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 17 deletions.
40 changes: 26 additions & 14 deletions cloud/filestore/libs/storage/tablet/tablet_actor_addblob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,11 @@ class TAddBlobsExecutor
TABLET_VERIFY(!args.UnalignedDataParts);

for (auto& blob: args.SrcBlobs) {
Tablet.UpdateBlockLists(db, blob);
const auto rangeId = Tablet.GetMixedRangeIndex(blob.Blocks);
auto& stats = AccessCompactionStats(rangeId);
if (!Tablet.UpdateBlockLists(db, blob)) {
stats.BlobsCount = Max(stats.BlobsCount, 1U) - 1;
}
}

for (auto& block: args.SrcBlocks) {
Expand Down Expand Up @@ -303,31 +307,39 @@ class TAddBlobsExecutor
for (const auto& blob: args.SrcBlobs) {
const auto rangeId = Tablet.GetMixedRangeIndex(blob.Blocks);
auto& stats = AccessCompactionStats(rangeId);
// Zeroing compaction counter for the overwritten blobs.
stats.BlobsCount = 0;
// Decrementing compaction counter for the overwritten blobs.
// The counter is not guaranteed to be perfectly in sync with the
// actual blob count in range so a check for moving below zero is
// needed.
stats.BlobsCount = Max(1U, stats.BlobsCount) - 1;
Tablet.DeleteMixedBlocks(db, blob.BlobId, blob.Blocks);
}

THashMap<ui32, ui32> rangeId2AddedBlobsCount;
for (auto& blob: args.MixedBlobs) {
const auto rangeId = Tablet.GetMixedRangeIndex(blob.Blocks);
auto& stats = AccessCompactionStats(rangeId);
// Incrementing blobs count as there could be multiple blobs
// per compacted range see NBS-4424
if (Tablet.WriteMixedBlocks(db, blob.BlobId, blob.Blocks)) {
++stats.BlobsCount;

// If BlobsCount >= CompactionThreshold, then Compaction will
// enter an infinite loop
// A simple solution is to limit BlobsCount by threshold - 1
if (stats.BlobsCount >= CompactionThreshold
&& CompactionThreshold > 1)
{
stats.BlobsCount = CompactionThreshold - 1;
}
++rangeId2AddedBlobsCount[rangeId];
}
}

for (const auto& [rangeId, addedBlobsCount]: rangeId2AddedBlobsCount) {
auto& stats = AccessCompactionStats(rangeId);

// If addedBlobsCount >= compactionThreshold, then Compaction will
// enter an infinite loop
// A simple solution is to limit addedBlobsCount by threshold - 1
auto increment = addedBlobsCount;
if (increment >= CompactionThreshold && CompactionThreshold > 1) {
increment = CompactionThreshold - 1;
}
stats.BlobsCount += increment;
}
}


void UpdateCompactionMap(
TIndexTabletDatabase& db,
TTxIndexTablet::TAddBlob& args)
Expand Down
2 changes: 1 addition & 1 deletion cloud/filestore/libs/storage/tablet/tablet_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,7 @@ FILESTORE_DUPCACHE_REQUESTS(FILESTORE_DECLARE_DUPCACHE)
ui32 rangeId,
NProto::TProfileLogRequestInfo& profileLogRequest);

void UpdateBlockLists(
bool UpdateBlockLists(
TIndexTabletDatabase& db,
TMixedBlobMeta& blob);

Expand Down
4 changes: 2 additions & 2 deletions cloud/filestore/libs/storage/tablet/tablet_state_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -858,13 +858,13 @@ void TIndexTabletState::MarkMixedBlocksDeleted(
InvalidateReadAheadCache(nodeId);
}

void TIndexTabletState::UpdateBlockLists(
bool TIndexTabletState::UpdateBlockLists(
TIndexTabletDatabase& db,
TMixedBlobMeta& blob)
{
const auto rangeId = GetMixedRangeIndex(blob.Blocks);
DeleteMixedBlocks(db, rangeId, blob.BlobId, blob.Blocks);
WriteMixedBlocks(db, rangeId, blob.BlobId, blob.Blocks);
return WriteMixedBlocks(db, rangeId, blob.BlobId, blob.Blocks);
}

ui32 TIndexTabletState::CleanupBlockDeletions(
Expand Down

0 comments on commit c4f1132

Please sign in to comment.