diff options
4 files changed, 28 insertions, 19 deletions
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp index 9752fa11c0e..5b997420fce 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp @@ -1018,6 +1018,28 @@ void WiredTigerKVEngine::setStableTimestamp(SnapshotName stableTimestamp) { if (_checkpointThread) { _checkpointThread->setStableTimestamp(stableTimestamp); } + + // Communicate to WiredTiger that it can clean up timestamp data earlier than the timestamp + // provided. No future queries will need point-in-time reads at a timestamp prior to the one + // provided here. + _setOldestTimestamp(stableTimestamp); +} + +void WiredTigerKVEngine::_setOldestTimestamp(SnapshotName oldestTimestamp) { + if (oldestTimestamp == SnapshotName()) { + // No oldestTimestamp to set, yet. + return; + } + + char oldestTSConfigString["oldest_timestamp="_sd.size() + (8 * 2) /* 16 hexadecimal digits */ + + 1 /* trailing null */]; + auto size = std::snprintf(oldestTSConfigString, + sizeof(oldestTSConfigString), + "oldest_timestamp=%llx", + static_cast<unsigned long long>(oldestTimestamp.asU64())); + invariant(static_cast<std::size_t>(size) < sizeof(oldestTSConfigString)); + invariantWTOK(_conn->set_timestamp(_conn, oldestTSConfigString)); + LOG(2) << "oldest_timestamp set to " << oldestTSConfigString; } void WiredTigerKVEngine::setInitialDataTimestamp(SnapshotName initialDataTimestamp) { diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.h b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.h index b9758b814e1..088bebf40b2 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.h +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.h @@ -236,6 +236,8 @@ private: std::string _uri(StringData ident) const; bool _drop(StringData ident); + void _setOldestTimestamp(SnapshotName oldestTimestamp); + WT_CONNECTION* _conn; WT_EVENT_HANDLER _eventHandler; std::unique_ptr<WiredTigerSessionCache> _sessionCache; diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_snapshot_manager.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_snapshot_manager.cpp index cd58ea18a13..a9204b3fefa 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_snapshot_manager.cpp +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_snapshot_manager.cpp @@ -61,15 +61,6 @@ void WiredTigerSnapshotManager::setCommittedSnapshot(const SnapshotName& name, T invariant(!_committedSnapshot || *_committedSnapshot <= name); _committedSnapshot = name; - - char oldestTSConfigString["oldest_timestamp="_sd.size() + (8 * 2) /* 16 hexadecimal digits */ + - 1 /* trailing null */]; - auto size = std::snprintf( - oldestTSConfigString, sizeof(oldestTSConfigString), "oldest_timestamp=%llx", ts.asULL()); - invariant(static_cast<std::size_t>(size) < sizeof(oldestTSConfigString)); - invariantWTOK(_conn->set_timestamp(_conn, oldestTSConfigString)); - _oldestKeptTimestamp = ts; - LOG(2) << "oldest_timestamp set to " << oldestTSConfigString; } void WiredTigerSnapshotManager::cleanupUnneededSnapshots() { @@ -124,16 +115,12 @@ void WiredTigerSnapshotManager::beginTransactionOnOplog(WiredTigerOplogManager* auto allCommittedTimestamp = oplogManager->getOplogReadTimestamp(); stdx::lock_guard<stdx::mutex> lock(_mutex); - // Choose a read timestamp that is >= oldest_timestamp, but <= all_committed. - // Using "unsigned long long" here to ensure that the snprintf works with %llx on all - // platforms. - unsigned long long readTimestamp = - std::max<std::uint64_t>(allCommittedTimestamp, _oldestKeptTimestamp.asULL()); - char readTSConfigString[15 /* read_timestamp= */ + (8 * 2) /* 16 hexadecimal digits */ + 1 /* trailing null */]; - auto size = std::snprintf( - readTSConfigString, sizeof(readTSConfigString), "read_timestamp=%llx", readTimestamp); + auto size = std::snprintf(readTSConfigString, + sizeof(readTSConfigString), + "read_timestamp=%llx", + static_cast<unsigned long long>(allCommittedTimestamp)); invariant(static_cast<std::size_t>(size) < sizeof(readTSConfigString)); invariantWTOK(session->begin_transaction(session, readTSConfigString)); } diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_snapshot_manager.h b/src/mongo/db/storage/wiredtiger/wiredtiger_snapshot_manager.h index 96e574402b0..a80a72ff7e9 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_snapshot_manager.h +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_snapshot_manager.h @@ -94,8 +94,6 @@ public: private: mutable stdx::mutex _mutex; // Guards all members. boost::optional<SnapshotName> _committedSnapshot; - Timestamp _oldestKeptTimestamp; // The timestamp communicated to WiredTiger before which no - // timestamp history is preserved. WT_SESSION* _session; WT_CONNECTION* _conn; }; |