From 85e4fc26905ec54cd1e597a69f38326e0edde487 Mon Sep 17 00:00:00 2001
From: Eric Milkie <milkie@10gen.com>
Date: Wed, 2 Aug 2017 11:38:24 -0400
Subject: [PATCH] test for checkpoint ROLLBACK crash

---
 src/mongo/db/storage/SConscript                    | 32 ++++++++++----------
 .../db/storage/record_store_test_recorditer.cpp    | 12 ++++----
 src/mongo/db/storage/wiredtiger/SConscript         | 35 +++++++++++++++++++++-
 .../db/storage/wiredtiger/wiredtiger_kv_engine.cpp | 11 ++++---
 .../wiredtiger/wiredtiger_recovery_unit.cpp        |  6 ++--
 .../wiredtiger_standard_record_store_test.cpp      |  4 +--
 6 files changed, 69 insertions(+), 31 deletions(-)

diff --git a/src/mongo/db/storage/SConscript b/src/mongo/db/storage/SConscript
index 46c00c7..d4feebe 100644
--- a/src/mongo/db/storage/SConscript
+++ b/src/mongo/db/storage/SConscript
@@ -137,23 +137,23 @@ env.Library(
 env.Library(
     target='record_store_test_harness',
     source=[
-        'record_store_test_capped_visibility.cpp',
-        'record_store_test_datafor.cpp',
-        'record_store_test_datasize.cpp',
-        'record_store_test_deleterecord.cpp',
-        'record_store_test_harness.cpp',
-        'record_store_test_insertrecord.cpp',
-        'record_store_test_manyiter.cpp',
-        'record_store_test_randomiter.cpp',
+#        'record_store_test_capped_visibility.cpp',
+#        'record_store_test_datafor.cpp',
+#        'record_store_test_datasize.cpp',
+#        'record_store_test_deleterecord.cpp',
+#        'record_store_test_harness.cpp',
+#        'record_store_test_insertrecord.cpp',
+#        'record_store_test_manyiter.cpp',
+#        'record_store_test_randomiter.cpp',
         'record_store_test_recorditer.cpp',
-        'record_store_test_recordstore.cpp',
-        'record_store_test_repairiter.cpp',
-        'record_store_test_storagesize.cpp',
-        'record_store_test_touch.cpp',
-        'record_store_test_truncate.cpp',
-        'record_store_test_updaterecord.cpp',
-        'record_store_test_updatewithdamages.cpp',
-        'record_store_test_validate.cpp',
+#        'record_store_test_recordstore.cpp',
+#        'record_store_test_repairiter.cpp',
+#        'record_store_test_storagesize.cpp',
+#        'record_store_test_touch.cpp',
+#        'record_store_test_truncate.cpp',
+#        'record_store_test_updaterecord.cpp',
+#        'record_store_test_updatewithdamages.cpp',
+#        'record_store_test_validate.cpp',
         ],
     LIBDEPS=[
         '$BUILD_DIR/mongo/db/service_context',
diff --git a/src/mongo/db/storage/record_store_test_recorditer.cpp b/src/mongo/db/storage/record_store_test_recorditer.cpp
index aa6c158..70c8fba 100644
--- a/src/mongo/db/storage/record_store_test_recorditer.cpp
+++ b/src/mongo/db/storage/record_store_test_recorditer.cpp
@@ -46,7 +46,7 @@ namespace {
 using std::unique_ptr;
 using std::string;
 using std::stringstream;
-
+/*
 // Insert multiple records and iterate through them in the forward direction.
 // When curr() or getNext() is called on an iterator positioned at EOF,
 // the iterator returns RecordId() and stays at EOF.
@@ -253,14 +253,15 @@ TEST(RecordStoreTestHarness, IterateStartFromMiddleReversed) {
         ASSERT(!cursor->next());
     }
 }
-
+*/
 // Insert several records, and iterate to the end. Ensure that the record iterator
 // is EOF. Add an additional record, saving and restoring the iterator state, and check
 // that the iterator remains EOF.
 TEST(RecordStoreTestHarness, RecordIteratorEOF) {
     const auto harnessHelper(newRecordStoreHarnessHelper());
-    unique_ptr<RecordStore> rs(harnessHelper->newNonCappedRecordStore());
 
+    unique_ptr<RecordStore> rs(harnessHelper->newNonCappedRecordStore());
+    /*
     {
         ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext());
         ASSERT_EQUALS(0, rs->numRecords(opCtx.get()));
@@ -325,8 +326,9 @@ TEST(RecordStoreTestHarness, RecordIteratorEOF) {
         ASSERT(!cursor->next());
         ASSERT(!cursor->next());
     }
+    */
 }
-
+/*
 // Test calling save and restore after each call to next
 TEST(RecordStoreTestHarness, RecordIteratorSaveRestore) {
     const auto harnessHelper(newRecordStoreHarnessHelper());
@@ -442,6 +444,6 @@ TEST(RecordStoreTestHarness, SeekAfterEofAndContinue) {
 
     ASSERT(!cursor->next());
 }
-
+*/
 }  // namespace
 }  // namespace mongo
diff --git a/src/mongo/db/storage/wiredtiger/SConscript b/src/mongo/db/storage/wiredtiger/SConscript
index e95eb5c..2b39a7e 100644
--- a/src/mongo/db/storage/wiredtiger/SConscript
+++ b/src/mongo/db/storage/wiredtiger/SConscript
@@ -150,7 +150,40 @@ if wiredtiger:
                 'additional_wiredtiger_record_store_tests',
             ],
         )
-
+        
+        wtEnv.CppUnitTest(
+            target='record_store_test_iter',
+            source=[
+#        'record_store_test_capped_visibility.cpp',
+#        'record_store_test_datafor.cpp',
+#        'record_store_test_datasize.cpp',
+#        'record_store_test_deleterecord.cpp',
+#        'record_store_test_harness.cpp',
+#        'record_store_test_insertrecord.cpp',
+#        'record_store_test_manyiter.cpp',
+#        'record_store_test_randomiter.cpp',
+                'wiredtiger_standard_record_store_test.cpp',
+                '../record_store_test_recorditer.cpp',
+#        'record_store_test_recordstore.cpp',
+#        'record_store_test_repairiter.cpp',
+#        'record_store_test_storagesize.cpp',
+#        'record_store_test_touch.cpp',
+#        'record_store_test_truncate.cpp',
+#        'record_store_test_updaterecord.cpp',
+#        'record_store_test_updatewithdamages.cpp',
+#        'record_store_test_validate.cpp',
+            ],
+            LIBDEPS=[
+                '$BUILD_DIR/mongo/db/service_context',
+                '$BUILD_DIR/mongo/db/storage/storage_options',
+                '$BUILD_DIR/mongo/unittest/unittest',
+                '../test_harness_helper',
+                '$BUILD_DIR/mongo/db/storage/kv/kv_engine_core',
+                '$BUILD_DIR/mongo/db/storage/record_store_test_harness',
+                'storage_wiredtiger_mock',
+                '$BUILD_DIR/mongo/util/clock_source_mock',
+            ],
+        )
         wtEnv.CppUnitTest(
             target='storage_wiredtiger_prefixed_record_store_test',
             source=[
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp
index bd05e14..ff010a5 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp
@@ -149,15 +149,17 @@ public:
 
         while (!_shuttingDown.load()) {
             {
-                stdx::unique_lock<stdx::mutex> lock(_mutex);
-                _condvar.wait_for(lock,
-                                  stdx::chrono::seconds(static_cast<std::int64_t>(
-                                      wiredTigerGlobalOptions.checkpointDelaySecs)));
+                //    stdx::unique_lock<stdx::mutex> lock(_mutex);
+                //_condvar.wait_for(lock,
+                //                  stdx::chrono::seconds(static_cast<std::int64_t>(
+                //                      wiredTigerGlobalOptions.checkpointDelaySecs)));
             }
 
             try {
                 const bool forceCheckpoint = true;
+                log() << "ckpt start";
                 _sessionCache->waitUntilDurable(forceCheckpoint);
+                log() << "ckpt end";
             } catch (const UserException& exc) {
                 invariant(exc.getCode() == ErrorCodes::ShutdownInProgress);
             } catch (const WriteConflictException& wce) {
@@ -168,6 +170,7 @@ public:
     }
 
     void shutdown() {
+        log() << "ckpt shutdown";
         _shuttingDown.store(true);
         _condvar.notify_one();
         wait();
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.cpp
index c7edea9..2bb30c6 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.cpp
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.cpp
@@ -195,10 +195,10 @@ void WiredTigerRecoveryUnit::_txnClose(bool commit) {
         } else {
             invariantWTOK(s->commit_transaction(s, NULL));
         }
-        LOG(3) << "WT commit_transaction for snapshot id " << _mySnapshotId;
+        LOG(0) << "WT commit_transaction for snapshot id " << _mySnapshotId;
     } else {
         invariantWTOK(s->rollback_transaction(s, NULL));
-        LOG(3) << "WT rollback_transaction for snapshot id " << _mySnapshotId;
+        LOG(0) << "WT rollback_transaction for snapshot id " << _mySnapshotId;
     }
     _active = false;
     _mySnapshotId = nextSnapshotId.fetchAndAdd(1);
@@ -249,7 +249,7 @@ void WiredTigerRecoveryUnit::_txnOpen(OperationContext* opCtx) {
         invariantWTOK(session->begin_transaction(session, NULL));
     }
 
-    LOG(3) << "WT begin_transaction for snapshot id " << _mySnapshotId;
+    LOG(0) << "WT begin_transaction for snapshot id " << _mySnapshotId;
     _active = true;
 }
 
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_standard_record_store_test.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_standard_record_store_test.cpp
index 2995b6b..a320171 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_standard_record_store_test.cpp
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_standard_record_store_test.cpp
@@ -205,7 +205,7 @@ MONGO_INITIALIZER(RegisterHarnessFactory)(InitializerContext* const) {
     mongo::registerHarnessHelperFactory(makeHarnessHelper);
     return Status::OK();
 }
-
+/*
 TEST(WiredTigerRecordStoreTest, StorageSizeStatisticsDisabled) {
     WiredTigerHarnessHelper harnessHelper("statistics=(none)");
     unique_ptr<RecordStore> rs(harnessHelper.newNonCappedRecordStore("a.b"));
@@ -457,6 +457,6 @@ TEST_F(SizeStorerValidateTest, InvalidSizeStorerAtCreation) {
     ASSERT_EQUALS(expectedNumRecords, rs->numRecords(NULL));
     ASSERT_EQUALS(expectedDataSize, rs->dataSize(NULL));
 }
-
+*/
 }  // namespace
 }  // mongo
-- 
2.9.4

