Skip to content

Fix pre-size hashtables per slot when reading RDB files#2466

Merged
enjoy-binbin merged 3 commits intovalkey-io:unstablefrom
enjoy-binbin:kvstore_expand
Aug 19, 2025
Merged

Fix pre-size hashtables per slot when reading RDB files#2466
enjoy-binbin merged 3 commits intovalkey-io:unstablefrom
enjoy-binbin:kvstore_expand

Conversation

@enjoy-binbin
Copy link
Member

@enjoy-binbin enjoy-binbin commented Aug 11, 2025

When reading RDB files with information about the number of keys per cluster slot, we need to create the hashtables if they don't exist.

Currently, when processing RDB slot-info, our expand has no effect because the hashtable does not exist (we initialize it only when we need it).

if (server.cluster_enabled) {
    /* In cluster mode we resize individual slot specific dictionaries based on the number of keys that
     * slot holds. */
    kvstoreHashtableExpand(db->keys, slot_id, slot_size);
    kvstoreHashtableExpand(db->expires, slot_id, expires_slot_size);
    should_expand_db = 0;
}

We also update kvstoreExpand to use the kvstoreHashtableExpand to make
sure there is only one code path. Also see #1199 for more details.

…e the hashtable

If we want to expand kvstoreHashtableExpand, we need to make sure the
hashtable exists. Currently, when processing RDB slot-info, our expand
has no effect because the hashtable does not exist (we initialize it only
when we need it).
```
if (server.cluster_enabled) {
    /* In cluster mode we resize individual slot specific dictionaries based on the number of keys that
     * slot holds. */
    kvstoreHashtableExpand(db->keys, slot_id, slot_size);
    kvstoreHashtableExpand(db->expires, slot_id, expires_slot_size);
    should_expand_db = 0;
}
```

We also update kvstoreExpand to use the kvstoreHashtableExpand to make
sure there is only one code path. Also see valkey-io#1328 for more details.

Signed-off-by: Binbin <[email protected]>
@enjoy-binbin
Copy link
Member Author

This seem broken at the very beginning.

@enjoy-binbin enjoy-binbin moved this to To be backported in Valkey 8.1 Aug 11, 2025
@enjoy-binbin enjoy-binbin moved this to To be backported in Valkey 8.0 Aug 11, 2025
@enjoy-binbin enjoy-binbin moved this to In Progress in Valkey 9.0 Aug 11, 2025
@enjoy-binbin enjoy-binbin requested a review from naglera August 11, 2025 10:02
@codecov
Copy link

codecov bot commented Aug 11, 2025

Codecov Report

❌ Patch coverage is 71.42857% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 72.07%. Comparing base (fb9503b) to head (cdd072d).
⚠️ Report is 2 commits behind head on unstable.

Files with missing lines Patch % Lines
src/kvstore.c 66.66% 4 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##           unstable    #2466      +/-   ##
============================================
+ Coverage     72.02%   72.07%   +0.04%     
============================================
  Files           126      126              
  Lines         70479    70485       +6     
============================================
+ Hits          50761    50799      +38     
+ Misses        19718    19686      -32     
Files with missing lines Coverage Δ
src/rdb.c 77.04% <100.00%> (+0.07%) ⬆️
src/kvstore.c 96.01% <66.66%> (-0.65%) ⬇️

... and 11 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.

Copy link
Contributor

@zuiderkwast zuiderkwast left a comment

Choose a reason for hiding this comment

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

Oops, #1199 was broken from the beginning. :) @naglera @hpatro PTAL.

Signed-off-by: Binbin <[email protected]>
@zuiderkwast zuiderkwast moved this from To be backported to In Progress in Valkey 8.0 Aug 15, 2025
@enjoy-binbin enjoy-binbin merged commit a97d584 into valkey-io:unstable Aug 19, 2025
52 checks passed
@github-project-automation github-project-automation bot moved this from In Progress to Done in Valkey 9.0 Aug 19, 2025
@github-project-automation github-project-automation bot moved this from In Progress to To be backported in Valkey 8.0 Aug 19, 2025
@enjoy-binbin enjoy-binbin deleted the kvstore_expand branch August 19, 2025 13:02
@enjoy-binbin enjoy-binbin added the release-notes This issue should get a line item in the release notes label Aug 19, 2025
@enjoy-binbin enjoy-binbin changed the title Fix slot-info expand not working, kvstoreHashtableExpand always creat… Fix slot-info expand not working, kvstoreHashtableExpand always create the hashtable Aug 19, 2025
@zuiderkwast zuiderkwast changed the title Fix slot-info expand not working, kvstoreHashtableExpand always create the hashtable Fix pre-size hashtables per slot when reading RDB files Aug 19, 2025
allenss-amazon pushed a commit to allenss-amazon/valkey-core that referenced this pull request Aug 19, 2025
valkey-io#2466)

If we want to expand kvstoreHashtableExpand, we need to make sure the
hashtable exists. Currently, when processing RDB slot-info, our expand
has no effect because the hashtable does not exist (we initialize it only
when we need it).

We also update kvstoreExpand to use the kvstoreHashtableExpand to make
sure there is only one code path. Also see valkey-io#1199 for more details.

Signed-off-by: Binbin <[email protected]>
asagege pushed a commit to asagege/valkey that referenced this pull request Aug 19, 2025
valkey-io#2466)

If we want to expand kvstoreHashtableExpand, we need to make sure the
hashtable exists. Currently, when processing RDB slot-info, our expand
has no effect because the hashtable does not exist (we initialize it only
when we need it).

We also update kvstoreExpand to use the kvstoreHashtableExpand to make
sure there is only one code path. Also see valkey-io#1199 for more details.

Signed-off-by: Binbin <[email protected]>
@zuiderkwast
Copy link
Contributor

zuiderkwast commented Aug 21, 2025

Backporting this to 8.0 is non-trivial, because of the dict/hashtable change. I suggest we make a separate PR targeting the 8.0 branch.

enjoy-binbin added a commit to vitarb/valkey that referenced this pull request Aug 22, 2025
When reading RDB files with information about the number of keys per cluster slot,
we need to create the dicts if they don't exist.

Currently, when processing RDB slot-info, our expand has no effect because the dict
does not exist (we initialize it only when we need it).

We also update kvstoreExpand to use the kvstoreDictExpand to make
sure there is only one code path. Also see valkey-io#1199 for more details.

Signed-off-by: Binbin <[email protected]>
@enjoy-binbin
Copy link
Member Author

I pushed the commit to the target branch already.

@enjoy-binbin enjoy-binbin moved this from To be backported to 8.0.5 (to be released) in Valkey 8.0 Aug 22, 2025
enjoy-binbin added a commit to vitarb/valkey that referenced this pull request Aug 22, 2025
When reading RDB files with information about the number of keys per cluster slot,
we need to create the dicts if they don't exist.

Currently, when processing RDB slot-info, our expand has no effect because the dict
does not exist (we initialize it only when we need it).

We also update kvstoreExpand to use the kvstoreDictExpand to make
sure there is only one code path. Also see valkey-io#1199 for more details.

Signed-off-by: Binbin <[email protected]>
zuiderkwast pushed a commit to vitarb/valkey that referenced this pull request Aug 22, 2025
When reading RDB files with information about the number of keys per cluster slot,
we need to create the dicts if they don't exist.

Currently, when processing RDB slot-info, our expand has no effect because the dict
does not exist (we initialize it only when we need it).

We also update kvstoreExpand to use the kvstoreDictExpand to make
sure there is only one code path. Also see valkey-io#1199 for more details.

Signed-off-by: Binbin <[email protected]>
zuiderkwast pushed a commit to vitarb/valkey that referenced this pull request Aug 22, 2025
When reading RDB files with information about the number of keys per cluster slot,
we need to create the dicts if they don't exist.

Currently, when processing RDB slot-info, our expand has no effect because the dict
does not exist (we initialize it only when we need it).

We also update kvstoreExpand to use the kvstoreDictExpand to make
sure there is only one code path. Also see valkey-io#1199 for more details.

Signed-off-by: Binbin <[email protected]>
zuiderkwast pushed a commit that referenced this pull request Aug 22, 2025
When reading RDB files with information about the number of keys per cluster slot,
we need to create the dicts if they don't exist.

Currently, when processing RDB slot-info, our expand has no effect because the dict
does not exist (we initialize it only when we need it).

We also update kvstoreExpand to use the kvstoreDictExpand to make
sure there is only one code path. Also see #1199 for more details.

Signed-off-by: Binbin <[email protected]>
@enjoy-binbin enjoy-binbin moved this from Done to RC2 in Valkey 9.0 Aug 29, 2025
@madolson madolson moved this from RC2 to Done in Valkey 9.0 Sep 3, 2025
sarthakaggarwal97 pushed a commit to sarthakaggarwal97/valkey that referenced this pull request Sep 16, 2025
When reading RDB files with information about the number of keys per cluster slot,
we need to create the dicts if they don't exist.

Currently, when processing RDB slot-info, our expand has no effect because the dict
does not exist (we initialize it only when we need it).

We also update kvstoreExpand to use the kvstoreDictExpand to make
sure there is only one code path. Also see valkey-io#1199 for more details.

Signed-off-by: Binbin <[email protected]>
rjd15372 pushed a commit to rjd15372/valkey that referenced this pull request Sep 19, 2025
valkey-io#2466)

If we want to expand kvstoreHashtableExpand, we need to make sure the
hashtable exists. Currently, when processing RDB slot-info, our expand
has no effect because the hashtable does not exist (we initialize it only
when we need it).

We also update kvstoreExpand to use the kvstoreHashtableExpand to make
sure there is only one code path. Also see valkey-io#1199 for more details.

Signed-off-by: Binbin <[email protected]>
rjd15372 pushed a commit that referenced this pull request Sep 23, 2025
#2466)

If we want to expand kvstoreHashtableExpand, we need to make sure the
hashtable exists. Currently, when processing RDB slot-info, our expand
has no effect because the hashtable does not exist (we initialize it only
when we need it).

We also update kvstoreExpand to use the kvstoreHashtableExpand to make
sure there is only one code path. Also see #1199 for more details.

Signed-off-by: Binbin <[email protected]>
@ranshid ranshid moved this from To be backported to In Progress in Valkey 8.1 Sep 30, 2025
ranshid pushed a commit to ranshid/valkey that referenced this pull request Sep 30, 2025
valkey-io#2466)

If we want to expand kvstoreHashtableExpand, we need to make sure the
hashtable exists. Currently, when processing RDB slot-info, our expand
has no effect because the hashtable does not exist (we initialize it only
when we need it).

We also update kvstoreExpand to use the kvstoreHashtableExpand to make
sure there is only one code path. Also see valkey-io#1199 for more details.

Signed-off-by: Binbin <[email protected]>
ranshid pushed a commit to ranshid/valkey that referenced this pull request Sep 30, 2025
valkey-io#2466)

If we want to expand kvstoreHashtableExpand, we need to make sure the
hashtable exists. Currently, when processing RDB slot-info, our expand
has no effect because the hashtable does not exist (we initialize it only
when we need it).

We also update kvstoreExpand to use the kvstoreHashtableExpand to make
sure there is only one code path. Also see valkey-io#1199 for more details.

Signed-off-by: Binbin <[email protected]>
@ranshid ranshid moved this from In Progress to 8.1.4 in Valkey 8.1 Sep 30, 2025
@ranshid ranshid moved this from 8.1.4 to To be backported in Valkey 8.1 Sep 30, 2025
zuiderkwast pushed a commit that referenced this pull request Oct 1, 2025
#2466)

If we want to expand kvstoreHashtableExpand, we need to make sure the
hashtable exists. Currently, when processing RDB slot-info, our expand
has no effect because the hashtable does not exist (we initialize it only
when we need it).

We also update kvstoreExpand to use the kvstoreHashtableExpand to make
sure there is only one code path. Also see #1199 for more details.

Signed-off-by: Binbin <[email protected]>
@zuiderkwast zuiderkwast moved this from To be backported to 8.1.4 in Valkey 8.1 Oct 1, 2025
hpatro pushed a commit to hpatro/valkey that referenced this pull request Oct 3, 2025
valkey-io#2466)

If we want to expand kvstoreHashtableExpand, we need to make sure the
hashtable exists. Currently, when processing RDB slot-info, our expand
has no effect because the hashtable does not exist (we initialize it only
when we need it).

We also update kvstoreExpand to use the kvstoreHashtableExpand to make
sure there is only one code path. Also see valkey-io#1199 for more details.

Signed-off-by: Binbin <[email protected]>
Signed-off-by: Harkrishn Patro <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-notes This issue should get a line item in the release notes

Projects

Status: 8.0.5
Status: 8.1.4
Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants