Fix rehashingStarted miscalculating bucket_count in dict initialization#12846
Merged
oranagra merged 9 commits intoredis:unstablefrom Dec 10, 2023
Merged
Fix rehashingStarted miscalculating bucket_count in dict initialization#12846oranagra merged 9 commits intoredis:unstablefrom
oranagra merged 9 commits intoredis:unstablefrom
Conversation
…tion In the old dictRehashingInfo implementation, for the initialization scenario, it mistakenly directly set to_size to DICTHT_SIZE(DICT_HT_INITIAL_EXP), which is 4 in our code by default. In scenarios where dictExpand directly passes the target size as initialization, the code will calculate bucket_count incorrectly. For example, in DEBUG POPULATE or RDB load scenarios, it will cause the final bucket_count to be initialized to 65536 (16384 * 4), see: ``` before: DB 0: 10000000 keys (0 volatile) in 65536 slots HT. it should be: DB 0: 10000000 keys (0 volatile) in 16777216 slots HT. ``` In PR, new ht will also be initialized before calling rehashingStarted in _dictExpand, so that the calls in dictRehashingInfo can be unified. This PR also cleans up dictRehashingStarted* and dictRehashingCompleted*, eliminating some duplicate code. Bug was introduced in redis#12697.
enjoy-binbin
commented
Dec 8, 2023
Contributor
Author
|
The last two commits dropped these two parts: This PR also cleans up dictRehashingStarted* and dictRehashingCompleted*, This PR also optimizes the situation in _dictExpand when old ht is empty. |
oranagra
approved these changes
Dec 9, 2023
Member
oranagra
left a comment
There was a problem hiding this comment.
LGTM.
please remove the obsolete parts from the top comment.
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.
In the old dictRehashingInfo implementation, for the initialization scenario,
it mistakenly directly set to_size to DICTHT_SIZE(DICT_HT_INITIAL_EXP), which
is 4 in our code by default.
In scenarios where dictExpand directly passes the target size as initialization,
the code will calculate bucket_count incorrectly. For example, in DEBUG POPULATE
or RDB load scenarios, it will cause the final bucket_count to be initialized to
65536 (16384 * 4), see:
In PR, new ht will also be initialized before calling rehashingStarted in
_dictExpand, so that the calls in dictRehashingInfo can be unified.
Bug was introduced in #12697.