Skip to content

Add NewlyZeroredBlocks parameter, add GetTopByGarbageIgnoringZeroed to compaction map#5865

Open
gy2411 wants to merge 2 commits intomainfrom
users/gayurgin/add_garbage_ignoring_zeroes_counters
Open

Add NewlyZeroredBlocks parameter, add GetTopByGarbageIgnoringZeroed to compaction map#5865
gy2411 wants to merge 2 commits intomainfrom
users/gayurgin/add_garbage_ignoring_zeroes_counters

Conversation

@gy2411
Copy link
Copy Markdown
Collaborator

@gy2411 gy2411 commented Apr 30, 2026

Notes

We want to add new compaction type to avoid burst of compaction after discards of large ranges: #5815. This is the first step for it.

In this pr:

  • Introduce NewlyZeroedBlocks parameter (per compaction range)
  • In compaction map, make possible to get top range by garbage blocks count ignoring newly zeroed blocks.

See details in the issue description.

Issue

#5815

@gy2411 gy2411 added large-tests Launch large tests for PR blockstore Add this label to run only cloud/blockstore build and tests on PR labels Apr 30, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Note

This is an automated comment that will be appended during run.

🟢 linux-x86_64-relwithdebinfo target: cloud/blockstore/ (test time: 11138s): all tests PASSED for commit af5a987.

TESTS PASSED ERRORS FAILED FAILED BUILD SKIPPED MUTED?
6527 6526 0 0 0 1 0

@gy2411 gy2411 force-pushed the users/gayurgin/add_garbage_ignoring_zeroes_counters branch from af5a987 to 6754daf Compare May 5, 2026 10:58
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 5, 2026

Note

This is an automated comment that will be appended during run.

🟢 linux-x86_64-relwithdebinfo target: cloud/blockstore/ (test time: 11435s): all tests PASSED for commit 6754daf.

TESTS PASSED ERRORS FAILED FAILED BUILD SKIPPED MUTED?
6541 6540 0 0 0 1 0

Copy link
Copy Markdown

@robot-vibe-db robot-vibe-db Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI Review Summary

Verdict: ✅ No critical issues found

Critical issues

No critical issues found.

Other findings

  • Major | Medium: NewlyZeroedBlocks is not persisted to the database — after tablet restart, GarbageIgnoringZeroed will equal GarbageBlockCount, losing the protection against compaction bursts — cloud/blockstore/libs/storage/partition/part_actor_addblobs.cpp:524
  • Minor | Medium: UsedBlocksIgnoringZeroed() is defined but never called anywhere — dead code — cloud/blockstore/libs/storage/core/compaction_policy.h:86
  • Minor | Medium: UsedBlocksIgnoringZeroed() has a potential ui16 overflow — UsedBlockCount + NewlyZeroedBlocks can wrap around — cloud/blockstore/libs/storage/core/compaction_policy.h:88
  • Minor | Low: TRangeStat parameterized constructor does not include NewlyZeroedBlocks — callers must rely on the default zero-init, easy to miss when extending — cloud/blockstore/libs/storage/core/compaction_policy.h:45

This review was generated automatically. Critical issues require attention; other findings are advisory.
If this comment was useful, please give it a 👍 — it helps us improve the review bot.

kv.second.Stat.BlockCount + kv.second.BlocksSkippedByCompaction
);
kv.second.Stat.BlockCount +
kv.second.BlocksSkippedByCompaction);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Severity: Major
Confidence: Medium

NewlyZeroedBlocks is computed and passed to CompactionMap.Update() but is not persisted by db.WriteCompactionMap(), which only writes blobCount and blockCount. After a tablet restart, ReadCompactionMap() constructs TRangeStat with NewlyZeroedBlocks = 0 for every range.

This means GarbageIgnoringZeroed() will equal GarbageBlockCount() after restart, so the protection against compaction bursts following large discards is lost until new writes re-accumulate the tracking data. If a large discard happened right before a restart, the very burst this feature is designed to prevent could occur on startup.

If this is intentional for the "first step" (as described in the PR), consider adding a comment here explaining the transient nature of NewlyZeroedBlocks and tracking the persistence work as a follow-up.

ui16 UsedBlocksIgnoringZeroed() const
{
return UsedBlockCount + NewlyZeroedBlocks;
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Severity: Minor
Confidence: Medium

Two issues with UsedBlocksIgnoringZeroed():

  1. Dead code: This method is defined but never called anywhere in the codebase. If it is intended for a future PR, consider deferring its introduction to when it is actually used.

  2. Potential ui16 overflow: UsedBlockCount + NewlyZeroedBlocks can exceed ui16 max (65535) if both values are large, causing a silent wrap-around. While MaxBlocksCount is 1024, the values are clamped at ui16 max by UpdateCompactionCounter, so an overflow is theoretically possible.

Suggested fix for overflow (if the method is kept):

ui16 UsedBlocksIgnoringZeroed() const
{
    return static_cast<ui16>(Min(
        static_cast<ui32>(UsedBlockCount) + NewlyZeroedBlocks,
        static_cast<ui32>(Max<ui16>())));
}

ui16 ReadRequestCount = 0;
ui16 ReadRequestBlobCount = 0;
ui16 ReadRequestBlockCount = 0;
ui16 NewlyZeroedBlocks = 0;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Severity: Minor
Confidence: Low

The NewlyZeroedBlocks field is added here with a default value of 0, but the parameterized constructor (lines 45-65) does not accept or initialize it. This is consistent with how ReadCompactionMap constructs TRangeStat (since NewlyZeroedBlocks is not persisted), but it creates a subtle inconsistency: a TRangeStat built via the parameterized constructor will always have NewlyZeroedBlocks = 0 regardless of intent.

Consider adding a comment near the constructor noting that NewlyZeroedBlocks is intentionally omitted because it is transient/in-memory only.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 7, 2026

Note

This is an automated comment that will be appended during run.

🟢 linux-x86_64-relwithdebinfo target: cloud/blockstore/ (test time: 11440s): all tests PASSED for commit 6754daf.

TESTS PASSED ERRORS FAILED FAILED BUILD SKIPPED MUTED?
6541 6540 0 0 0 1 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai_reviewed blockstore Add this label to run only cloud/blockstore build and tests on PR large-tests Launch large tests for PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants