summaryrefslogtreecommitdiff
path: root/src/mongo/db/storage
diff options
context:
space:
mode:
authorDaniel Gottlieb <daniel.gottlieb@mongodb.com>2017-11-21 12:25:54 -0500
committerDaniel Gottlieb <daniel.gottlieb@mongodb.com>2017-11-21 12:25:54 -0500
commit470c30273c479c5ab139de0d38e016f95c589c49 (patch)
tree1b8fa734567a6976c4980bb6ca4885b13af6ed8a /src/mongo/db/storage
parenta094c5b4b4783895d5fe168541bd97103a0d05f5 (diff)
downloadmongo-470c30273c479c5ab139de0d38e016f95c589c49.tar.gz
SERVER-31304: Refactor away SnapshotName.
Diffstat (limited to 'src/mongo/db/storage')
-rw-r--r--src/mongo/db/storage/SConscript7
-rw-r--r--src/mongo/db/storage/kv/kv_engine.h6
-rw-r--r--src/mongo/db/storage/kv/kv_engine_test_timestamps.cpp55
-rw-r--r--src/mongo/db/storage/kv/kv_storage_engine.cpp4
-rw-r--r--src/mongo/db/storage/kv/kv_storage_engine.h5
-rw-r--r--src/mongo/db/storage/recovery_unit.h14
-rw-r--r--src/mongo/db/storage/snapshot_manager.h3
-rw-r--r--src/mongo/db/storage/snapshot_name.h97
-rw-r--r--src/mongo/db/storage/storage_engine.h6
-rw-r--r--src/mongo/db/storage/storage_snapshot_name_test.cpp48
-rw-r--r--src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp30
-rw-r--r--src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.h9
-rw-r--r--src/mongo/db/storage/wiredtiger/wiredtiger_oplog_manager.cpp2
-rw-r--r--src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp6
-rw-r--r--src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.cpp11
-rw-r--r--src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.h12
-rw-r--r--src/mongo/db/storage/wiredtiger/wiredtiger_snapshot_manager.cpp20
-rw-r--r--src/mongo/db/storage/wiredtiger/wiredtiger_snapshot_manager.h11
18 files changed, 97 insertions, 249 deletions
diff --git a/src/mongo/db/storage/SConscript b/src/mongo/db/storage/SConscript
index 079a1e4ec91..3f1362e3a0c 100644
--- a/src/mongo/db/storage/SConscript
+++ b/src/mongo/db/storage/SConscript
@@ -222,10 +222,3 @@ env.CppUnitTest(
'$BUILD_DIR/mongo/base',
]
)
-
-env.CppUnitTest(
- target='storage_snapshot_name_test',
- source='storage_snapshot_name_test.cpp',
- LIBDEPS=[],
- LIBDEPS_PRIVATE=[],
-)
diff --git a/src/mongo/db/storage/kv/kv_engine.h b/src/mongo/db/storage/kv/kv_engine.h
index 3350971bddc..c0e5bc1b906 100644
--- a/src/mongo/db/storage/kv/kv_engine.h
+++ b/src/mongo/db/storage/kv/kv_engine.h
@@ -36,10 +36,10 @@
#include "mongo/base/status.h"
#include "mongo/base/string_data.h"
+#include "mongo/bson/timestamp.h"
#include "mongo/db/catalog/collection_options.h"
#include "mongo/db/storage/kv/kv_prefix.h"
#include "mongo/db/storage/record_store.h"
-#include "mongo/db/storage/snapshot_name.h"
namespace mongo {
@@ -249,12 +249,12 @@ public:
/**
* See `StorageEngine::setStableTimestamp`
*/
- virtual void setStableTimestamp(SnapshotName stableTimestamp) {}
+ virtual void setStableTimestamp(Timestamp stableTimestamp) {}
/**
* See `StorageEngine::setInitialDataTimestamp`
*/
- virtual void setInitialDataTimestamp(SnapshotName initialDataTimestamp) {}
+ virtual void setInitialDataTimestamp(Timestamp initialDataTimestamp) {}
/**
* See `StorageEngine::supportsRecoverToStableTimestamp`
diff --git a/src/mongo/db/storage/kv/kv_engine_test_timestamps.cpp b/src/mongo/db/storage/kv/kv_engine_test_timestamps.cpp
index a45da7bf28b..7112ce561c8 100644
--- a/src/mongo/db/storage/kv/kv_engine_test_timestamps.cpp
+++ b/src/mongo/db/storage/kv/kv_engine_test_timestamps.cpp
@@ -31,6 +31,7 @@
#include <memory>
#include <string>
+#include "mongo/bson/timestamp.h"
#include "mongo/db/operation_context_noop.h"
#include "mongo/db/service_context_noop.h"
#include "mongo/db/storage/kv/kv_engine.h"
@@ -89,10 +90,11 @@ public:
return Operation(service.makeClient(""), helper->getEngine()->newRecoveryUnit());
}
- SnapshotName incrementTimestamp() {
- auto name = SnapshotName(_counter);
+ // Returns the timestamp before incrementing.
+ Timestamp fetchAndIncrementTimestamp() {
+ auto preImage = _counter;
_counter = Timestamp(_counter.getSecs() + 1, _counter.getInc());
- return name;
+ return preImage;
}
RecordId insertRecord(OperationContext* opCtx, std::string contents = "abcd") {
@@ -112,7 +114,7 @@ public:
void updateRecordAndCommit(RecordId id, std::string contents) {
auto op = makeOperation();
WriteUnitOfWork wuow(op);
- ASSERT_OK(op->recoveryUnit()->setTimestamp(SnapshotName(_counter)));
+ ASSERT_OK(op->recoveryUnit()->setTimestamp(_counter));
ASSERT_OK(
rs->updateRecord(op, id, contents.c_str(), contents.length() + 1, false, nullptr));
wuow.commit();
@@ -121,7 +123,7 @@ public:
void deleteRecordAndCommit(RecordId id) {
auto op = makeOperation();
WriteUnitOfWork wuow(op);
- ASSERT_OK(op->recoveryUnit()->setTimestamp(SnapshotName(_counter)));
+ ASSERT_OK(op->recoveryUnit()->setTimestamp(_counter));
rs->deleteRecord(op, id);
wuow.commit();
}
@@ -208,12 +210,12 @@ TEST_F(SnapshotManagerTests, FailsWithNoCommittedSnapshot) {
ErrorCodes::ReadConcernMajorityNotAvailableYet);
// There is a snapshot but it isn't committed.
- auto name = incrementTimestamp();
+ auto snap = fetchAndIncrementTimestamp();
ASSERT_EQ(ru->setReadFromMajorityCommittedSnapshot(),
ErrorCodes::ReadConcernMajorityNotAvailableYet);
// Now there is a committed snapshot.
- snapshotManager->setCommittedSnapshot(name, Timestamp(name.asU64()));
+ snapshotManager->setCommittedSnapshot(snap);
ASSERT_OK(ru->setReadFromMajorityCommittedSnapshot());
// Not anymore!
@@ -229,8 +231,8 @@ TEST_F(SnapshotManagerTests, FailsAfterDropAllSnapshotsWhileYielded) {
auto op = makeOperation();
// Start an operation using a committed snapshot.
- auto name = incrementTimestamp();
- snapshotManager->setCommittedSnapshot(name, Timestamp(name.asU64()));
+ auto snap = fetchAndIncrementTimestamp();
+ snapshotManager->setCommittedSnapshot(snap);
ASSERT_OK(op->recoveryUnit()->setReadFromMajorityCommittedSnapshot());
ASSERT_EQ(itCountOn(op), 0); // acquires a snapshot.
@@ -248,10 +250,8 @@ TEST_F(SnapshotManagerTests, BasicFunctionality) {
if (!snapshotManager)
return; // This test is only for engines that DO support SnapshotMangers.
- // Snapshot variables are named according to the size of the RecordStore at the time of the
- // snapshot.
- auto snap0 = incrementTimestamp();
- snapshotManager->setCommittedSnapshot(snap0, Timestamp(snap0.asU64()));
+ auto snap0 = fetchAndIncrementTimestamp();
+ snapshotManager->setCommittedSnapshot(snap0);
ASSERT_EQ(itCountCommitted(), 0);
insertRecordAndCommit();
@@ -259,11 +259,11 @@ TEST_F(SnapshotManagerTests, BasicFunctionality) {
ASSERT_EQ(itCountCommitted(), 0);
- auto snap1 = incrementTimestamp();
+ auto snap1 = fetchAndIncrementTimestamp();
insertRecordAndCommit();
insertRecordAndCommit();
- auto snap3 = incrementTimestamp();
+ auto snap3 = fetchAndIncrementTimestamp();
{
auto op = makeOperation();
@@ -273,13 +273,13 @@ TEST_F(SnapshotManagerTests, BasicFunctionality) {
}
insertRecordAndCommit();
- auto snap4 = incrementTimestamp();
+ auto snap4 = fetchAndIncrementTimestamp();
// If these fail, everything is busted.
ASSERT_EQ(itCountCommitted(), 0);
- snapshotManager->setCommittedSnapshot(snap1, Timestamp(snap1.asU64()));
+ snapshotManager->setCommittedSnapshot(snap1);
ASSERT_EQ(itCountCommitted(), 1);
- snapshotManager->setCommittedSnapshot(snap3, Timestamp(snap3.asU64()));
+ snapshotManager->setCommittedSnapshot(snap3);
ASSERT_EQ(itCountCommitted(), 3);
// This op should keep its original snapshot until abandoned.
@@ -288,7 +288,7 @@ TEST_F(SnapshotManagerTests, BasicFunctionality) {
ASSERT_EQ(itCountOn(longOp), 3);
// If this fails, the snapshot contains writes that were rolled back.
- snapshotManager->setCommittedSnapshot(snap4, Timestamp(snap4.asU64()));
+ snapshotManager->setCommittedSnapshot(snap4);
ASSERT_EQ(itCountCommitted(), 4);
// If this fails, longOp changed snapshots at an illegal time.
@@ -303,31 +303,30 @@ TEST_F(SnapshotManagerTests, UpdateAndDelete) {
if (!snapshotManager)
return; // This test is only for engines that DO support SnapshotMangers.
- // Snapshot variables are named according to the state of the record.
- auto snapBeforeInsert = incrementTimestamp();
+ auto snapBeforeInsert = fetchAndIncrementTimestamp();
auto id = insertRecordAndCommit("Dog");
- auto snapDog = incrementTimestamp();
+ auto snapDog = fetchAndIncrementTimestamp();
updateRecordAndCommit(id, "Cat");
- auto snapCat = incrementTimestamp();
+ auto snapCat = fetchAndIncrementTimestamp();
deleteRecordAndCommit(id);
- auto snapAfterDelete = incrementTimestamp();
+ auto snapAfterDelete = fetchAndIncrementTimestamp();
- snapshotManager->setCommittedSnapshot(snapBeforeInsert, Timestamp(snapBeforeInsert.asU64()));
+ snapshotManager->setCommittedSnapshot(snapBeforeInsert);
ASSERT_EQ(itCountCommitted(), 0);
ASSERT(!readRecordCommitted(id));
- snapshotManager->setCommittedSnapshot(snapDog, Timestamp(snapDog.asU64()));
+ snapshotManager->setCommittedSnapshot(snapDog);
ASSERT_EQ(itCountCommitted(), 1);
ASSERT_EQ(readStringCommitted(id), "Dog");
- snapshotManager->setCommittedSnapshot(snapCat, Timestamp(snapCat.asU64()));
+ snapshotManager->setCommittedSnapshot(snapCat);
ASSERT_EQ(itCountCommitted(), 1);
ASSERT_EQ(readStringCommitted(id), "Cat");
- snapshotManager->setCommittedSnapshot(snapAfterDelete, Timestamp(snapAfterDelete.asU64()));
+ snapshotManager->setCommittedSnapshot(snapAfterDelete);
ASSERT_EQ(itCountCommitted(), 0);
ASSERT(!readRecordCommitted(id));
}
diff --git a/src/mongo/db/storage/kv/kv_storage_engine.cpp b/src/mongo/db/storage/kv/kv_storage_engine.cpp
index 55d03fd0b52..63f589fcd7d 100644
--- a/src/mongo/db/storage/kv/kv_storage_engine.cpp
+++ b/src/mongo/db/storage/kv/kv_storage_engine.cpp
@@ -364,11 +364,11 @@ void KVStorageEngine::setJournalListener(JournalListener* jl) {
_engine->setJournalListener(jl);
}
-void KVStorageEngine::setStableTimestamp(SnapshotName stableTimestamp) {
+void KVStorageEngine::setStableTimestamp(Timestamp stableTimestamp) {
_engine->setStableTimestamp(stableTimestamp);
}
-void KVStorageEngine::setInitialDataTimestamp(SnapshotName initialDataTimestamp) {
+void KVStorageEngine::setInitialDataTimestamp(Timestamp initialDataTimestamp) {
_engine->setInitialDataTimestamp(initialDataTimestamp);
}
diff --git a/src/mongo/db/storage/kv/kv_storage_engine.h b/src/mongo/db/storage/kv/kv_storage_engine.h
index 580e1c7d069..5ecf45aaf04 100644
--- a/src/mongo/db/storage/kv/kv_storage_engine.h
+++ b/src/mongo/db/storage/kv/kv_storage_engine.h
@@ -33,6 +33,7 @@
#include "mongo/base/status_with.h"
#include "mongo/base/string_data.h"
+#include "mongo/bson/timestamp.h"
#include "mongo/db/storage/journal_listener.h"
#include "mongo/db/storage/kv/kv_catalog.h"
#include "mongo/db/storage/kv/kv_database_catalog_entry_base.h"
@@ -112,9 +113,9 @@ public:
virtual void cleanShutdown();
- virtual void setStableTimestamp(SnapshotName stableTimestamp) override;
+ virtual void setStableTimestamp(Timestamp stableTimestamp) override;
- virtual void setInitialDataTimestamp(SnapshotName initialDataTimestamp) override;
+ virtual void setInitialDataTimestamp(Timestamp initialDataTimestamp) override;
virtual bool supportsRecoverToStableTimestamp() const override;
diff --git a/src/mongo/db/storage/recovery_unit.h b/src/mongo/db/storage/recovery_unit.h
index 5ac712b4887..72b25fccb63 100644
--- a/src/mongo/db/storage/recovery_unit.h
+++ b/src/mongo/db/storage/recovery_unit.h
@@ -34,8 +34,8 @@
#include "mongo/base/disallow_copying.h"
#include "mongo/base/status.h"
+#include "mongo/bson/timestamp.h"
#include "mongo/db/storage/snapshot.h"
-#include "mongo/db/storage/snapshot_name.h"
namespace mongo {
@@ -120,13 +120,13 @@ public:
}
/**
- * Returns the SnapshotName being used by this recovery unit or boost::none if not reading from
+ * Returns the Timestamp being used by this recovery unit or boost::none if not reading from
* a majority committed snapshot.
*
* It is possible for reads to occur from later snapshots, but they may not occur from earlier
* snapshots.
*/
- virtual boost::optional<SnapshotName> getMajorityCommittedSnapshot() const {
+ virtual boost::optional<Timestamp> getMajorityCommittedSnapshot() const {
dassert(!isReadingFromMajorityCommittedSnapshot());
return {};
}
@@ -136,7 +136,7 @@ public:
*
* It is only valid to compare SnapshotIds generated by a single RecoveryUnit.
*
- * This is unrelated to SnapshotName which must be globally comparable.
+ * This is unrelated to Timestamp which must be globally comparable.
*/
virtual SnapshotId getSnapshotId() const = 0;
@@ -148,14 +148,14 @@ public:
* Writes that occur before any setTimestamp() is called will be assigned the timestamp
* specified in the last setTimestamp() call in the transaction, at commit time.
*/
- virtual Status setTimestamp(SnapshotName timestamp) {
+ virtual Status setTimestamp(Timestamp timestamp) {
return Status::OK();
}
/**
- * Chooses which snapshot to use for read transactions.
+ * Chooses which timestamp to use for read transactions.
*/
- virtual Status selectSnapshot(SnapshotName timestamp) {
+ virtual Status selectSnapshot(Timestamp timestamp) {
return Status(ErrorCodes::CommandNotSupported,
"point-in-time reads are not implemented for this storage engine");
}
diff --git a/src/mongo/db/storage/snapshot_manager.h b/src/mongo/db/storage/snapshot_manager.h
index 4ca7be39a7c..0577236a4ce 100644
--- a/src/mongo/db/storage/snapshot_manager.h
+++ b/src/mongo/db/storage/snapshot_manager.h
@@ -34,7 +34,6 @@
#include "mongo/base/status.h"
#include "mongo/bson/timestamp.h"
#include "mongo/db/operation_context.h"
-#include "mongo/db/storage/snapshot_name.h"
#include "mongo/util/assert_util.h"
namespace mongo {
@@ -70,7 +69,7 @@ public:
* can be done later. In particular, cleaning up of old snapshots should be deferred until
* cleanupUnneededSnapshots is called.
*/
- virtual void setCommittedSnapshot(const SnapshotName& name, Timestamp ts) = 0;
+ virtual void setCommittedSnapshot(const Timestamp& timestamp) = 0;
/**
* Cleans up all snapshots older than the current committed snapshot.
diff --git a/src/mongo/db/storage/snapshot_name.h b/src/mongo/db/storage/snapshot_name.h
deleted file mode 100644
index d9f8618c673..00000000000
--- a/src/mongo/db/storage/snapshot_name.h
+++ /dev/null
@@ -1,97 +0,0 @@
-/**
- * Copyright (C) 2015 MongoDB Inc.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- * As a special exception, the copyright holders give permission to link the
- * code of portions of this program with the OpenSSL library under certain
- * conditions as described in each individual source file and distribute
- * linked combinations including the program with the OpenSSL library. You
- * must comply with the GNU Affero General Public License in all respects for
- * all of the code used other than as permitted herein. If you modify file(s)
- * with this exception, you may extend this exception to your version of the
- * file(s), but you are not obligated to do so. If you do not wish to do so,
- * delete this exception statement from your version. If you delete this
- * exception statement from all source files in the program, then also delete
- * it in the license file.
- */
-
-#pragma once
-
-#include <cstdint>
-#include <limits>
-#include <ostream>
-
-#include "mongo/bson/timestamp.h"
-#include "mongo/util/hex.h"
-
-namespace mongo {
-
-class SnapshotName {
-public:
- explicit SnapshotName(uint64_t value) : _value(value) {}
- explicit SnapshotName(Timestamp timestamp) : _value(timestamp.asULL()) {}
- SnapshotName() : _value(0) {}
-
- /**
- * Returns a SnapshotName guaranteed to compare < all names of actual snapshots.
- */
- static SnapshotName min() {
- return SnapshotName(std::numeric_limits<uint64_t>::min());
- }
-
- /**
- * Returns a SnapshotName guaranteed to compare > all names of actual snapshots.
- */
- static SnapshotName max() {
- return SnapshotName(std::numeric_limits<uint64_t>::max());
- }
-
- /**
- * Returns an unsigned number that compares with the same ordering as the SnapshotName.
- */
- uint64_t asU64() const {
- return _value;
- }
-
- std::string toString() const {
- return integerToHex(_value);
- }
-
- bool operator==(const SnapshotName& rhs) const {
- return _value == rhs._value;
- }
- bool operator!=(const SnapshotName& rhs) const {
- return _value != rhs._value;
- }
- bool operator<(const SnapshotName& rhs) const {
- return _value < rhs._value;
- }
- bool operator<=(const SnapshotName& rhs) const {
- return _value <= rhs._value;
- }
- bool operator>(const SnapshotName& rhs) const {
- return _value > rhs._value;
- }
- bool operator>=(const SnapshotName& rhs) const {
- return _value >= rhs._value;
- }
-
- friend std::ostream& operator<<(std::ostream& out, const SnapshotName& snapshotName) {
- return out << snapshotName.toString();
- }
-
-private:
- uint64_t _value;
-};
-}
diff --git a/src/mongo/db/storage/storage_engine.h b/src/mongo/db/storage/storage_engine.h
index 7af4e45b942..fe6a22dab44 100644
--- a/src/mongo/db/storage/storage_engine.h
+++ b/src/mongo/db/storage/storage_engine.h
@@ -35,7 +35,7 @@
#include "mongo/base/status.h"
#include "mongo/bson/bsonobj.h"
-#include "mongo/db/storage/snapshot_name.h"
+#include "mongo/bson/timestamp.h"
#include "mongo/util/mongoutils/str.h"
namespace mongo {
@@ -320,13 +320,13 @@ public:
* Sets the highest timestamp at which the storage engine is allowed to take a checkpoint.
* This timestamp can never decrease, and thus should be a timestamp that can never roll back.
*/
- virtual void setStableTimestamp(SnapshotName snapshotName) {}
+ virtual void setStableTimestamp(Timestamp timestamp) {}
/**
* Tells the storage engine the timestamp of the data at startup. This is necessary because
* timestamps are not persisted in the storage layer.
*/
- virtual void setInitialDataTimestamp(SnapshotName snapshotName) {}
+ virtual void setInitialDataTimestamp(Timestamp timestamp) {}
/**
* Notifies the storage engine that a replication batch has completed.
diff --git a/src/mongo/db/storage/storage_snapshot_name_test.cpp b/src/mongo/db/storage/storage_snapshot_name_test.cpp
deleted file mode 100644
index b4b7bebb33f..00000000000
--- a/src/mongo/db/storage/storage_snapshot_name_test.cpp
+++ /dev/null
@@ -1,48 +0,0 @@
-/**
- * Copyright (C) 2017 MongoDB Inc.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- * As a special exception, the copyright holders give permission to link the
- * code of portions of this program with the OpenSSL library under certain
- * conditions as described in each individual source file and distribute
- * linked combinations including the program with the OpenSSL library. You
- * must comply with the GNU Affero General Public License in all respects for
- * all of the code used other than as permitted herein. If you modify file(s)
- * with this exception, you may extend this exception to your version of the
- * file(s), but you are not obligated to do so. If you do not wish to do so,
- * delete this exception statement from your version. If you delete this
- * exception statement from all source files in the program, then also delete
- * it in the license file.
- */
-
-#include "mongo/platform/basic.h"
-
-#include <utility>
-#include <vector>
-
-#include "mongo/unittest/unittest.h"
-#include "snapshot_name.h"
-
-namespace mongo {
-TEST(SnapshotNameTest, TestToString) {
- std::vector<std::pair<uint64_t, std::string>> tests = {
- {1234, "4D2"},
- {1501697192, "598214A8"},
- {6449740328135032833, "598214A800000001"},
- {6449740328135037744, "598214A800001330"}};
- for (auto pair : tests) {
- ASSERT_EQUALS(pair.second, SnapshotName(pair.first).toString());
- }
-}
-} // namespace mongo
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp
index 509b6864744..efee60428e4 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp
@@ -163,8 +163,8 @@ public:
wiredTigerGlobalOptions.checkpointDelaySecs)));
}
- const SnapshotName stableTimestamp(_stableTimestamp.load());
- const SnapshotName initialDataTimestamp(_initialDataTimestamp.load());
+ const Timestamp stableTimestamp(_stableTimestamp.load());
+ const Timestamp initialDataTimestamp(_initialDataTimestamp.load());
const bool keepOldBehavior = true;
try {
@@ -186,7 +186,7 @@ public:
//
// Third, stableTimestamp >= initialDataTimestamp: Take stable
// checkpoint. Steady state case.
- if (initialDataTimestamp.asU64() <= 1) {
+ if (initialDataTimestamp.asULL() <= 1) {
const bool forceCheckpoint = true;
const bool stableCheckpoint = false;
_sessionCache->waitUntilDurable(forceCheckpoint, stableCheckpoint);
@@ -234,12 +234,12 @@ public:
return _stableTimestamp.load() > initialDataTimestamp;
}
- void setStableTimestamp(SnapshotName stableTimestamp) {
- _stableTimestamp.store(stableTimestamp.asU64());
+ void setStableTimestamp(Timestamp stableTimestamp) {
+ _stableTimestamp.store(stableTimestamp.asULL());
}
- void setInitialDataTimestamp(SnapshotName initialDataTimestamp) {
- _initialDataTimestamp.store(initialDataTimestamp.asU64());
+ void setInitialDataTimestamp(Timestamp initialDataTimestamp) {
+ _initialDataTimestamp.store(initialDataTimestamp.asULL());
}
void shutdown() {
@@ -995,7 +995,7 @@ bool WiredTigerKVEngine::initRsOplogBackgroundThread(StringData ns) {
return initRsOplogBackgroundThreadCallback(ns);
}
-void WiredTigerKVEngine::setStableTimestamp(SnapshotName stableTimestamp) {
+void WiredTigerKVEngine::setStableTimestamp(Timestamp stableTimestamp) {
const bool keepOldBehavior = true;
// Communicate to WiredTiger what the "stable timestamp" is. Timestamp-aware checkpoints will
// only persist to disk transactions committed with a timestamp earlier than the "stable
@@ -1025,8 +1025,8 @@ void WiredTigerKVEngine::setStableTimestamp(SnapshotName stableTimestamp) {
_setOldestTimestamp(stableTimestamp);
}
-void WiredTigerKVEngine::_setOldestTimestamp(SnapshotName oldestTimestamp) {
- if (oldestTimestamp == SnapshotName()) {
+void WiredTigerKVEngine::_setOldestTimestamp(Timestamp oldestTimestamp) {
+ if (oldestTimestamp == Timestamp()) {
// No oldestTimestamp to set, yet.
return;
}
@@ -1036,7 +1036,7 @@ void WiredTigerKVEngine::_setOldestTimestamp(SnapshotName oldestTimestamp) {
// No oplog yet, so don't bother setting oldest_timestamp.
return;
}
- if (_oplogManager->getOplogReadTimestamp() < oldestTimestamp.asU64()) {
+ if (_oplogManager->getOplogReadTimestamp() < oldestTimestamp.asULL()) {
// For one node replica sets, the commit point might race ahead of the oplog read
// timestamp.
// For now, we will simply avoid setting the oldestTimestamp in such cases.
@@ -1045,7 +1045,7 @@ void WiredTigerKVEngine::_setOldestTimestamp(SnapshotName oldestTimestamp) {
}
auto timestampToSet = _previousSetOldestTimestamp;
_previousSetOldestTimestamp = oldestTimestamp;
- if (timestampToSet == SnapshotName()) {
+ if (timestampToSet == Timestamp()) {
// Nothing to set yet.
return;
}
@@ -1055,7 +1055,7 @@ void WiredTigerKVEngine::_setOldestTimestamp(SnapshotName oldestTimestamp) {
auto size = std::snprintf(oldestTSConfigString,
sizeof(oldestTSConfigString),
"oldest_timestamp=%llx",
- static_cast<unsigned long long>(timestampToSet.asU64()));
+ timestampToSet.asULL());
if (size < 0) {
int e = errno;
error() << "error snprintf " << errnoWithDescription(e);
@@ -1063,10 +1063,10 @@ void WiredTigerKVEngine::_setOldestTimestamp(SnapshotName oldestTimestamp) {
}
invariant(static_cast<std::size_t>(size) < sizeof(oldestTSConfigString));
invariantWTOK(_conn->set_timestamp(_conn, oldestTSConfigString));
- LOG(2) << "oldest_timestamp set to " << timestampToSet.asU64();
+ LOG(2) << "oldest_timestamp set to " << timestampToSet;
}
-void WiredTigerKVEngine::setInitialDataTimestamp(SnapshotName initialDataTimestamp) {
+void WiredTigerKVEngine::setInitialDataTimestamp(Timestamp initialDataTimestamp) {
if (_checkpointThread) {
_checkpointThread->setInitialDataTimestamp(initialDataTimestamp);
}
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.h b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.h
index b34d12146f3..5f7ca29e13f 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.h
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.h
@@ -38,6 +38,7 @@
#include <wiredtiger.h>
#include "mongo/bson/ordering.h"
+#include "mongo/bson/timestamp.h"
#include "mongo/db/storage/kv/kv_engine.h"
#include "mongo/db/storage/wiredtiger/wiredtiger_oplog_manager.h"
#include "mongo/db/storage/wiredtiger/wiredtiger_session_cache.h"
@@ -162,9 +163,9 @@ public:
void setJournalListener(JournalListener* jl) final;
- virtual void setStableTimestamp(SnapshotName stableTimestamp) override;
+ virtual void setStableTimestamp(Timestamp stableTimestamp) override;
- virtual void setInitialDataTimestamp(SnapshotName initialDataTimestamp) override;
+ virtual void setInitialDataTimestamp(Timestamp initialDataTimestamp) override;
virtual bool supportsRecoverToStableTimestamp() const override;
@@ -246,8 +247,8 @@ private:
std::string _uri(StringData ident) const;
// Not threadsafe; callers must be serialized.
- void _setOldestTimestamp(SnapshotName oldestTimestamp);
- SnapshotName _previousSetOldestTimestamp;
+ void _setOldestTimestamp(Timestamp oldestTimestamp);
+ Timestamp _previousSetOldestTimestamp;
WT_CONNECTION* _conn;
WT_EVENT_HANDLER _eventHandler;
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_oplog_manager.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_oplog_manager.cpp
index b270fe8bcdc..8b8c130cba0 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_oplog_manager.cpp
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_oplog_manager.cpp
@@ -199,7 +199,7 @@ void WiredTigerOplogManager::_oplogJournalThreadLoop(WiredTigerSessionCache* ses
// For master/slave masters, set oldest timestamp here so that we clean up old timestamp
// data. SERVER-31802
if (isMasterSlave) {
- sessionCache->getKVEngine()->setStableTimestamp(SnapshotName(newTimestamp));
+ sessionCache->getKVEngine()->setStableTimestamp(Timestamp(newTimestamp));
}
}
}
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp
index 336b7d9d486..ac302cb4921 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp
@@ -1146,8 +1146,8 @@ Status WiredTigerRecordStore::_insertRecords(OperationContext* opCtx,
ts = timestamps[i];
}
if (!ts.isNull()) {
- LOG(4) << "inserting record with timestamp " << ts.asULL();
- fassertStatusOK(39001, opCtx->recoveryUnit()->setTimestamp(SnapshotName(ts)));
+ LOG(4) << "inserting record with timestamp " << ts;
+ fassertStatusOK(39001, opCtx->recoveryUnit()->setTimestamp(ts));
}
setKey(c, record.id);
WiredTigerItem value(record.data.data(), record.data.size());
@@ -1678,7 +1678,7 @@ Status WiredTigerRecordStore::oplogDiskLocRegister(OperationContext* opCtx,
// This labels the current transaction with a timestamp.
// This is required for oplog visibility to work correctly, as WiredTiger uses the transaction
// list to determine where there are holes in the oplog.
- return opCtx->recoveryUnit()->setTimestamp(SnapshotName(opTime));
+ return opCtx->recoveryUnit()->setTimestamp(opTime);
}
// Cursor Base:
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.cpp
index 54db183fe36..fa0d2d2b66d 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.cpp
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.cpp
@@ -39,6 +39,7 @@
#include "mongo/db/storage/wiredtiger/wiredtiger_kv_engine.h"
#include "mongo/db/storage/wiredtiger/wiredtiger_session_cache.h"
#include "mongo/db/storage/wiredtiger/wiredtiger_util.h"
+#include "mongo/util/hex.h"
#include "mongo/util/log.h"
namespace mongo {
@@ -237,7 +238,7 @@ Status WiredTigerRecoveryUnit::setReadFromMajorityCommittedSnapshot() {
return Status::OK();
}
-boost::optional<SnapshotName> WiredTigerRecoveryUnit::getMajorityCommittedSnapshot() const {
+boost::optional<Timestamp> WiredTigerRecoveryUnit::getMajorityCommittedSnapshot() const {
if (!_readFromMajorityCommittedSnapshot)
return {};
return _majorityCommittedSnapshot;
@@ -253,7 +254,7 @@ void WiredTigerRecoveryUnit::_txnOpen() {
}
WT_SESSION* session = _session->getSession();
- if (_readAtTimestamp != SnapshotName::min()) {
+ if (_readAtTimestamp != Timestamp::min()) {
uassertStatusOK(_sessionCache->snapshotManager().beginTransactionAtTimestamp(
_readAtTimestamp, session));
} else if (_readFromMajorityCommittedSnapshot) {
@@ -271,7 +272,7 @@ void WiredTigerRecoveryUnit::_txnOpen() {
}
-Status WiredTigerRecoveryUnit::setTimestamp(SnapshotName timestamp) {
+Status WiredTigerRecoveryUnit::setTimestamp(Timestamp timestamp) {
_ensureSession();
LOG(3) << "WT set timestamp of future write operations to " << timestamp;
WT_SESSION* session = _session->getSession();
@@ -280,7 +281,7 @@ Status WiredTigerRecoveryUnit::setTimestamp(SnapshotName timestamp) {
// Starts the WT transaction associated with this session.
getSession();
- const std::string conf = "commit_timestamp=" + timestamp.toString();
+ const std::string conf = "commit_timestamp=" + integerToHex(timestamp.asULL());
auto rc = session->timestamp_transaction(session, conf.c_str());
if (rc == 0) {
_isTimestamped = true;
@@ -288,7 +289,7 @@ Status WiredTigerRecoveryUnit::setTimestamp(SnapshotName timestamp) {
return wtRCToStatus(rc, "timestamp_transaction");
}
-Status WiredTigerRecoveryUnit::selectSnapshot(SnapshotName timestamp) {
+Status WiredTigerRecoveryUnit::selectSnapshot(Timestamp timestamp) {
_readAtTimestamp = timestamp;
return Status::OK();
}
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.h b/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.h
index a1040952dc3..5da0d2987fb 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.h
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.h
@@ -36,10 +36,10 @@
#include <vector>
#include "mongo/base/checked_cast.h"
+#include "mongo/bson/timestamp.h"
#include "mongo/db/operation_context.h"
#include "mongo/db/record_id.h"
#include "mongo/db/storage/recovery_unit.h"
-#include "mongo/db/storage/snapshot_name.h"
#include "mongo/db/storage/wiredtiger/wiredtiger_session_cache.h"
#include "mongo/util/timer.h"
@@ -77,13 +77,13 @@ public:
return _readFromMajorityCommittedSnapshot;
}
- boost::optional<SnapshotName> getMajorityCommittedSnapshot() const override;
+ boost::optional<Timestamp> getMajorityCommittedSnapshot() const override;
SnapshotId getSnapshotId() const override;
- Status setTimestamp(SnapshotName timestamp) override;
+ Status setTimestamp(Timestamp timestamp) override;
- Status selectSnapshot(SnapshotName timestamp) override;
+ Status selectSnapshot(Timestamp timestamp) override;
void* writingPtr(void* data, size_t len) override;
@@ -148,8 +148,8 @@ private:
bool _isTimestamped = false;
uint64_t _mySnapshotId;
bool _readFromMajorityCommittedSnapshot = false;
- SnapshotName _majorityCommittedSnapshot = SnapshotName::min();
- SnapshotName _readAtTimestamp = SnapshotName::min();
+ Timestamp _majorityCommittedSnapshot;
+ Timestamp _readAtTimestamp;
std::unique_ptr<Timer> _timer;
bool _isOplogReader = false;
typedef std::vector<std::unique_ptr<Change>> Changes;
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_snapshot_manager.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_snapshot_manager.cpp
index a666ad6d5cb..a554015102b 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_snapshot_manager.cpp
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_snapshot_manager.cpp
@@ -50,11 +50,11 @@ Status WiredTigerSnapshotManager::prepareForCreateSnapshot(OperationContext* opC
return Status::OK();
}
-void WiredTigerSnapshotManager::setCommittedSnapshot(const SnapshotName& name, Timestamp ts) {
+void WiredTigerSnapshotManager::setCommittedSnapshot(const Timestamp& timestamp) {
stdx::lock_guard<stdx::mutex> lock(_mutex);
- invariant(!_committedSnapshot || *_committedSnapshot <= name);
- _committedSnapshot = name;
+ invariant(!_committedSnapshot || *_committedSnapshot <= timestamp);
+ _committedSnapshot = timestamp;
}
void WiredTigerSnapshotManager::cleanupUnneededSnapshots() {}
@@ -72,20 +72,17 @@ void WiredTigerSnapshotManager::shutdown() {
_session = nullptr;
}
-boost::optional<SnapshotName> WiredTigerSnapshotManager::getMinSnapshotForNextCommittedRead()
- const {
+boost::optional<Timestamp> WiredTigerSnapshotManager::getMinSnapshotForNextCommittedRead() const {
stdx::lock_guard<stdx::mutex> lock(_mutex);
return _committedSnapshot;
}
-Status WiredTigerSnapshotManager::beginTransactionAtTimestamp(SnapshotName pointInTime,
+Status WiredTigerSnapshotManager::beginTransactionAtTimestamp(Timestamp pointInTime,
WT_SESSION* session) const {
char readTSConfigString[15 /* read_timestamp= */ + (8 * 2) /* 8 hexadecimal characters */ +
1 /* trailing null */];
- auto size = std::snprintf(readTSConfigString,
- sizeof(readTSConfigString),
- "read_timestamp=%llx",
- static_cast<unsigned long long>(pointInTime.asU64()));
+ auto size = std::snprintf(
+ readTSConfigString, sizeof(readTSConfigString), "read_timestamp=%llx", pointInTime.asULL());
if (size < 0) {
int e = errno;
error() << "error snprintf " << errnoWithDescription(e);
@@ -96,13 +93,14 @@ Status WiredTigerSnapshotManager::beginTransactionAtTimestamp(SnapshotName point
return wtRCToStatus(session->begin_transaction(session, readTSConfigString));
}
-SnapshotName WiredTigerSnapshotManager::beginTransactionOnCommittedSnapshot(
+Timestamp WiredTigerSnapshotManager::beginTransactionOnCommittedSnapshot(
WT_SESSION* session) const {
stdx::lock_guard<stdx::mutex> lock(_mutex);
uassert(ErrorCodes::ReadConcernMajorityNotAvailableYet,
"Committed view disappeared while running operation",
_committedSnapshot);
+
auto status = beginTransactionAtTimestamp(_committedSnapshot.get(), session);
fassertStatusOK(30635, status);
return *_committedSnapshot;
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_snapshot_manager.h b/src/mongo/db/storage/wiredtiger/wiredtiger_snapshot_manager.h
index 2609b396e24..b3853206bcc 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_snapshot_manager.h
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_snapshot_manager.h
@@ -33,6 +33,7 @@
#include <wiredtiger.h>
#include "mongo/base/disallow_copying.h"
+#include "mongo/bson/timestamp.h"
#include "mongo/db/storage/snapshot_manager.h"
#include "mongo/db/storage/wiredtiger/wiredtiger_util.h"
#include "mongo/stdx/mutex.h"
@@ -55,7 +56,7 @@ public:
}
Status prepareForCreateSnapshot(OperationContext* opCtx) final;
- void setCommittedSnapshot(const SnapshotName& name, Timestamp ts) final;
+ void setCommittedSnapshot(const Timestamp& timestamp) final;
void cleanupUnneededSnapshots() final;
void dropAllSnapshots() final;
@@ -68,14 +69,14 @@ public:
*/
void shutdown();
- Status beginTransactionAtTimestamp(SnapshotName pointInTime, WT_SESSION* session) const;
+ Status beginTransactionAtTimestamp(Timestamp pointInTime, WT_SESSION* session) const;
/**
* Starts a transaction and returns the SnapshotName used.
*
* Throws if there is currently no committed snapshot.
*/
- SnapshotName beginTransactionOnCommittedSnapshot(WT_SESSION* session) const;
+ Timestamp beginTransactionOnCommittedSnapshot(WT_SESSION* session) const;
/**
* Starts a transaction on the oplog using an appropriate timestamp for oplog visiblity.
@@ -90,11 +91,11 @@ public:
* This should not be used for starting a transaction on this SnapshotName since the named
* snapshot may be deleted by the time you start the transaction.
*/
- boost::optional<SnapshotName> getMinSnapshotForNextCommittedRead() const;
+ boost::optional<Timestamp> getMinSnapshotForNextCommittedRead() const;
private:
mutable stdx::mutex _mutex; // Guards all members.
- boost::optional<SnapshotName> _committedSnapshot;
+ boost::optional<Timestamp> _committedSnapshot;
WT_SESSION* _session;
WT_CONNECTION* _conn;
};