diff options
author | 赵磊 <zhaolei21@meituan.com> | 2018-05-08 15:30:11 +0800 |
---|---|---|
committer | antirez <antirez@gmail.com> | 2018-06-01 16:54:30 +0200 |
commit | 59080f602358445b558c539077c76ffbd78301c0 (patch) | |
tree | 7783724b4f02ef469a6f6b8554086ee5e4579b27 | |
parent | ac2a824aa9d8e794acb9eb15a13b0942c20674ff (diff) | |
download | redis-59080f602358445b558c539077c76ffbd78301c0.tar.gz |
Fix dictScan(): It can't scan all buckets when dict is shrinking.
-rw-r--r-- | src/dict.c | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/src/dict.c b/src/dict.c index 97e636805..18cb9ee79 100644 --- a/src/dict.c +++ b/src/dict.c @@ -858,6 +858,15 @@ unsigned long dictScan(dict *d, de = next; } + /* Set unmasked bits so incrementing the reversed cursor + * operates on the masked bits */ + v |= ~m0; + + /* Increment the reverse cursor */ + v = rev(v); + v++; + v = rev(v); + } else { t0 = &d->ht[0]; t1 = &d->ht[1]; @@ -892,22 +901,16 @@ unsigned long dictScan(dict *d, de = next; } - /* Increment bits not covered by the smaller mask */ - v = (((v | m0) + 1) & ~m0) | (v & m0); + /* Increment the reverse cursor not covered by the smaller mask.*/ + v |= ~m1; + v = rev(v); + v++; + v = rev(v); /* Continue while bits covered by mask difference is non-zero */ } while (v & (m0 ^ m1)); } - /* Set unmasked bits so incrementing the reversed cursor - * operates on the masked bits of the smaller table */ - v |= ~m0; - - /* Increment the reverse cursor */ - v = rev(v); - v++; - v = rev(v); - return v; } |