Skip to content

Commit 4ea2003

Browse files
owend74daverigby
authored andcommitted
[BP] MB-25798: Don't schedule backfill until previous is complete
Previously in the handleSlowStream function if we are in the Backfilling state and backfillTask is not running then we called scheduleBackfill_UNLOCKED. However although the backfillTask is not running there could still be items in the Ready Queue. As we are still in the Backfilling state, regardless as to whether the backfillTask is running, we should drop the current cursor and set the pendingBackfill flag. Change-Id: I7d8c19041b9cec10640c4ef72c5d62cd73985ea4 Reviewed-on: http://review.couchbase.org/83533 Well-Formed: Build Bot <[email protected]> Tested-by: Build Bot <[email protected]> Reviewed-by: Dave Rigby <[email protected]>
1 parent 2513928 commit 4ea2003

File tree

2 files changed

+52
-9
lines changed

2 files changed

+52
-9
lines changed

src/dcp/stream.cc

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,14 +1174,6 @@ void ActiveStream::handleSlowStream()
11741174
isBackfillTaskRunning.load() ? "True" : "False");
11751175
switch (state_.load()) {
11761176
case STREAM_BACKFILLING:
1177-
if (isBackfillTaskRunning.load()) {
1178-
/* Drop the existing cursor and set pending backfill */
1179-
dropCheckpointCursor_UNLOCKED();
1180-
pendingBackfill = true;
1181-
} else {
1182-
scheduleBackfill_UNLOCKED(true);
1183-
}
1184-
break;
11851177
case STREAM_IN_MEMORY:
11861178
/* Drop the existing cursor and set pending backfill */
11871179
dropCheckpointCursor_UNLOCKED();

tests/module_tests/evp_store_single_threaded_test.cc

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,58 @@ class SingleThreadedEPStoreTest : public EventuallyPersistentStoreTest {
119119
SingleThreadedExecutorPool* task_executor;
120120
};
121121

122-
/**
122+
/*
123+
* The following test checks to see if we call handleSlowStream when in a
124+
* backfilling state, but the backfillTask is not running, we
125+
* drop the existing cursor and set pendingBackfill to true.
126+
*/
127+
TEST_F(SingleThreadedEPStoreTest, MB22421_backfilling_but_task_finished) {
128+
// Make vbucket active.
129+
setVBucketStateAndRunPersistTask(vbid, vbucket_state_active);
130+
auto vb = store->getVBuckets().getBucket(vbid);
131+
auto& ckpt_mgr = vb->checkpointManager;
132+
133+
// Create a Mock Dcp producer
134+
dcp_producer_t producer = new MockDcpProducer(*engine,
135+
cookie,
136+
"test_producer",
137+
/*notifyOnly*/false);
138+
// Create a Mock Active Stream
139+
stream_t stream = new MockActiveStream(
140+
static_cast<EventuallyPersistentEngine*>(engine.get()),
141+
producer,
142+
producer->getName(),
143+
/*flags*/0,
144+
/*opaque*/0, vbid,
145+
/*st_seqno*/0,
146+
/*en_seqno*/~0,
147+
/*vb_uuid*/0xabcd,
148+
/*snap_start_seqno*/0,
149+
/*snap_end_seqno*/~0);
150+
151+
MockActiveStream* mock_stream =
152+
static_cast<MockActiveStream*>(stream.get());
153+
154+
mock_stream->transitionStateToBackfilling();
155+
ASSERT_TRUE(mock_stream->isInMemory())
156+
<< "stream state should have transitioned to InMemory";
157+
// Have a persistence cursor and DCP cursor
158+
ASSERT_EQ(2, ckpt_mgr.getNumOfCursors());
159+
// Set backfilling task to true so can transition to Backfilling State
160+
mock_stream->public_setBackfillTaskRunning(true);
161+
mock_stream->transitionStateToBackfilling();
162+
ASSERT_TRUE(mock_stream->isBackfilling())
163+
<< "stream state should not have transitioned to Backfilling";
164+
// Set backfilling task to false for test
165+
mock_stream->public_setBackfillTaskRunning(false);
166+
mock_stream->handleSlowStream();
167+
// The call to handleSlowStream should result in setting pendingBackfill
168+
// flag to true and the DCP cursor being dropped
169+
EXPECT_TRUE(mock_stream->public_getPendingBackfill());
170+
EXPECT_EQ(1, ckpt_mgr.getNumOfCursors());
171+
}
172+
173+
/*
123174
* The following test checks to see if a cursor is re-registered after it is
124175
* dropped in handleSlowStream. In particular the test is for when
125176
* scheduleBackfill_UNLOCKED is called however the backfill task does not need

0 commit comments

Comments
 (0)