Draft: Forkless Snapshot (Threadsave)#3648
Draft
nitaicaro wants to merge 4 commits into
Draft
Conversation
Signed-off-by: harrylin98 <harrylin980107@gmail.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## forkless-pre-threadsave #3648 +/- ##
===========================================================
+ Coverage 76.76% 76.98% +0.22%
===========================================================
Files 161 162 +1
Lines 81423 81712 +289
===========================================================
+ Hits 62502 62906 +404
+ Misses 18921 18806 -115
🚀 New features to boost your workflow:
|
harrylin98
reviewed
May 8, 2026
harrylin98
reviewed
May 8, 2026
harrylin98
reviewed
May 8, 2026
a00a573 to
5482b96
Compare
|
Important Review skippedIgnore keyword(s) in the title. ⛔ Ignored keywords (1)
Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Comment |
1588575 to
79b3cc3
Compare
c4090e9 to
cca0dfe
Compare
cca0dfe to
fa3301a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Draft: Thread-based RDB snapshot (Threadsave)
Motivation
Fork-based BGSAVE relies on
fork(), which on large datasets causes significant memory overhead from copy-on-write page duplication. On systems where memory is constrained, fork can fail entirely. Threadsave provides an alternative that avoids fork by performing the RDB snapshot on a background thread while the main thread continues serving clients.How it works
Threadsave builds on the bgIteration framework (introduced in #3553). bgIteration walks the keyspace on the main thread, delivering keys to a FIFO queue. A background thread consumes entries from the queue and serializes them to an RDB file using the standard
rdbSaveKeyValuePairencoding. The result is a normal RDB file - loadable by any Valkey instance.Usage
A thread-based snapshot can be triggered in three ways:
BGSAVE THREAD- explicit command (requiresforkless-options-supported yes)config set threadsave-enabled-for-backup yes- makes plainBGSAVEuse threadsavethreadsave-enabled-for-backupis enabledBGSAVE FORKexplicitly forces a fork-based snapshot regardless of configuration.BGSAVE SCHEDULE THREAD/BGSAVE SCHEDULE FORKschedule a snapshot with explicit type.Draft status
This PR is marked as draft because it includes three cherry-picked commits (the
pending_commandlifecycle fix, thefindDbForEntryNULL check, and the hashtable bucket-chain iteration fix) that belong in the underlying bgIteration and blocked-inuse branches. Once those patches are merged into their respective base branches, this PR will be rebased and those commits will disappear from the diff. The threadsave-specific changes should mostly remain the same.