Skip to content

Commit b624230

Browse files
jameseh96daverigby
authored andcommitted
MB-41804: Track correct number of vbuckets in each state
When moving between states, the vbmap needs to decrement the count of vbuckets in the old state, and increment in the new state. It previously only decremented the old state. Change-Id: I2f2f50e87cbd0c09f8496cfddeb4e7726339d4da Reviewed-on: http://review.couchbase.org/c/kv_engine/+/139835 Tested-by: Build Bot <[email protected]> Well-Formed: Build Bot <[email protected]> Reviewed-by: Ben Huddleston <[email protected]>
1 parent 920b20a commit b624230

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

engines/ep/src/kv_bucket.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -802,6 +802,7 @@ ENGINE_ERROR_CODE KVBucket::setVBucketState_UNLOCKED(
802802
} else {
803803
vb->setState(to);
804804
}
805+
vbMap.incrVBStateCount(to);
805806

806807
if (oldstate != to && notify_dcp) {
807808
bool closeInboundStreams = false;

engines/ep/src/vbucketmap.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,14 @@ friend class Warmup;
109109
void setHLCDriftAheadThreshold(std::chrono::microseconds threshold);
110110
void setHLCDriftBehindThreshold(std::chrono::microseconds threshold);
111111

112+
/**
113+
* Increment the vb count for the given state.
114+
* @param state the state for which the vb count is to be incremented.
115+
*/
116+
void incrVBStateCount(vbucket_state_t state) {
117+
++vbStateCount[state];
118+
}
119+
112120
/**
113121
* Decrement the vb count for the given state.
114122
* @param state the state for which the vb count is to be decremented.

engines/ep/tests/module_tests/kv_bucket_test.cc

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1353,6 +1353,31 @@ TEST_P(KVBucketParamTest, MB_34346) {
13531353
<< "Should still have 0 items after time-travelling/expiry";
13541354
}
13551355

1356+
TEST_P(KVBucketParamTest, VbucketStateCounts) {
1357+
// confirm the vbMap correctly changes the number of vbuckets in a given
1358+
// state when vbuckets change state
1359+
auto vbA = 0;
1360+
auto vbB = 1;
1361+
1362+
auto expectVbCounts = [this](uint16_t active, uint16_t replica) {
1363+
auto message = "Expected " + std::to_string(active) + " active and " +
1364+
std::to_string(replica) + " replica vbs";
1365+
EXPECT_EQ(active, store->getNumOfVBucketsInState(vbucket_state_active))
1366+
<< message;
1367+
EXPECT_EQ(replica,
1368+
store->getNumOfVBucketsInState(vbucket_state_replica))
1369+
<< message;
1370+
};
1371+
store->setVBucketState(vbA, vbucket_state_active, false);
1372+
expectVbCounts(1, 0);
1373+
store->setVBucketState(vbB, vbucket_state_active, false);
1374+
expectVbCounts(2, 0);
1375+
store->setVBucketState(vbA, vbucket_state_replica, false);
1376+
expectVbCounts(1, 1);
1377+
store->setVBucketState(vbB, vbucket_state_replica, false);
1378+
expectVbCounts(0, 2);
1379+
}
1380+
13561381
class StoreIfTest : public KVBucketTest {
13571382
public:
13581383
void SetUp() override {

0 commit comments

Comments
 (0)