diff options
author | Daniel Gottlieb <daniel.gottlieb@mongodb.com> | 2017-08-02 21:06:14 -0400 |
---|---|---|
committer | Daniel Gottlieb <daniel.gottlieb@mongodb.com> | 2017-08-02 21:06:14 -0400 |
commit | 4cfb89fa0ed61b6ea8f63a1452561cd95ffe0626 (patch) | |
tree | 9a1690eb097ec5e0c4cc917b4daf9daa83960de4 | |
parent | 64313d4e689558b501bf924f2b2b3040269b285f (diff) | |
download | mongo-4cfb89fa0ed61b6ea8f63a1452561cd95ffe0626.tar.gz |
SERVER-30309: Stage changes for supportsRecoverToStableTimestamp
-rw-r--r-- | src/mongo/bson/timestamp.cpp | 2 | ||||
-rw-r--r-- | src/mongo/bson/timestamp.h | 2 | ||||
-rw-r--r-- | src/mongo/db/repl/initial_syncer.cpp | 2 | ||||
-rw-r--r-- | src/mongo/db/repl/initial_syncer_test.cpp | 2 | ||||
-rw-r--r-- | src/mongo/db/storage/kv/kv_engine.h | 7 | ||||
-rw-r--r-- | src/mongo/db/storage/kv/kv_storage_engine.cpp | 4 | ||||
-rw-r--r-- | src/mongo/db/storage/kv/kv_storage_engine.h | 2 | ||||
-rw-r--r-- | src/mongo/db/storage/storage_engine.h | 3 | ||||
-rw-r--r-- | src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp | 35 | ||||
-rw-r--r-- | src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.h | 2 |
10 files changed, 55 insertions, 6 deletions
diff --git a/src/mongo/bson/timestamp.cpp b/src/mongo/bson/timestamp.cpp index 24d78241dfc..7918b9101a7 100644 --- a/src/mongo/bson/timestamp.cpp +++ b/src/mongo/bson/timestamp.cpp @@ -39,7 +39,7 @@ namespace mongo { -const Timestamp Timestamp::kAllowUnstableCheckpointsSentinal = Timestamp(0, 1); +const Timestamp Timestamp::kAllowUnstableCheckpointsSentinel = Timestamp(0, 1); Timestamp Timestamp::max() { unsigned int t = static_cast<unsigned int>(std::numeric_limits<uint32_t>::max()); diff --git a/src/mongo/bson/timestamp.h b/src/mongo/bson/timestamp.h index 2c1f96e3caa..c600e2e6eff 100644 --- a/src/mongo/bson/timestamp.h +++ b/src/mongo/bson/timestamp.h @@ -42,7 +42,7 @@ class BSONObj; class Timestamp { public: // Timestamp to signal that the storage engine should take unstable checkpoints. - static const Timestamp kAllowUnstableCheckpointsSentinal; + static const Timestamp kAllowUnstableCheckpointsSentinel; // Maximum Timestamp value. static Timestamp max(); diff --git a/src/mongo/db/repl/initial_syncer.cpp b/src/mongo/db/repl/initial_syncer.cpp index cdba4798a16..1e86e011c2f 100644 --- a/src/mongo/db/repl/initial_syncer.cpp +++ b/src/mongo/db/repl/initial_syncer.cpp @@ -395,7 +395,7 @@ void InitialSyncer::_setUp_inlock(OperationContext* opCtx, std::uint32_t initial // 'opCtx' is passed through from startup(). _replicationProcess->getConsistencyMarkers()->setInitialSyncFlag(opCtx); _storage->setInitialDataTimestamp(opCtx, - SnapshotName(Timestamp::kAllowUnstableCheckpointsSentinal)); + SnapshotName(Timestamp::kAllowUnstableCheckpointsSentinel)); _storage->setStableTimestamp(opCtx, SnapshotName::min()); LOG(1) << "Creating oplogBuffer."; diff --git a/src/mongo/db/repl/initial_syncer_test.cpp b/src/mongo/db/repl/initial_syncer_test.cpp index c43be289add..2a402f2ff06 100644 --- a/src/mongo/db/repl/initial_syncer_test.cpp +++ b/src/mongo/db/repl/initial_syncer_test.cpp @@ -630,7 +630,7 @@ TEST_F(InitialSyncerTest, StartupSetsInitialDataTimestampAndStableTimestampOnSuc ASSERT_OK(initialSyncer->startup(opCtx.get(), maxAttempts)); ASSERT_TRUE(initialSyncer->isActive()); - ASSERT_EQUALS(SnapshotName(Timestamp::kAllowUnstableCheckpointsSentinal), + ASSERT_EQUALS(SnapshotName(Timestamp::kAllowUnstableCheckpointsSentinel), _storageInterface->getInitialDataTimestamp()); ASSERT_EQUALS(SnapshotName::min(), _storageInterface->getStableTimestamp()); } diff --git a/src/mongo/db/storage/kv/kv_engine.h b/src/mongo/db/storage/kv/kv_engine.h index 39f6110ff83..2f10701691f 100644 --- a/src/mongo/db/storage/kv/kv_engine.h +++ b/src/mongo/db/storage/kv/kv_engine.h @@ -250,6 +250,13 @@ public: virtual void setInitialDataTimestamp(SnapshotName initialDataTimestamp) {} /** + * See `StorageEngine::supportsRecoverToStableTimestamp` + */ + virtual bool supportsRecoverToStableTimestamp() const { + return false; + } + + /** * The destructor will never be called from mongod, but may be called from tests. * Engines may assume that this will only be called in the case of clean shutdown, even if * cleanShutdown() hasn't been called. diff --git a/src/mongo/db/storage/kv/kv_storage_engine.cpp b/src/mongo/db/storage/kv/kv_storage_engine.cpp index 89ffa97bbc6..79bb56028a1 100644 --- a/src/mongo/db/storage/kv/kv_storage_engine.cpp +++ b/src/mongo/db/storage/kv/kv_storage_engine.cpp @@ -309,4 +309,8 @@ void KVStorageEngine::setInitialDataTimestamp(SnapshotName initialDataTimestamp) _engine->setInitialDataTimestamp(initialDataTimestamp); } +bool KVStorageEngine::supportsRecoverToStableTimestamp() const { + return _engine->supportsRecoverToStableTimestamp(); +} + } // namespace mongo diff --git a/src/mongo/db/storage/kv/kv_storage_engine.h b/src/mongo/db/storage/kv/kv_storage_engine.h index dae157064a1..40a5908c186 100644 --- a/src/mongo/db/storage/kv/kv_storage_engine.h +++ b/src/mongo/db/storage/kv/kv_storage_engine.h @@ -111,6 +111,8 @@ public: virtual void setInitialDataTimestamp(SnapshotName initialDataTimestamp) override; + virtual bool supportsRecoverToStableTimestamp() const override; + SnapshotManager* getSnapshotManager() const final; void setJournalListener(JournalListener* jl) final; diff --git a/src/mongo/db/storage/storage_engine.h b/src/mongo/db/storage/storage_engine.h index 64428fdfd43..7e9d77641c3 100644 --- a/src/mongo/db/storage/storage_engine.h +++ b/src/mongo/db/storage/storage_engine.h @@ -286,6 +286,9 @@ public: * if the storage engine supports the "recover to stable timestamp" feature but does not have * a stable timestamp, or if for some reason the storage engine is unable to recover to the * last provided stable timestamp. + * + * It is illegal to call this concurrently with `setStableTimestamp` or + * `setInitialDataTimestamp`. */ virtual bool supportsRecoverToStableTimestamp() const { return false; diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp index d841c3eca5c..ce780e182ba 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp @@ -207,11 +207,34 @@ public: LOG(1) << "stopping " << name() << " thread"; } - virtual void setStableTimestamp(SnapshotName stableTimestamp) { + bool supportsRecoverToStableTimestamp() { + // Replication is calling this method, however it is not setting the + // `_initialDataTimestamp` in all necessary cases. This may be removed when replication + // believes all sets of `_initialDataTimestamp` are correct. See SERVER-30184, + // SERVER-30185, SERVER-30335. + const bool keepOldBehavior = true; + if (keepOldBehavior) { + return false; + } + + static const std::uint64_t allowUnstableCheckpointsSentinel = + static_cast<std::uint64_t>(Timestamp::kAllowUnstableCheckpointsSentinel.asULL()); + const std::uint64_t initialDataTimestamp = _initialDataTimestamp.load(); + // Illegal to be called when the dataset is incomplete. + invariant(initialDataTimestamp > allowUnstableCheckpointsSentinel); + + // Must return false until `recoverToStableTimestamp` is implemented. See SERVER-29213. + if (keepOldBehavior) { + return false; + } + return _stableTimestamp.load() > initialDataTimestamp; + } + + void setStableTimestamp(SnapshotName stableTimestamp) { _stableTimestamp.store(stableTimestamp.asU64()); } - virtual void setInitialDataTimestamp(SnapshotName initialDataTimestamp) { + void setInitialDataTimestamp(SnapshotName initialDataTimestamp) { _initialDataTimestamp.store(initialDataTimestamp.asU64()); } @@ -981,4 +1004,12 @@ void WiredTigerKVEngine::setStableTimestamp(SnapshotName stableTimestamp) { void WiredTigerKVEngine::setInitialDataTimestamp(SnapshotName initialDataTimestamp) { _checkpointThread->setInitialDataTimestamp(initialDataTimestamp); } + +bool WiredTigerKVEngine::supportsRecoverToStableTimestamp() const { + if (_ephemeral) { + return false; + } + + return _checkpointThread->supportsRecoverToStableTimestamp(); +} } // namespace mongo diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.h b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.h index 2849e8f3cf4..383935c937d 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.h +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.h @@ -164,6 +164,8 @@ public: virtual void setInitialDataTimestamp(SnapshotName initialDataTimestamp) override; + virtual bool supportsRecoverToStableTimestamp() const override; + // wiredtiger specific // Calls WT_CONNECTION::reconfigure on the underlying WT_CONNECTION // held by this class |