MB-20744: Increment reject ops on insertion to reject queue 19/68219/10
authorSriram Ganesan <sriram@couchbase.com>
Mon, 29 Aug 2016 22:48:40 +0000 (15:48 -0700)
committerDave Rigby <daver@couchbase.com>
Mon, 3 Oct 2016 07:49:27 +0000 (07:49 +0000)
In case of a failure to persist items, the items are added to the
reject queue in which the reject stats needs to be updated for
the associated vbucket.

Change-Id: I15b7ad26d8bcab5b6a437b8d172d8b914df8b683
Reviewed-on: http://review.couchbase.org/68219
Tested-by: buildbot <build@couchbase.com>
Reviewed-by: Dave Rigby <daver@couchbase.com>
src/ep.cc
tests/ep_testsuite.cc

index 09d612f..bd2f935 100644 (file)
--- a/src/ep.cc
+++ b/src/ep.cc
@@ -3281,6 +3281,7 @@ private:
                                          queuedItem->getVBucketId(),
                                          &StoredValue::reDirty);
         vbucket->rejectQueue.push(queuedItem);
+        ++vbucket->opsReject;
     }
 
     const queued_item queuedItem;
index 7904c09..92f02ac 100644 (file)
@@ -6472,6 +6472,49 @@ static enum test_result test_mb20697(ENGINE_HANDLE *h,
     return SUCCESS;
 }
 
+/* Check if vbucket reject ops are incremented on persistence failure */
+static enum test_result test_mb20744_check_incr_reject_ops(ENGINE_HANDLE* h,
+                                                           ENGINE_HANDLE_V1* h1) {
+
+    std::string dbname = get_dbname(testHarness.get_current_testcase()->cfg);
+    std::string filename = dbname +
+                           DIRECTORY_SEPARATOR_CHARACTER +
+                           "0.couch.1";
+
+    /* corrupt the couchstore file */
+    FILE *fp = fopen(filename.c_str(), "wb");
+
+    if (fp == nullptr) {
+        return FAIL;
+    }
+
+    char buf[2048];
+    memset(buf, 'x', sizeof(buf));
+
+    size_t numBytes = fwrite(buf, sizeof(char), sizeof(buf), fp);
+
+    fflush(fp);
+
+    checkeq(static_cast<unsigned long>(2048), static_cast<unsigned long>(numBytes),
+            "Bytes written should be equal to 2048");
+
+    checkeq(ENGINE_SUCCESS, store(h, h1, NULL, OPERATION_SET,"key", "somevalue",
+                                  NULL, 0, 0, 0), "store should have succeeded");
+
+    wait_for_stat_change(h, h1, "vb_active_ops_reject", 0);
+
+    checkeq(1, get_int_stat(h, h1, "vb_0:ops_reject", "vbucket-details 0"),
+            "Expected rejected ops to be equal to 1");
+
+    fclose(fp);
+
+    rmdb(filename.c_str());
+
+    CouchbaseDirectoryUtilities::mkdirp(dbname);
+
+    return SUCCESS;
+}
+
 static enum test_result test_mb20943_complete_pending_ops_on_vbucket_delete(
         ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1) {
     const void *cookie = testHarness.create_cookie();
@@ -7027,5 +7070,8 @@ BaseTestCase testsuite_testcases[] = {
         TestCase("test_MB-test_mb20943_remove_pending_ops_on_vbucket_delete",
                  test_mb20943_complete_pending_ops_on_vbucket_delete,
                  test_setup, teardown, NULL, prepare, cleanup),
+        TestCase("test_mb20744_check_incr_reject_ops",
+                 test_mb20744_check_incr_reject_ops,
+                 test_setup, teardown, NULL, prepare, cleanup),
         TestCase(NULL, NULL, NULL, NULL, NULL, prepare, cleanup)
 };