Skip to content

chore(server): Introduce read budget to prep for tagged chunk loading#7109

Merged
abhijat merged 4 commits into
mainfrom
abhijat/chore/prep-chunk-load
Apr 22, 2026
Merged

chore(server): Introduce read budget to prep for tagged chunk loading#7109
abhijat merged 4 commits into
mainfrom
abhijat/chore/prep-chunk-load

Conversation

@abhijat
Copy link
Copy Markdown
Contributor

@abhijat abhijat commented Apr 10, 2026

This PR is a preparatory step towards #7070 to make the diff smaller and easier to review. The PR produces no functional changes.

The main change introduced here is a chunk state. This remains unset in this PR.

A chunk budget is also introduced. This budget is to be read from a tagged chunk header. This budget also remains unlimited in this PR.

Essentially the budget checks here are no-ops, but they prepare for the next PR where tagged chunk header will be read, the budget will be set and the read functions will return at exact chunk boundaries.

Two other changes introduced here:

  • make SBF loading work with chunks - now we can split sbf filters, the code in the loader is changed to handle these splits
  • fix an issue with streams where chunk could split after listpacks and before tail data
  • A helper called ReadAndDispatchObject introduced. It makes the inner loop of LoadKeyValPair isolated, which will be reused in later PR feat(server): Implement tagged chunk loading #7070 to load chunks of a value.

@abhijat abhijat changed the title chore(server): Introduce chunk budget to prep for chunk loading chore(server): Introduce read budget to prep for tagged chunk loading Apr 10, 2026
@abhijat abhijat marked this pull request as ready for review April 13, 2026 09:41
Copilot AI review requested due to automatic review settings April 13, 2026 09:41
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Prepares the RDB loader/saver pipeline for upcoming “tagged chunk” loading (PR #7070) by introducing chunk budget accounting hooks and refactoring loader dispatch so value loading can later stop/resume at chunk boundaries.

Changes:

  • Introduce chunk budget/state plumbing in RdbLoaderBase and refactor LoadKeyValPair inner loop into ReadAndDispatchObject.
  • Update SBF loading to support split/partial filter reads (to work with filter chunking and future tagged chunking).
  • Prevent stream serialization from flushing between the final listpack and the stream metadata tail.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
src/server/rdb_save.cc Avoids flushing after the last stream listpack so tail metadata stays bundled.
src/server/rdb_load.h Adds chunk-budget state/hooks and SBF partial-filter continuation state; refactors chunked-value tracking key.
src/server/rdb_load.cc Implements budget consumption helpers, refactors load dispatch, and extends SBF loading for partial filter reads.
src/server/rdb_extensions.h Adds opcode constant for upcoming tagged chunk support.

Comment thread src/server/rdb_load.cc Outdated
@augmentcode
Copy link
Copy Markdown

augmentcode Bot commented Apr 13, 2026

🤖 Augment PR Summary

Summary: This PR prepares the RDB loader for upcoming “tagged chunk” loading by introducing a (currently no-op) per-chunk read budget and plumbing partial-read boundaries through the object-loading loop.

Changes:

  • Added a new RDB opcode constant (RDB_OPCODE_TAGGED_CHUNK) to support tagged chunk payloads.
  • Introduced chunk-budget tracking in RdbLoaderBase (ConsumeInput, ConsumeChunkBudget, ChunkBudgetExhausted) and replaced direct buffer consumption in key read paths.
  • Updated collection readers (set/hash/zset/quicklist/streams) to stop at budget boundaries and record remaining elements for continuation.
  • Refactored the inner load loop into ReadAndDispatchObject to isolate “read part + dispatch” logic for reuse in chunked loading.
  • Made SBF/SBF2 loading compatible with chunk splits by supporting filters encoded as multiple chunks and resuming mid-filter via PendingRead::sbf_filter.
  • Adjusted chunked-value tracking to key now_chunked_ by (db index, key) to avoid cross-DB collisions.
  • Prevented stream serialization from flushing between the final listpack and the stream metadata tail to keep loader expectations consistent.

Technical Notes: The chunk state and budget remain effectively unlimited in this PR; the new checks are intended to be activated by a follow-up that parses tagged chunk headers and sets per-chunk limits.

🤖 Was this summary useful? React with 👍 or 👎

Copy link
Copy Markdown

@augmentcode augmentcode Bot left a comment

Choose a reason for hiding this comment

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

Review completed. 1 suggestion posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

Comment thread src/server/rdb_load.cc
@abhijat abhijat force-pushed the abhijat/chore/prep-chunk-load branch 2 times, most recently from 642e835 to 423b5c5 Compare April 15, 2026 10:53
dranikpg
dranikpg previously approved these changes Apr 20, 2026
Comment thread src/server/rdb_load.cc Outdated
Comment on lines +2521 to +2522
if (n > current_chunk_state_->remaining_payload_bytes)
return RdbError(errc::rdb_file_corrupted);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I would advise some log here or in the call chains because it will be very difficult to debug an error with rdb_file_corrupted and no other data. Alternatively we can split rdb_file_corrupted into multiple corrupted codes

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I added a log and also added new error codes for short and over read, as the next PR has more such places.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Comment thread src/server/error.h
Comment thread src/server/rdb_load.cc
abhijat added 3 commits April 21, 2026 15:58
Skip PushToConsumerIfNeeded after the last listpack in SaveStreamObject.
The stream metadata tail (length, IDs, consumer groups) must stay
bundled with the last listpack chunk so the loader can read it in the
same chunk.
@abhijat abhijat force-pushed the abhijat/chore/prep-chunk-load branch from d4ccedc to c9d40d4 Compare April 21, 2026 10:30
@abhijat abhijat merged commit fa9392f into main Apr 22, 2026
13 checks passed
@abhijat abhijat deleted the abhijat/chore/prep-chunk-load branch April 22, 2026 10:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants