diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/mongo/db/auth/auth_op_observer.h | 3 | ||||
-rw-r--r-- | src/mongo/db/free_mon/free_mon_op_observer.h | 3 | ||||
-rw-r--r-- | src/mongo/db/op_observer.h | 10 | ||||
-rw-r--r-- | src/mongo/db/op_observer_impl.h | 2 | ||||
-rw-r--r-- | src/mongo/db/op_observer_noop.h | 2 | ||||
-rw-r--r-- | src/mongo/db/op_observer_registry.h | 6 | ||||
-rw-r--r-- | src/mongo/db/repl/replication_coordinator_external_state_impl.cpp | 1 | ||||
-rw-r--r-- | src/mongo/db/s/config_server_op_observer.cpp | 7 | ||||
-rw-r--r-- | src/mongo/db/s/config_server_op_observer.h | 3 | ||||
-rw-r--r-- | src/mongo/db/s/config_server_op_observer_test.cpp | 13 | ||||
-rw-r--r-- | src/mongo/db/s/shard_server_op_observer.h | 2 | ||||
-rw-r--r-- | src/mongo/s/grid.cpp | 8 | ||||
-rw-r--r-- | src/mongo/s/grid.h | 9 |
13 files changed, 67 insertions, 2 deletions
diff --git a/src/mongo/db/auth/auth_op_observer.h b/src/mongo/db/auth/auth_op_observer.h index 45f9d56b099..5920146860e 100644 --- a/src/mongo/db/auth/auth_op_observer.h +++ b/src/mongo/db/auth/auth_op_observer.h @@ -180,6 +180,9 @@ public: void onReplicationRollback(OperationContext* opCtx, const RollbackObserverInfo& rbInfo); + void onMajorityCommitPointUpdate(ServiceContext* service, + const repl::OpTime& newCommitPoint) final {} + // Contains the fields of the document that are in the collection's shard key, and "_id". static BSONObj getDocumentKey(OperationContext* opCtx, NamespaceString const& nss, diff --git a/src/mongo/db/free_mon/free_mon_op_observer.h b/src/mongo/db/free_mon/free_mon_op_observer.h index 4408d1d76ac..30642076e7e 100644 --- a/src/mongo/db/free_mon/free_mon_op_observer.h +++ b/src/mongo/db/free_mon/free_mon_op_observer.h @@ -179,6 +179,9 @@ public: boost::optional<OplogSlot> abortOplogEntryOpTime) final {} void onReplicationRollback(OperationContext* opCtx, const RollbackObserverInfo& rbInfo); + + void onMajorityCommitPointUpdate(ServiceContext* service, + const repl::OpTime& newCommitPoint) final {} }; } // namespace mongo diff --git a/src/mongo/db/op_observer.h b/src/mongo/db/op_observer.h index b970643444a..aefdf1fc04e 100644 --- a/src/mongo/db/op_observer.h +++ b/src/mongo/db/op_observer.h @@ -395,6 +395,16 @@ public: virtual void onReplicationRollback(OperationContext* opCtx, const RollbackObserverInfo& rbInfo) = 0; + /** + * Called when the majority commit point is updated by replication. + * + * This is called while holding a very hot mutex (the ReplicationCoordinator mutex). Therefore + * it should avoid doing any work that can be done later, and avoid calling back into any + * replication functions that take this mutex (which would cause self-deadlock). + */ + virtual void onMajorityCommitPointUpdate(ServiceContext* service, + const repl::OpTime& newCommitPoint) = 0; + struct Times; protected: diff --git a/src/mongo/db/op_observer_impl.h b/src/mongo/db/op_observer_impl.h index e61f14e6e2c..dcc82c6605a 100644 --- a/src/mongo/db/op_observer_impl.h +++ b/src/mongo/db/op_observer_impl.h @@ -155,6 +155,8 @@ public: void onTransactionAbort(OperationContext* opCtx, boost::optional<OplogSlot> abortOplogEntryOpTime) final; void onReplicationRollback(OperationContext* opCtx, const RollbackObserverInfo& rbInfo) final; + void onMajorityCommitPointUpdate(ServiceContext* service, + const repl::OpTime& newCommitPoint) final {} // Contains the fields of the document that are in the collection's shard key, and "_id". static BSONObj getDocumentKey(OperationContext* opCtx, diff --git a/src/mongo/db/op_observer_noop.h b/src/mongo/db/op_observer_noop.h index 3684625cc27..f3636fdc43f 100644 --- a/src/mongo/db/op_observer_noop.h +++ b/src/mongo/db/op_observer_noop.h @@ -156,6 +156,8 @@ public: boost::optional<OplogSlot> abortOplogEntryOpTime) override{}; void onReplicationRollback(OperationContext* opCtx, const RollbackObserverInfo& rbInfo) override {} + void onMajorityCommitPointUpdate(ServiceContext* service, + const repl::OpTime& newCommitPoint) override {} }; } // namespace mongo diff --git a/src/mongo/db/op_observer_registry.h b/src/mongo/db/op_observer_registry.h index 9bc29820269..9ce4ec255a0 100644 --- a/src/mongo/db/op_observer_registry.h +++ b/src/mongo/db/op_observer_registry.h @@ -311,6 +311,12 @@ public: o->onReplicationRollback(opCtx, rbInfo); } + void onMajorityCommitPointUpdate(ServiceContext* service, + const repl::OpTime& newCommitPoint) override { + for (auto& o : _observers) + o->onMajorityCommitPointUpdate(service, newCommitPoint); + } + private: static repl::OpTime _getOpTimeToReturn(const std::vector<repl::OpTime>& times) { if (times.empty()) { diff --git a/src/mongo/db/repl/replication_coordinator_external_state_impl.cpp b/src/mongo/db/repl/replication_coordinator_external_state_impl.cpp index 61c30f2b6e4..c8b740275ad 100644 --- a/src/mongo/db/repl/replication_coordinator_external_state_impl.cpp +++ b/src/mongo/db/repl/replication_coordinator_external_state_impl.cpp @@ -962,6 +962,7 @@ void ReplicationCoordinatorExternalStateImpl::updateCommittedSnapshot( if (manager) { manager->setCommittedSnapshot(newCommitPoint.getTimestamp()); } + _service->getOpObserver()->onMajorityCommitPointUpdate(_service, newCommitPoint); notifyOplogMetadataWaiters(newCommitPoint); } diff --git a/src/mongo/db/s/config_server_op_observer.cpp b/src/mongo/db/s/config_server_op_observer.cpp index 30927f2372c..13e1d91378e 100644 --- a/src/mongo/db/s/config_server_op_observer.cpp +++ b/src/mongo/db/s/config_server_op_observer.cpp @@ -36,6 +36,7 @@ #include "mongo/db/s/config/sharding_catalog_manager.h" #include "mongo/s/catalog/type_config_version.h" #include "mongo/s/cluster_identity_loader.h" +#include "mongo/s/grid.h" namespace mongo { @@ -91,4 +92,10 @@ void ConfigServerOpObserver::onReplicationRollback(OperationContext* opCtx, } } +void ConfigServerOpObserver::onMajorityCommitPointUpdate(ServiceContext* service, + const repl::OpTime& newCommitPoint) { + // TODO SERVER-46200: tick the VectorClock's ConfigTime. + Grid::get(service)->advanceConfigOpTimeAuthoritative(newCommitPoint); +} + } // namespace mongo diff --git a/src/mongo/db/s/config_server_op_observer.h b/src/mongo/db/s/config_server_op_observer.h index ca17153d814..b34827afba0 100644 --- a/src/mongo/db/s/config_server_op_observer.h +++ b/src/mongo/db/s/config_server_op_observer.h @@ -180,6 +180,9 @@ public: boost::optional<OplogSlot> abortOplogEntryOpTime) override {} void onReplicationRollback(OperationContext* opCtx, const RollbackObserverInfo& rbInfo); + + void onMajorityCommitPointUpdate(ServiceContext* service, + const repl::OpTime& newCommitPoint) override; }; } // namespace mongo diff --git a/src/mongo/db/s/config_server_op_observer_test.cpp b/src/mongo/db/s/config_server_op_observer_test.cpp index de05c419fef..e7383bdab54 100644 --- a/src/mongo/db/s/config_server_op_observer_test.cpp +++ b/src/mongo/db/s/config_server_op_observer_test.cpp @@ -95,5 +95,18 @@ TEST_F(ConfigServerOpObserverTest, NodeDoesNotClearClusterIDWhenConfigVersionNot ASSERT_EQ(ClusterIdentityLoader::get(operationContext())->getClusterId(), _clusterId); } +TEST_F(ConfigServerOpObserverTest, ConfigOpTimeAdvancedWhenMajorityCommitPointAdvanced) { + ConfigServerOpObserver opObserver; + + repl::OpTime a(Timestamp(1, 1), 1); + repl::OpTime b(Timestamp(1, 2), 1); + + opObserver.onMajorityCommitPointUpdate(getServiceContext(), a); + // TODO SERVER-46200: Verify that configOpTime is a. + + opObserver.onMajorityCommitPointUpdate(getServiceContext(), b); + // TODO SERVER-46200: Verify that configOpTime is b. +} + } // namespace } // namespace mongo diff --git a/src/mongo/db/s/shard_server_op_observer.h b/src/mongo/db/s/shard_server_op_observer.h index 481b4619836..f2edb1138d2 100644 --- a/src/mongo/db/s/shard_server_op_observer.h +++ b/src/mongo/db/s/shard_server_op_observer.h @@ -179,6 +179,8 @@ public: boost::optional<OplogSlot> abortOplogEntryOpTime) override {} void onReplicationRollback(OperationContext* opCtx, const RollbackObserverInfo& rbInfo) {} + void onMajorityCommitPointUpdate(ServiceContext* service, + const repl::OpTime& newCommitPoint) override {} }; } // namespace mongo diff --git a/src/mongo/s/grid.cpp b/src/mongo/s/grid.cpp index ad83cfc0a1c..dbc42a8e20e 100644 --- a/src/mongo/s/grid.cpp +++ b/src/mongo/s/grid.cpp @@ -124,6 +124,7 @@ repl::OpTime Grid::configOpTime() const { boost::optional<repl::OpTime> Grid::advanceConfigOpTime(OperationContext* opCtx, repl::OpTime opTime, StringData what) { + invariant(serverGlobalParams.clusterRole != ClusterRole::ConfigServer); const auto prevOpTime = _advanceConfigOpTime(opTime); if (prevOpTime && prevOpTime->getTerm() != opTime.getTerm()) { std::string clientAddr = "(unknown)"; @@ -142,9 +143,12 @@ boost::optional<repl::OpTime> Grid::advanceConfigOpTime(OperationContext* opCtx, return prevOpTime; } -boost::optional<repl::OpTime> Grid::_advanceConfigOpTime(const repl::OpTime& opTime) { - invariant(serverGlobalParams.clusterRole != ClusterRole::ConfigServer); +boost::optional<repl::OpTime> Grid::advanceConfigOpTimeAuthoritative(repl::OpTime opTime) { + invariant(serverGlobalParams.clusterRole == ClusterRole::ConfigServer); + return _advanceConfigOpTime(opTime); +} +boost::optional<repl::OpTime> Grid::_advanceConfigOpTime(const repl::OpTime& opTime) { stdx::lock_guard<Latch> lk(_mutex); if (_configOpTime < opTime) { repl::OpTime prev = _configOpTime; diff --git a/src/mongo/s/grid.h b/src/mongo/s/grid.h index 0bd14b9c5cf..861fa3f159c 100644 --- a/src/mongo/s/grid.h +++ b/src/mongo/s/grid.h @@ -163,6 +163,15 @@ public: StringData what); /** + * Called whenever a config server's majority committed optime changes. + * If the config optime was updated, returns the previous value. + * NOTE: This is ONLY valid to call on a config server instance. + */ + // TODO SERVER-46200: remove this once the ConfigServerOpObserver is calling into the + // VectorClock, rather than here. + boost::optional<repl::OpTime> advanceConfigOpTimeAuthoritative(repl::OpTime opTime); + + /** * Clears the grid object so that it can be reused between test executions. This will not * be necessary if grid is hanging off the global ServiceContext and each test gets its * own service context. |