Skip to content

Commit df99171

Browse files
owend74daverigby
authored andcommitted
Refactor: Simplify KVBucket::getRandomKey
There was a bug in KBBucket::getRandomKey - see MB-31495, which although has been fixed highlighted unnecessary complexity in the implementation of the function. This patch simplfies the implementation of the function by removing the nested while loops. Change-Id: I614ef388abecf90992df31fbbd06d1b6ead5477e Reviewed-on: http://review.couchbase.org/100397 Tested-by: Build Bot <[email protected]> Reviewed-by: Paolo Cocchi <[email protected]>
1 parent c176cda commit df99171

File tree

1 file changed

+3
-14
lines changed

1 file changed

+3
-14
lines changed

engines/ep/src/kv_bucket.cc

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1413,28 +1413,17 @@ GetValue KVBucket::getRandomKey() {
14131413

14141414
while (itm == NULL) {
14151415
VBucketPtr vb = getVBucket(Vbid(curr++));
1416-
while (!vb || vb->getState() != vbucket_state_active) {
1417-
if (curr == max) {
1418-
curr = 0;
1419-
}
1420-
if (curr == start) {
1421-
return GetValue(NULL, ENGINE_KEY_ENOENT);
1422-
}
1423-
1424-
vb = getVBucket(Vbid(curr++));
1425-
}
1426-
1427-
if ((itm = vb->ht.getRandomKey(getRandom()))) {
1416+
if (vb && vb->getState() == vbucket_state_active &&
1417+
(itm = vb->ht.getRandomKey(getRandom()))) {
14281418
GetValue rv(std::move(itm), ENGINE_SUCCESS);
14291419
return rv;
14301420
}
14311421

14321422
if (curr == max) {
14331423
curr = 0;
14341424
}
1435-
14361425
if (curr == start) {
1437-
return GetValue(NULL, ENGINE_KEY_ENOENT);
1426+
break;
14381427
}
14391428
// Search next vbucket
14401429
}

0 commit comments

Comments
 (0)