Skip to content

Conversation

@enjoy-binbin
Copy link
Contributor

@enjoy-binbin enjoy-binbin commented Dec 8, 2023

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.

Bug was introduced in #12697.

…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 enjoy-binbin changed the title Fixed rehashingStarted miscalculating bucket_count in dict initialization Fix rehashingStarted miscalculating bucket_count in dict initialization Dec 8, 2023
@enjoy-binbin
Copy link
Contributor Author

The last two commits dropped these two parts:

This PR also cleans up dictRehashingStarted* and dictRehashingCompleted*,
eliminating some duplicate code.
This was drop because #12848

This PR also optimizes the situation in _dictExpand when old ht is empty.
Similar to the first initialization, new ht can be set directly in this case.
This was drop because #12847

Copy link
Member

@oranagra oranagra left a 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.

@oranagra oranagra merged commit e6423b7 into redis:unstable Dec 10, 2023
@enjoy-binbin enjoy-binbin deleted the fix_bucket_count_on_load branch December 10, 2023 08:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants