MB-16656: Set the open chkpt id on replica to 0 when disk snapshot is recvd. 34/57834/4
authorManu Dhundi <manu@couchbase.com>
Sat, 19 Dec 2015 02:15:16 +0000 (18:15 -0800)
committerManu Dhundi <manu@couchbase.com>
Wed, 23 Dec 2015 07:44:38 +0000 (07:44 +0000)
Currently due to a bug in 3.0.x the open checkpoint id is not set to 0
when replica receives a disk snapshot from active.

Change-Id: Iffda89b8da713539a52d50aa4acc33458ae7150e
Reviewed-on: http://review.couchbase.org/57834
Reviewed-by: Chiyoung Seo <chiyoung@couchbase.com>
Tested-by: buildbot <build@couchbase.com>
src/dcp-stream.cc
tests/ep_testsuite.cc

index 99f2e66..c9b6556 100644 (file)
@@ -1355,7 +1355,9 @@ void PassiveStream::processMarker(SnapshotMarker* marker) {
     if (vb) {
         if (marker->getFlags() & MARKER_FLAG_DISK && vb->getHighSeqno() == 0) {
             vb->setBackfillPhase(true);
-            vb->checkpointManager.checkAndAddNewCheckpoint(0, vb);
+            /* When replica vb is in backfill phase, then open checkpoint id
+               is set to 0. */
+            vb->checkpointManager.setOpenCheckpointId(0);
         } else {
             if (marker->getFlags() & MARKER_FLAG_CHK ||
                 vb->checkpointManager.getOpenCheckpointId() == 0) {
index df01893..73275b1 100644 (file)
@@ -5198,6 +5198,50 @@ static void dcp_stream_to_replica(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1,
     }
 }
 
+static enum test_result test_dcp_replica_stream_backfill(ENGINE_HANDLE *h,
+                                                         ENGINE_HANDLE_V1 *h1)
+{
+    check(set_vbucket_state(h, h1, 0, vbucket_state_replica),
+          "Failed to set vbucket state.");
+
+    const void *cookie = testHarness.create_cookie();
+    uint32_t opaque = 0xFFFF0000;
+    uint32_t seqno = 0;
+    uint32_t flags = 0;
+    const int num_items = 100;
+    const char *name = "unittest";
+    uint16_t nname = strlen(name);
+
+    /* Open an DCP consumer connection */
+    checkeq(ENGINE_SUCCESS,
+            h1->dcp.open(h, cookie, opaque, seqno, flags, (void*)name, nname),
+            "Failed dcp producer open connection.");
+
+    std::string type = get_str_stat(h, h1, "eq_dcpq:unittest:type", "dcp");
+    checkeq(0, type.compare("consumer"), "Consumer not found");
+
+    opaque = add_stream_for_consumer(h, h1, cookie, opaque, 0, 0,
+                                     PROTOCOL_BINARY_RESPONSE_SUCCESS);
+
+    /* Write backfill elements on to replica, flag (0x02) */
+    dcp_stream_to_replica(h, h1, cookie, opaque, 0, 0x02, 1, num_items, 0,
+                          num_items);
+
+    /* Stream in mutations from replica */
+    wait_for_flusher_to_settle(h, h1);
+    wait_for_stat_to_be(h, h1, "vb_0:high_seqno", num_items,
+                        "vbucket-seqno");
+    uint64_t vb_uuid = get_ull_stat(h, h1, "vb_0:0:id", "failovers");
+
+    const void *cookie1 = testHarness.create_cookie();
+    dcp_stream(h, h1, "unittest1", cookie1, 0, 0, 0, num_items, vb_uuid, 0, 0,
+               num_items, 0, 1, 0, 2);
+
+    testHarness.destroy_cookie(cookie1);
+    testHarness.destroy_cookie(cookie);
+    return SUCCESS;
+}
+
 static enum test_result test_dcp_replica_stream_in_memory(ENGINE_HANDLE *h,
                                                           ENGINE_HANDLE_V1 *h1)
 {
@@ -12367,6 +12411,9 @@ engine_test_t* get_tests(void) {
                  teardown, NULL, prepare, cleanup),
         TestCase("test dcp consumer noop", test_dcp_consumer_noop, test_setup,
                  teardown, NULL, prepare, cleanup),
+        TestCase("test dcp replica stream backfill",
+                 test_dcp_replica_stream_backfill, test_setup, teardown,
+                 "chk_remover_stime=1;max_checkpoints=2", prepare, cleanup),
         TestCase("test dcp replica stream in-memory",
                  test_dcp_replica_stream_in_memory, test_setup, teardown,
                  "chk_remover_stime=1;max_checkpoints=2", prepare, cleanup),