-
Notifications
You must be signed in to change notification settings - Fork 24.4k
Fix rehashingStarted miscalculating bucket_count in dict initialization #12846
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix rehashingStarted miscalculating bucket_count in dict initialization #12846
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.
|
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
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
please remove the obsolete parts from the top comment.
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.