Skip to content

Forkless, background iteration utility (forkless)#3553

Open
JimB123 wants to merge 42 commits into
valkey-io:forklessfrom
JimB123:forkless-bgiterator
Open

Forkless, background iteration utility (forkless)#3553
JimB123 wants to merge 42 commits into
valkey-io:forklessfrom
JimB123:forkless-bgiterator

Conversation

@JimB123

@JimB123 JimB123 commented Apr 23, 2026

Copy link
Copy Markdown
Member

The heart of forkless save (also forkless sync and forkless slot migration) is the bgIteration utility.

bgIteration is responsible for presenting a view of the database, possibly with replication, to achieve the requested consistency.

Important concepts:

  • bgIteration is a utility which performs iteration over the database with the intent to present this iteration to a "bgIteration client". It is analogous to any other iterator. It has no specific knowledge of the reason for iteration. It can be used for any purpose.
  • A "bgIteration client" receives iteration data from bgIteration. It is expected that the bgIteration client works in the background (on another thread). The bgIteration client is not permitted to modify the data during iteration. The bgIteration client understands the reason for iteration. (Threadsave is the bgIteration client responsible for forkless save - and is not included in this PR.)
  • A "consistent" iteration offers point-in-time consistency. This is the type of consistency needed for snapshot (bgsave). In a consistent iteration, all key/value data must be presented (to the bgIteration client) - as it existed at the point of consistency - before any modifications may be permitted.
  • A "non-consistent" iteration doesn't maintain consistency from the start of iteration. Instead, it presents key/value pairs as they exist currently in the database. The guarantees are similar to other iterators. If a value is created during the iteration, it may or may not be presented as part of the iteration.
  • An iteration may contain replication. Replication is a filtered view of replication which presents replication data related to key/values which have already been iterated (and new values being created). When replication is combined with a non-consistent iteration, it's possible to achieve consistency at the END of the iteration.

The current use case, forkless save, will use a consistent iteration without replication.
Full sync will use a non-consistent iteration, with replication. This allows consistency to be achieved by the end of the syncronization.

There is currently no use case for consistent with replication or non-consistent without replication. However such use cases may be developed in the future. They are fully supported and tested.

Read the documentation in bgiteration.h for more details.

@JimB123 JimB123 force-pushed the forkless-bgiterator branch from ca38ccc to 206635b Compare April 23, 2026 22:36
@JimB123

JimB123 commented Apr 23, 2026

Copy link
Copy Markdown
Member Author

This replaces previous draft version (which was against a different branch). #3432

@codecov

codecov Bot commented Apr 23, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 59.32203% with 24 lines in your changes missing coverage. Please review.
✅ Project coverage is 77.44%. Comparing base (6b8bd41) to head (c930dc5).

Files with missing lines Patch % Lines
src/server.c 54.83% 14 Missing ⚠️
src/hashtable.c 20.00% 8 Missing ⚠️
src/defrag.c 50.00% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##           forkless    #3553      +/-   ##
============================================
+ Coverage     76.64%   77.44%   +0.79%     
============================================
  Files           159      161       +2     
  Lines         79575    82109    +2534     
============================================
+ Hits          60994    63590    +2596     
+ Misses        18581    18519      -62     
Files with missing lines Coverage Δ
src/bgiteration.c 92.31% <ø> (ø)
src/db.c 94.60% <100.00%> (+0.23%) ⬆️
src/expire.c 98.13% <100.00%> (+0.01%) ⬆️
src/object.c 87.48% <100.00%> (-3.19%) ⬇️
src/server.h 100.00% <ø> (ø)
src/unit/custom_matchers.hpp 100.00% <100.00%> (ø)
src/unit/test_bgiteration.cpp 99.78% <ø> (ø)
src/defrag.c 80.92% <50.00%> (-0.20%) ⬇️
src/hashtable.c 97.05% <20.00%> (-0.77%) ⬇️
src/server.c 89.47% <54.83%> (-0.03%) ⬇️

... and 14 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread src/hashtable.c Outdated
Comment thread src/bgiteration.c Outdated
Comment thread src/bgiteration.c Outdated
JimB123 added a commit that referenced this pull request Apr 28, 2026
…#3575)

Alt branch merging for Threadsave development. The real PR (for review)
is at #3553

This submission is temporary - and will be replaced by the result of
#3553

Signed-off-by: Jim Brunner <brunnerj@amazon.com>

@murphyjacob4 murphyjacob4 left a comment

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.

Not a full review - but want to publish some comments to unblock discussion

Comment thread src/bgiteration.h Outdated
Comment thread src/bgiteration.h Outdated
Comment thread src/bgiteration.h Outdated
Comment thread src/server.c Outdated
Comment thread src/server.c Outdated
Comment thread src/replication.c Outdated
Comment thread src/bgiteration.c Outdated
Comment thread src/bgiteration.c
@coderabbitai

coderabbitai Bot commented May 14, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 8e069dc0-54bc-4510-968b-6eff8a6d02c7

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@JimB123 JimB123 marked this pull request as ready for review May 20, 2026 22:23
@JimB123 JimB123 changed the title Draft: Forkless, background iteration utility (forkless) Forkless, background iteration utility (forkless) May 20, 2026
@JimB123

This comment was marked as outdated.

Comment thread src/bgiteration.c Outdated
@JimB123 JimB123 mentioned this pull request May 28, 2026
JimB123 added a commit that referenced this pull request May 28, 2026
prerequisite for threadsave. The real PR for this is being reviewed at
#3553

---------

Signed-off-by: Jim Brunner <brunnerj@amazon.com>
JimB123 added 13 commits May 29, 2026 15:03
Signed-off-by: Jim Brunner <brunnerj@amazon.com>
Signed-off-by: Jim Brunner <brunnerj@amazon.com>
Signed-off-by: Jim Brunner <brunnerj@amazon.com>
Signed-off-by: Jim Brunner <brunnerj@amazon.com>
Signed-off-by: Jim Brunner <brunnerj@amazon.com>
Signed-off-by: Jim Brunner <brunnerj@amazon.com>
Signed-off-by: Jim Brunner <brunnerj@amazon.com>
Signed-off-by: Jim Brunner <brunnerj@amazon.com>
Signed-off-by: Jim Brunner <brunnerj@amazon.com>
Signed-off-by: Jim Brunner <brunnerj@amazon.com>
Signed-off-by: Jim Brunner <brunnerj@amazon.com>
Signed-off-by: Jim Brunner <brunnerj@amazon.com>
Signed-off-by: Jim Brunner <brunnerj@amazon.com>
JimB123 added a commit that referenced this pull request May 29, 2026
prerequisite for threadsave. The real PR for this is being reviewed at
#3553

---------

Signed-off-by: harrylin98 <harrylin980107@gmail.com>
Signed-off-by: Jim Brunner <brunnerj@amazon.com>
Co-authored-by: Harry Lin <49881386+harrylin98@users.noreply.github.com>
Signed-off-by: Jim Brunner <brunnerj@amazon.com>
@JimB123

This comment was marked as outdated.

JimB123 added 11 commits May 29, 2026 21:06
Signed-off-by: Jim Brunner <brunnerj@amazon.com>
Signed-off-by: Jim Brunner <brunnerj@amazon.com>
Signed-off-by: Jim Brunner <brunnerj@amazon.com>
Signed-off-by: Jim Brunner <brunnerj@amazon.com>
Signed-off-by: Jim Brunner <brunnerj@amazon.com>
Signed-off-by: Jim Brunner <brunnerj@amazon.com>
Signed-off-by: Jim Brunner <brunnerj@amazon.com>
Signed-off-by: Jim Brunner <brunnerj@amazon.com>
Signed-off-by: Jim Brunner <brunnerj@amazon.com>
Signed-off-by: Jim Brunner <brunnerj@amazon.com>
Signed-off-by: Jim Brunner <brunnerj@amazon.com>
Comment thread src/bgiteration.c Outdated
Comment thread src/bgiteration.c
Comment thread src/bgiteration.c Outdated
Comment thread src/server.c Outdated
JimB123 added 8 commits June 4, 2026 17:56
Signed-off-by: Jim Brunner <brunnerj@amazon.com>
Signed-off-by: Jim Brunner <brunnerj@amazon.com>
Signed-off-by: Jim Brunner <brunnerj@amazon.com>
Signed-off-by: Jim Brunner <brunnerj@amazon.com>
Signed-off-by: Jim Brunner <brunnerj@amazon.com>
Signed-off-by: Jim Brunner <brunnerj@amazon.com>
Signed-off-by: Jim Brunner <brunnerj@amazon.com>
Signed-off-by: Jim Brunner <brunnerj@amazon.com>
JimB123 added a commit that referenced this pull request Jun 11, 2026
Just rebasing. The real PR is:
#3553

---------

Signed-off-by: harrylin98 <harrylin980107@gmail.com>
Signed-off-by: Jim Brunner <brunnerj@amazon.com>
Co-authored-by: Harry Lin <49881386+harrylin98@users.noreply.github.com>
Signed-off-by: Jim Brunner <brunnerj@amazon.com>
@JimB123 JimB123 force-pushed the forkless-bgiterator branch from 91a0712 to b22338f Compare June 15, 2026 20:50
@JimB123

JimB123 commented Jun 15, 2026

Copy link
Copy Markdown
Member Author

Status 6/16/2026:

  • All pipeline checks passing
  • All outstanding comments addressed

JimB123 added 2 commits June 16, 2026 16:45
Signed-off-by: Jim Brunner <brunnerj@amazon.com>
Signed-off-by: Jim Brunner <brunnerj@amazon.com>
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