MB-20697: Return false if commit2couchstore fails 93/67093/3
authorDave Rigby <daver@couchbase.com>
Fri, 26 Aug 2016 18:29:43 +0000 (19:29 +0100)
committerDave Finlay <dave.finlay@couchbase.com>
Wed, 31 Aug 2016 00:42:36 +0000 (00:42 +0000)
This ensures that callers are notified of the failure, and
specifically we correctly increment the ep_item_commit_failed stat

Change-Id: I56f2591479c45c03fba184236aa3790a67290b38
Reviewed-on: http://review.couchbase.org/67093
Tested-by: buildbot <build@couchbase.com>
Reviewed-by: Will Gardner <will.gardner@couchbase.com>
Reviewed-by: Dave Rigby <daver@couchbase.com>
Well-Formed: buildbot <build@couchbase.com>

src/couch-kvstore/couch-kvstore.cc
tests/ep_testsuite.cc

index d771b3d..48e5237 100644 (file)
@@ -1757,6 +1757,7 @@ bool CouchKVStore::commit2couchstore(Callback<kvstats_ctx> *cb) {
                                           docinfos, pendingCommitCnt,
                                           kvctx);
     if (errCode) {
+        success = false;
         LOG(EXTENSION_LOG_WARNING,
             "Commit failed, cannot save CouchDB docs "
             "for vbucket = %d rev = %" PRIu64, vbucket2flush, fileRev);
index 815fb0b..429d38c 100644 (file)
@@ -6454,6 +6454,26 @@ static enum test_result test_mb19687_variable(ENGINE_HANDLE* h,
     return SUCCESS;
 }
 
+static enum test_result test_mb20697(ENGINE_HANDLE *h,
+                                     ENGINE_HANDLE_V1 *h1) {
+    checkeq(ENGINE_SUCCESS,
+            h1->get_stats(h, NULL, NULL, 0, add_stats),
+            "Failed to get stats.");
+
+    std::string dbname = vals["ep_dbname"];
+
+    /* Nuke the database directory to simulate the commit failure */
+    rmdb(dbname.c_str());
+
+    checkeq(ENGINE_SUCCESS, store(h, h1, NULL, OPERATION_SET,"key", "somevalue",
+                                  NULL, 0, 0, 0), "store should have succeeded");
+
+    /* Ensure that this results in commit failure and the stat gets incremented */
+    wait_for_stat_change(h, h1, "ep_item_commit_failed", 0);
+
+    return SUCCESS;
+}
+
 /* This test case checks the purge seqno validity when no items are actually
    purged in a compaction call */
 static enum test_result test_vbucket_compact_no_purge(ENGINE_HANDLE *h,
@@ -6955,5 +6975,8 @@ BaseTestCase testsuite_testcases[] = {
                  prepare, cleanup),
         TestCase("test vbucket compact no purge", test_vbucket_compact_no_purge,
                  test_setup, teardown, NULL, prepare, cleanup),
+
+        TestCase("test_MB-20697", test_mb20697, test_setup, teardown, NULL, prepare,
+                 cleanup),
         TestCase(NULL, NULL, NULL, NULL, NULL, prepare, cleanup)
 };