MB-17517: Testcase for invalid max_cas in _local/vbstate 58/60858/3
authorDave Rigby <daver@couchbase.com>
Thu, 3 Mar 2016 15:03:27 +0000 (15:03 +0000)
committerDave Rigby <daver@couchbase.com>
Mon, 7 Mar 2016 13:29:57 +0000 (13:29 +0000)
Unit test for fe67145 - verify that if a vbucket is created with a max
CAS of -1, upon re-reading from disk it is detected and fixed.

Change-Id: Ifdf3e642589f93191786ac55c1cf02207159f657
Reviewed-on: http://review.couchbase.org/60858
Tested-by: buildbot <build@couchbase.com>
Reviewed-by: Jim Walker <jim@couchbase.com>
CMakeLists.txt
tests/module_tests/kvstore_test.cc [new file with mode: 0644]

index 3ca43c8..9735d0e 100644 (file)
@@ -270,6 +270,59 @@ ADD_EXECUTABLE(ep-engine_failover_table_test tests/module_tests/failover_table_t
                         ${OBJECTREGISTRY_SOURCE} ${CONFIG_SOURCE})
 TARGET_LINK_LIBRARIES(ep-engine_failover_table_test cJSON platform)
 
+ADD_EXECUTABLE(ep-engine_kvstore_test
+  tests/module_tests/kvstore_test.cc
+  src/access_scanner.cc
+  src/atomic.cc
+  src/backfill.cc
+  src/bgfetcher.cc
+  src/bloomfilter.cc
+  src/checkpoint.cc
+  src/checkpoint_remover.cc
+  src/conflict_resolution.cc
+  src/connmap.cc
+  src/dcp-backfill.cc
+  src/dcp-backfill-manager.cc
+  src/dcp-consumer.cc
+  src/dcp-producer.cc
+  src/dcp-response.cc
+  src/dcp-stream.cc
+  src/defragmenter.cc
+  src/defragmenter_visitor.cc
+  src/ep.cc
+  src/ep_engine.cc
+  src/ep_time.c
+  src/executorpool.cc
+  src/executorthread.cc
+  src/ext_meta_parser.cc
+  src/failover-table.cc
+  src/flusher.cc
+  src/htresizer.cc
+  src/item.cc
+  src/item_pager.cc
+  src/kvshard.cc
+  src/memory_tracker.cc
+  src/murmurhash3.cc
+  src/mutation_log.cc
+  src/mutex.cc
+  src/objectregistry.cc
+  src/priority.cc
+  src/tapconnection.cc
+  src/stored-value.cc
+  src/tapthrottle.cc
+  src/tasks.cc
+  src/taskqueue.cc
+  src/vbucket.cc
+  src/vbucketmap.cc
+  src/warmup.cc
+  ${CMAKE_CURRENT_BINARY_DIR}/src/stats-info.c
+  ${OBJECTREGISTRY_SOURCE}
+  ${KVSTORE_SOURCE}
+  ${COUCH_KVSTORE_SOURCE}
+  ${CONFIG_SOURCE})
+TARGET_LINK_LIBRARIES(ep-engine_kvstore_test
+                      cJSON JSON_checker couchstore dirutils platform)
+
 ADD_TEST(ep-engine_atomic_ptr_test ep-engine_atomic_ptr_test)
 ADD_TEST(ep-engine_atomic_test ep-engine_atomic_test)
 ADD_TEST(ep-engine_checkpoint_test ep-engine_checkpoint_test)
@@ -283,6 +336,7 @@ ADD_TEST(ep-engine_mutex_test ep-engine_mutex_test)
 ADD_TEST(ep-engine_priority_test ep-engine_priority_test)
 ADD_TEST(ep-engine_ringbuffer_test ep-engine_ringbuffer_test)
 ADD_TEST(ep-engine_stream_test ep-engine_stream_test)
+ADD_TEST(ep-engine_kvstore_test ep-engine_kvstore_test)
 
 ADD_LIBRARY(timing_tests SHARED tests/module_tests/timing_tests.cc)
 SET_TARGET_PROPERTIES(timing_tests PROPERTIES PREFIX "")
diff --git a/tests/module_tests/kvstore_test.cc b/tests/module_tests/kvstore_test.cc
new file mode 100644 (file)
index 0000000..4fa3a60
--- /dev/null
@@ -0,0 +1,63 @@
+/* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
+/*
+ *     Copyright 2016 Couchbase, Inc
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ */
+
+#include "config.h"
+
+#include <platform/dirutils.h>
+
+#include "kvstore.h"
+
+// Regression test for MB-17517 - ensure that if a couchstore file has a max
+// CAS of -1, it is detected and reset to zero when file is loaded.
+static void mb_17517_max_cas_of_minus_1_test() {
+    std::string data_dir("/tmp/kvstore-test");
+
+    CouchbaseDirectoryUtilities::rmrf(data_dir.c_str());
+
+    Configuration config;
+    config.setDbname(data_dir);
+    KVStore* kvstore = KVStoreFactory::create(config);
+    cb_assert(kvstore);
+
+    // Activate vBucket.
+    std::string failoverLog("[]");
+    vbucket_state state(vbucket_state_active, /*ckid*/0, /*maxDelSeqNum*/0,
+                        /*highSeqno*/0, /*purgeSeqno*/0, /*lastSnapStart*/0,
+                        /*lastSnapEnd*/0, /*maxCas*/-1, /*driftCounter*/0,
+                        failoverLog);
+    cb_assert(kvstore->snapshotVBucket(/*vbid*/0, state, NULL));
+    cb_assert(kvstore->listPersistedVbuckets()[0]->maxCas == ~0ull);
+
+    // Close the file, then re-open.
+    delete kvstore;
+    kvstore = KVStoreFactory::create(config);
+    cb_assert(kvstore);
+
+    // Check that our max CAS was repaired on startup.
+    cb_assert(kvstore->listPersistedVbuckets()[0]->maxCas == 0);
+
+    // Cleanup
+    delete kvstore;
+}
+
+
+int main(int argc, char **argv) {
+    (void)argc; (void)argv;
+    putenv(strdup("ALLOW_NO_STATS_UPDATE=yeah"));
+
+    mb_17517_max_cas_of_minus_1_test();
+}