Fix random probability check in ziplistRandomPairsUnique (#8467)
When (remaining == (total_size - index)), element will definitely be random to. But when rand() == RAND_MAX, the element will miss, this will trigger assert in serverAssert(ziplistRandomPairsUnique(zsetobj->ptr, count, keys, vals) == count).
This commit is contained in:
parent
88272cf7ac
commit
1f12be3072
@ -1608,7 +1608,7 @@ unsigned int ziplistRandomPairsUnique(unsigned char *zl, unsigned int count, zip
|
||||
while (picked < count && p) {
|
||||
double randomDouble = ((double)rand()) / RAND_MAX;
|
||||
double threshold = ((double)remaining) / (total_size - index);
|
||||
if(randomDouble < threshold){
|
||||
if (randomDouble <= threshold) {
|
||||
assert(ziplistGet(p, &key, &klen, &klval));
|
||||
ziplistSaveValue(key, klen, klval, &keys[picked]);
|
||||
p = ziplistNext(zl, p);
|
||||
|
Loading…
x
Reference in New Issue
Block a user