diff options
Diffstat (limited to 'src')
21 files changed, 98 insertions, 268 deletions
diff --git a/src/mongo/db/s/collmod_coordinator.cpp b/src/mongo/db/s/collmod_coordinator.cpp index 3ec0db50ec5..50e92b41571 100644 --- a/src/mongo/db/s/collmod_coordinator.cpp +++ b/src/mongo/db/s/collmod_coordinator.cpp @@ -77,7 +77,7 @@ bool hasTimeSeriesGranularityUpdate(const CollModRequest& request) { CollModCoordinator::CollModCoordinator(ShardingDDLCoordinatorService* service, const BSONObj& initialState) - : RecoverableShardingDDLCoordinator(service, initialState), + : RecoverableShardingDDLCoordinator(service, "CollModCoordinator", initialState), _request{_doc.getCollModRequest()} {} void CollModCoordinator::checkIfOptionsConflict(const BSONObj& doc) const { @@ -93,31 +93,9 @@ void CollModCoordinator::checkIfOptionsConflict(const BSONObj& doc) const { SimpleBSONObjComparator::kInstance.evaluate(selfReq == otherReq)); } -boost::optional<BSONObj> CollModCoordinator::reportForCurrentOp( - MongoProcessInterface::CurrentOpConnectionsMode connMode, - MongoProcessInterface::CurrentOpSessionsMode sessionMode) noexcept { - - BSONObjBuilder cmdBob; - if (const auto& optComment = getForwardableOpMetadata().getComment()) { - cmdBob.append(optComment.get().firstElement()); - } - - const auto currPhase = [&]() { - stdx::lock_guard l{_docMutex}; - return _doc.getPhase(); - }(); - - cmdBob.appendElements(_request.toBSON()); - BSONObjBuilder bob; - bob.append("type", "op"); - bob.append("desc", "CollModCoordinator"); - bob.append("op", "command"); - bob.append("ns", nss().toString()); - bob.append("command", cmdBob.obj()); - bob.append("currentPhase", currPhase); - bob.append("active", true); - return bob.obj(); -} +void CollModCoordinator::appendCommandInfo(BSONObjBuilder* cmdInfoBuilder) const { + cmdInfoBuilder->appendElements(_request.toBSON()); +}; void CollModCoordinator::_performNoopRetryableWriteOnParticipants( OperationContext* opCtx, const std::shared_ptr<executor::TaskExecutor>& executor) { diff --git a/src/mongo/db/s/collmod_coordinator.h b/src/mongo/db/s/collmod_coordinator.h index 8c51b62e8ce..4b65502f78d 100644 --- a/src/mongo/db/s/collmod_coordinator.h +++ b/src/mongo/db/s/collmod_coordinator.h @@ -46,9 +46,7 @@ public: void checkIfOptionsConflict(const BSONObj& doc) const override; - boost::optional<BSONObj> reportForCurrentOp( - MongoProcessInterface::CurrentOpConnectionsMode connMode, - MongoProcessInterface::CurrentOpSessionsMode sessionMode) noexcept override; + void appendCommandInfo(BSONObjBuilder* cmdInfoBuilder) const override; /** * Waits for the termination of the parent DDLCoordinator (so all the resources are liberated) diff --git a/src/mongo/db/s/compact_structured_encryption_data_coordinator.cpp b/src/mongo/db/s/compact_structured_encryption_data_coordinator.cpp index fca007b684c..69c67d89dcb 100644 --- a/src/mongo/db/s/compact_structured_encryption_data_coordinator.cpp +++ b/src/mongo/db/s/compact_structured_encryption_data_coordinator.cpp @@ -187,43 +187,16 @@ void doDropOperation(const CompactStructuredEncryptionDataState& state) { boost::optional<BSONObj> CompactStructuredEncryptionDataCoordinator::reportForCurrentOp( MongoProcessInterface::CurrentOpConnectionsMode connMode, MongoProcessInterface::CurrentOpSessionsMode sessionMode) noexcept { - BSONObjBuilder bob; - - CompactStructuredEncryptionDataPhaseEnum currPhase; - std::string nss; - std::string escNss; - std::string eccNss; - std::string ecoNss; - std::string ecocNss; - std::string ecocRenameUuid; - std::string ecocUiid; - std::string ecocRenameNss; - { - stdx::lock_guard l{_docMutex}; - currPhase = _doc.getPhase(); - nss = _doc.getId().getNss().ns(); - escNss = _doc.getEscNss().ns(); - eccNss = _doc.getEccNss().ns(); - ecoNss = _doc.getEcocNss().ns(); - ecocNss = _doc.getEcocNss().ns(); - ecocRenameUuid = - _doc.getEcocRenameUuid() ? _doc.getEcocRenameUuid().value().toString() : "none"; - ecocUiid = _doc.getEcocUuid() ? _doc.getEcocUuid().value().toString() : "none"; - ecocRenameNss = _doc.getEcocRenameNss().ns(); - } - - bob.append("type", "op"); - bob.append("desc", "CompactStructuredEncryptionDataCoordinator"); - bob.append("op", "command"); - bob.append("nss", nss); - bob.append("escNss", escNss); - bob.append("eccNss", eccNss); - bob.append("ecocNss", ecocNss); - bob.append("ecocUuid", ecocUiid); - bob.append("ecocRenameNss", ecocRenameNss); - bob.append("ecocRenameUuid", ecocRenameUuid); - bob.append("currentPhase", currPhase); - bob.append("active", true); + auto bob = basicReportBuilder(); + + stdx::lock_guard lg{_docMutex}; + bob.append("escNss", _doc.getEscNss().ns()); + bob.append("eccNss", _doc.getEccNss().ns()); + bob.append("ecocNss", _doc.getEcocNss().ns()); + bob.append("ecocUuid", _doc.getEcocUuid() ? _doc.getEcocUuid().value().toString() : "none"); + bob.append("ecocRenameNss", _doc.getEcocRenameNss().ns()); + bob.append("ecocRenameUuid", + _doc.getEcocRenameUuid() ? _doc.getEcocRenameUuid().value().toString() : "none"); return bob.obj(); } diff --git a/src/mongo/db/s/compact_structured_encryption_data_coordinator.h b/src/mongo/db/s/compact_structured_encryption_data_coordinator.h index b441ae3c156..b030e19910a 100644 --- a/src/mongo/db/s/compact_structured_encryption_data_coordinator.h +++ b/src/mongo/db/s/compact_structured_encryption_data_coordinator.h @@ -50,7 +50,8 @@ public: CompactStructuredEncryptionDataCoordinator(ShardingDDLCoordinatorService* service, const BSONObj& doc) - : RecoverableShardingDDLCoordinator(service, doc) {} + : RecoverableShardingDDLCoordinator( + service, "CompactStructuredEncryptionDataCoordinator", doc) {} boost::optional<BSONObj> reportForCurrentOp( MongoProcessInterface::CurrentOpConnectionsMode connMode, diff --git a/src/mongo/db/s/create_collection_coordinator.cpp b/src/mongo/db/s/create_collection_coordinator.cpp index 1f0ac4ece12..ccbad667d35 100644 --- a/src/mongo/db/s/create_collection_coordinator.cpp +++ b/src/mongo/db/s/create_collection_coordinator.cpp @@ -359,29 +359,8 @@ void broadcastDropCollection(OperationContext* opCtx, } // namespace -boost::optional<BSONObj> CreateCollectionCoordinator::reportForCurrentOp( - MongoProcessInterface::CurrentOpConnectionsMode connMode, - MongoProcessInterface::CurrentOpSessionsMode sessionMode) noexcept { - BSONObjBuilder cmdBob; - if (const auto& optComment = getForwardableOpMetadata().getComment()) { - cmdBob.append(optComment.get().firstElement()); - } - cmdBob.appendElements(_request.toBSON()); - - const auto currPhase = [&]() { - stdx::lock_guard l{_docMutex}; - return _doc.getPhase(); - }(); - - BSONObjBuilder bob; - bob.append("type", "op"); - bob.append("desc", "CreateCollectionCoordinator"); - bob.append("op", "command"); - bob.append("ns", nss().toString()); - bob.append("command", cmdBob.obj()); - bob.append("currentPhase", currPhase); - bob.append("active", true); - return bob.obj(); +void CreateCollectionCoordinator::appendCommandInfo(BSONObjBuilder* cmdInfoBuilder) const { + cmdInfoBuilder->appendElements(_request.toBSON()); } void CreateCollectionCoordinator::checkIfOptionsConflict(const BSONObj& doc) const { diff --git a/src/mongo/db/s/create_collection_coordinator.h b/src/mongo/db/s/create_collection_coordinator.h index a6e7d0b9709..a1f8bbea4e8 100644 --- a/src/mongo/db/s/create_collection_coordinator.h +++ b/src/mongo/db/s/create_collection_coordinator.h @@ -47,7 +47,7 @@ public: using Phase = CreateCollectionCoordinatorPhaseEnum; CreateCollectionCoordinator(ShardingDDLCoordinatorService* service, const BSONObj& initialState) - : RecoverableShardingDDLCoordinator(service, initialState), + : RecoverableShardingDDLCoordinator(service, "CreateCollectionCoordinator", initialState), _request(_doc.getCreateCollectionRequest()), _critSecReason(BSON("command" << "createCollection" @@ -58,9 +58,7 @@ public: void checkIfOptionsConflict(const BSONObj& coorDoc) const override; - boost::optional<BSONObj> reportForCurrentOp( - MongoProcessInterface::CurrentOpConnectionsMode connMode, - MongoProcessInterface::CurrentOpSessionsMode sessionMode) noexcept override; + void appendCommandInfo(BSONObjBuilder* cmdInfoBuilder) const override; /** * Waits for the termination of the parent DDLCoordinator (so all the resources are liberated) diff --git a/src/mongo/db/s/drop_collection_coordinator.cpp b/src/mongo/db/s/drop_collection_coordinator.cpp index 720ac168b5b..fa1e2f4b84e 100644 --- a/src/mongo/db/s/drop_collection_coordinator.cpp +++ b/src/mongo/db/s/drop_collection_coordinator.cpp @@ -47,31 +47,6 @@ namespace mongo { -boost::optional<BSONObj> DropCollectionCoordinator::reportForCurrentOp( - MongoProcessInterface::CurrentOpConnectionsMode connMode, - MongoProcessInterface::CurrentOpSessionsMode sessionMode) noexcept { - - BSONObjBuilder cmdBob; - if (const auto& optComment = getForwardableOpMetadata().getComment()) { - cmdBob.append(optComment.get().firstElement()); - } - - const auto currPhase = [&]() { - stdx::lock_guard l{_docMutex}; - return _doc.getPhase(); - }(); - - BSONObjBuilder bob; - bob.append("type", "op"); - bob.append("desc", "DropCollectionCoordinator"); - bob.append("op", "command"); - bob.append("ns", nss().toString()); - bob.append("command", cmdBob.obj()); - bob.append("currentPhase", currPhase); - bob.append("active", true); - return bob.obj(); -} - DropReply DropCollectionCoordinator::dropCollectionLocally(OperationContext* opCtx, const NamespaceString& nss) { { diff --git a/src/mongo/db/s/drop_collection_coordinator.h b/src/mongo/db/s/drop_collection_coordinator.h index 93435c0dcf1..46b37d2a415 100644 --- a/src/mongo/db/s/drop_collection_coordinator.h +++ b/src/mongo/db/s/drop_collection_coordinator.h @@ -43,16 +43,12 @@ public: using Phase = DropCollectionCoordinatorPhaseEnum; DropCollectionCoordinator(ShardingDDLCoordinatorService* service, const BSONObj& initialState) - : RecoverableShardingDDLCoordinator(service, initialState) {} + : RecoverableShardingDDLCoordinator(service, "DropCollectionCoordinator", initialState) {} ~DropCollectionCoordinator() = default; void checkIfOptionsConflict(const BSONObj& doc) const override {} - boost::optional<BSONObj> reportForCurrentOp( - MongoProcessInterface::CurrentOpConnectionsMode connMode, - MongoProcessInterface::CurrentOpSessionsMode sessionMode) noexcept override; - /** * Locally drops a collection, cleans its CollectionShardingRuntime metadata and refreshes the * catalog cache. diff --git a/src/mongo/db/s/drop_database_coordinator.cpp b/src/mongo/db/s/drop_database_coordinator.cpp index 84d64665831..54b8ef1108e 100644 --- a/src/mongo/db/s/drop_database_coordinator.cpp +++ b/src/mongo/db/s/drop_database_coordinator.cpp @@ -144,30 +144,6 @@ void DropDatabaseCoordinator::_dropShardedCollection( opCtx, nss, {primaryShardId}, **executor, getCurrentSession()); } -boost::optional<BSONObj> DropDatabaseCoordinator::reportForCurrentOp( - MongoProcessInterface::CurrentOpConnectionsMode connMode, - MongoProcessInterface::CurrentOpSessionsMode sessionMode) noexcept { - BSONObjBuilder cmdBob; - if (const auto& optComment = getForwardableOpMetadata().getComment()) { - cmdBob.append(optComment.get().firstElement()); - } - - const auto currPhase = [&]() { - stdx::lock_guard l{_docMutex}; - return _doc.getPhase(); - }(); - - BSONObjBuilder bob; - bob.append("type", "op"); - bob.append("desc", "DropDatabaseCoordinator"); - bob.append("op", "command"); - bob.append("ns", nss().toString()); - bob.append("command", cmdBob.obj()); - bob.append("currentPhase", currPhase); - bob.append("active", true); - return bob.obj(); -} - void DropDatabaseCoordinator::_clearDatabaseInfoOnPrimary(OperationContext* opCtx) { Lock::DBLock dbLock(opCtx, _dbName, MODE_X); auto dss = DatabaseShardingState::get(opCtx, _dbName); diff --git a/src/mongo/db/s/drop_database_coordinator.h b/src/mongo/db/s/drop_database_coordinator.h index 62b3a418b8d..f70ea2981cb 100644 --- a/src/mongo/db/s/drop_database_coordinator.h +++ b/src/mongo/db/s/drop_database_coordinator.h @@ -43,15 +43,12 @@ public: using Phase = DropDatabaseCoordinatorPhaseEnum; DropDatabaseCoordinator(ShardingDDLCoordinatorService* service, const BSONObj& initialState) - : RecoverableShardingDDLCoordinator(service, initialState), _dbName(nss().db()) {} + : RecoverableShardingDDLCoordinator(service, "DropDatabaseCoordinator", initialState), + _dbName(nss().db()) {} ~DropDatabaseCoordinator() = default; void checkIfOptionsConflict(const BSONObj& doc) const override {} - boost::optional<BSONObj> reportForCurrentOp( - MongoProcessInterface::CurrentOpConnectionsMode connMode, - MongoProcessInterface::CurrentOpSessionsMode sessionMode) noexcept override; - private: StringData serializePhase(const Phase& phase) const override { return DropDatabaseCoordinatorPhase_serializer(phase); diff --git a/src/mongo/db/s/move_primary_coordinator.cpp b/src/mongo/db/s/move_primary_coordinator.cpp index 32d7a6af9bf..863a4c17b9d 100644 --- a/src/mongo/db/s/move_primary_coordinator.cpp +++ b/src/mongo/db/s/move_primary_coordinator.cpp @@ -46,24 +46,10 @@ namespace mongo { -boost::optional<BSONObj> MovePrimaryCoordinator::reportForCurrentOp( - MongoProcessInterface::CurrentOpConnectionsMode connMode, - MongoProcessInterface::CurrentOpSessionsMode sessionMode) noexcept { - BSONObjBuilder cmdBob; - if (const auto& optComment = getForwardableOpMetadata().getComment()) { - cmdBob.append(optComment.get().firstElement()); - } - cmdBob.append("request", BSON(_doc.kToShardIdFieldName << _doc.getToShardId())); - - BSONObjBuilder bob; - bob.append("type", "op"); - bob.append("desc", "MovePrimaryCoordinator"); - bob.append("op", "command"); - bob.append("ns", nss().toString()); - bob.append("command", cmdBob.obj()); - bob.append("active", true); - return bob.obj(); -} +void MovePrimaryCoordinator::appendCommandInfo(BSONObjBuilder* cmdInfoBuilder) const { + stdx::lock_guard lk{_docMutex}; + cmdInfoBuilder->append("request", BSON(_doc.kToShardIdFieldName << _doc.getToShardId())); +}; void MovePrimaryCoordinator::checkIfOptionsConflict(const BSONObj& doc) const { // If we have two shard collections on the same namespace, then the arguments must be the same. diff --git a/src/mongo/db/s/move_primary_coordinator.h b/src/mongo/db/s/move_primary_coordinator.h index c8d01060a4a..80a1586e0a4 100644 --- a/src/mongo/db/s/move_primary_coordinator.h +++ b/src/mongo/db/s/move_primary_coordinator.h @@ -39,15 +39,13 @@ class MovePrimaryCoordinator final : public ShardingDDLCoordinatorImpl<MovePrimaryCoordinatorDocument> { public: MovePrimaryCoordinator(ShardingDDLCoordinatorService* service, const BSONObj& initialState) - : ShardingDDLCoordinatorImpl(service, initialState) {} + : ShardingDDLCoordinatorImpl(service, "MovePrimaryCoordinator", initialState) {} ~MovePrimaryCoordinator() = default; void checkIfOptionsConflict(const BSONObj& coorDoc) const override; - boost::optional<BSONObj> reportForCurrentOp( - MongoProcessInterface::CurrentOpConnectionsMode connMode, - MongoProcessInterface::CurrentOpSessionsMode sessionMode) noexcept override; + void appendCommandInfo(BSONObjBuilder* cmdInfoBuilder) const override; bool canAlwaysStartWhenUserWritesAreDisabled() const override { return true; diff --git a/src/mongo/db/s/refine_collection_shard_key_coordinator.cpp b/src/mongo/db/s/refine_collection_shard_key_coordinator.cpp index a4786584ab2..b8d981bb4ce 100644 --- a/src/mongo/db/s/refine_collection_shard_key_coordinator.cpp +++ b/src/mongo/db/s/refine_collection_shard_key_coordinator.cpp @@ -86,7 +86,8 @@ void notifyChangeStreamsOnRefineCollectionShardKeyComplete(OperationContext* opC RefineCollectionShardKeyCoordinator::RefineCollectionShardKeyCoordinator( ShardingDDLCoordinatorService* service, const BSONObj& initialState) - : RecoverableShardingDDLCoordinator(service, initialState), + : RecoverableShardingDDLCoordinator( + service, "RefineCollectionShardKeyCoordinator", initialState), _request(_doc.getRefineCollectionShardKeyRequest()), _newShardKey(_doc.getNewShardKey()) {} @@ -102,23 +103,8 @@ void RefineCollectionShardKeyCoordinator::checkIfOptionsConflict(const BSONObj& _request.toBSON() == otherDoc.getRefineCollectionShardKeyRequest().toBSON())); } -boost::optional<BSONObj> RefineCollectionShardKeyCoordinator::reportForCurrentOp( - MongoProcessInterface::CurrentOpConnectionsMode connMode, - MongoProcessInterface::CurrentOpSessionsMode sessionMode) noexcept { - BSONObjBuilder cmdBob; - if (const auto& optComment = getForwardableOpMetadata().getComment()) { - cmdBob.append(optComment.get().firstElement()); - } - cmdBob.appendElements(_request.toBSON()); - - BSONObjBuilder bob; - bob.append("type", "op"); - bob.append("desc", "RefineCollectionShardKeyCoordinator"); - bob.append("op", "command"); - bob.append("ns", nss().toString()); - bob.append("command", cmdBob.obj()); - bob.append("active", true); - return bob.obj(); +void RefineCollectionShardKeyCoordinator::appendCommandInfo(BSONObjBuilder* cmdInfoBuilder) const { + cmdInfoBuilder->appendElements(_request.toBSON()); } ExecutorFuture<void> RefineCollectionShardKeyCoordinator::_runImpl( diff --git a/src/mongo/db/s/refine_collection_shard_key_coordinator.h b/src/mongo/db/s/refine_collection_shard_key_coordinator.h index 21a1a46d5fe..c461383e876 100644 --- a/src/mongo/db/s/refine_collection_shard_key_coordinator.h +++ b/src/mongo/db/s/refine_collection_shard_key_coordinator.h @@ -47,9 +47,7 @@ public: void checkIfOptionsConflict(const BSONObj& coorDoc) const override; - boost::optional<BSONObj> reportForCurrentOp( - MongoProcessInterface::CurrentOpConnectionsMode connMode, - MongoProcessInterface::CurrentOpSessionsMode sessionMode) noexcept override; + void appendCommandInfo(BSONObjBuilder* cmdInfoBuilder) const override; private: StringData serializePhase(const Phase& phase) const override { diff --git a/src/mongo/db/s/rename_collection_coordinator.cpp b/src/mongo/db/s/rename_collection_coordinator.cpp index 8032fbd1922..64680e96cc2 100644 --- a/src/mongo/db/s/rename_collection_coordinator.cpp +++ b/src/mongo/db/s/rename_collection_coordinator.cpp @@ -90,7 +90,7 @@ boost::optional<UUID> getCollectionUUID(OperationContext* opCtx, RenameCollectionCoordinator::RenameCollectionCoordinator(ShardingDDLCoordinatorService* service, const BSONObj& initialState) - : RecoverableShardingDDLCoordinator(service, initialState), + : RecoverableShardingDDLCoordinator(service, "RenameCollectionCoordinator", initialState), _request(_doc.getRenameCollectionRequest()) {} void RenameCollectionCoordinator::checkIfOptionsConflict(const BSONObj& doc) const { @@ -111,30 +111,8 @@ std::vector<StringData> RenameCollectionCoordinator::_acquireAdditionalLocks( return {_request.getTo().ns()}; } -boost::optional<BSONObj> RenameCollectionCoordinator::reportForCurrentOp( - MongoProcessInterface::CurrentOpConnectionsMode connMode, - MongoProcessInterface::CurrentOpSessionsMode sessionMode) noexcept { - - BSONObjBuilder cmdBob; - if (const auto& optComment = getForwardableOpMetadata().getComment()) { - cmdBob.append(optComment.get().firstElement()); - } - cmdBob.appendElements(_request.toBSON()); - - const auto currPhase = [&]() { - stdx::lock_guard l{_docMutex}; - return _doc.getPhase(); - }(); - - BSONObjBuilder bob; - bob.append("type", "op"); - bob.append("desc", "RenameCollectionCoordinator"); - bob.append("op", "command"); - bob.append("ns", nss().toString()); - bob.append("command", cmdBob.obj()); - bob.append("currentPhase", currPhase); - bob.append("active", true); - return bob.obj(); +void RenameCollectionCoordinator::appendCommandInfo(BSONObjBuilder* cmdInfoBuilder) const { + cmdInfoBuilder->appendElements(_request.toBSON()); } ExecutorFuture<void> RenameCollectionCoordinator::_runImpl( diff --git a/src/mongo/db/s/rename_collection_coordinator.h b/src/mongo/db/s/rename_collection_coordinator.h index 502bd0cead7..32621bb6ea4 100644 --- a/src/mongo/db/s/rename_collection_coordinator.h +++ b/src/mongo/db/s/rename_collection_coordinator.h @@ -47,9 +47,7 @@ public: void checkIfOptionsConflict(const BSONObj& doc) const override; - boost::optional<BSONObj> reportForCurrentOp( - MongoProcessInterface::CurrentOpConnectionsMode connMode, - MongoProcessInterface::CurrentOpSessionsMode sessionMode) noexcept override; + void appendCommandInfo(BSONObjBuilder* cmdInfoBuilder) const override; /** * Waits for the rename to complete and returns the collection version. diff --git a/src/mongo/db/s/reshard_collection_coordinator.cpp b/src/mongo/db/s/reshard_collection_coordinator.cpp index ee9f7115e93..c0c9648e0a4 100644 --- a/src/mongo/db/s/reshard_collection_coordinator.cpp +++ b/src/mongo/db/s/reshard_collection_coordinator.cpp @@ -107,7 +107,7 @@ ReshardCollectionCoordinator::ReshardCollectionCoordinator(ShardingDDLCoordinato ReshardCollectionCoordinator::ReshardCollectionCoordinator(ShardingDDLCoordinatorService* service, const BSONObj& initialState, bool persistCoordinatorDocument) - : RecoverableShardingDDLCoordinator(service, initialState), + : RecoverableShardingDDLCoordinator(service, "ReshardCollectionCoordinator", initialState), _request(_doc.getReshardCollectionRequest()), _persistCoordinatorDocument(persistCoordinatorDocument) {} @@ -122,23 +122,8 @@ void ReshardCollectionCoordinator::checkIfOptionsConflict(const BSONObj& doc) co _request.toBSON() == otherDoc.getReshardCollectionRequest().toBSON())); } -boost::optional<BSONObj> ReshardCollectionCoordinator::reportForCurrentOp( - MongoProcessInterface::CurrentOpConnectionsMode connMode, - MongoProcessInterface::CurrentOpSessionsMode sessionMode) noexcept { - BSONObjBuilder cmdBob; - if (const auto& optComment = getForwardableOpMetadata().getComment()) { - cmdBob.append(optComment.get().firstElement()); - } - cmdBob.appendElements(_request.toBSON()); - - BSONObjBuilder bob; - bob.append("type", "op"); - bob.append("desc", "ReshardCollectionCoordinator"); - bob.append("op", "command"); - bob.append("ns", nss().toString()); - bob.append("command", cmdBob.obj()); - bob.append("active", true); - return bob.obj(); +void ReshardCollectionCoordinator::appendCommandInfo(BSONObjBuilder* cmdInfoBuilder) const { + cmdInfoBuilder->appendElements(_request.toBSON()); } void ReshardCollectionCoordinator::_enterPhase(Phase newPhase) { diff --git a/src/mongo/db/s/reshard_collection_coordinator.h b/src/mongo/db/s/reshard_collection_coordinator.h index a17edf9f2e8..085c183dc55 100644 --- a/src/mongo/db/s/reshard_collection_coordinator.h +++ b/src/mongo/db/s/reshard_collection_coordinator.h @@ -46,9 +46,7 @@ public: void checkIfOptionsConflict(const BSONObj& coorDoc) const override; - boost::optional<BSONObj> reportForCurrentOp( - MongoProcessInterface::CurrentOpConnectionsMode connMode, - MongoProcessInterface::CurrentOpSessionsMode sessionMode) noexcept override; + void appendCommandInfo(BSONObjBuilder* cmdInfoBuilder) const override; protected: ReshardCollectionCoordinator(ShardingDDLCoordinatorService* service, diff --git a/src/mongo/db/s/set_allow_migrations_coordinator.cpp b/src/mongo/db/s/set_allow_migrations_coordinator.cpp index 9362005a11f..d8cb15afb2e 100644 --- a/src/mongo/db/s/set_allow_migrations_coordinator.cpp +++ b/src/mongo/db/s/set_allow_migrations_coordinator.cpp @@ -64,23 +64,9 @@ void SetAllowMigrationsCoordinator::checkIfOptionsConflict(const BSONObj& doc) c otherDoc.getSetAllowMigrationsRequest().toBSON())); } -boost::optional<BSONObj> SetAllowMigrationsCoordinator::reportForCurrentOp( - MongoProcessInterface::CurrentOpConnectionsMode connMode, - MongoProcessInterface::CurrentOpSessionsMode sessionMode) noexcept { - BSONObjBuilder cmdBob; - if (const auto& optComment = getForwardableOpMetadata().getComment()) { - cmdBob.append(optComment.get().firstElement()); - } - cmdBob.appendElements(_doc.getSetAllowMigrationsRequest().toBSON()); - - BSONObjBuilder bob; - bob.append("type", "op"); - bob.append("desc", "SetAllowMigrationsCoordinator"); - bob.append("op", "command"); - bob.append("ns", nss().toString()); - bob.append("command", cmdBob.obj()); - bob.append("active", true); - return bob.obj(); +void SetAllowMigrationsCoordinator::appendCommandInfo(BSONObjBuilder* cmdInfoBuilder) const { + stdx::lock_guard lk{_docMutex}; + cmdInfoBuilder->appendElements(_doc.getSetAllowMigrationsRequest().toBSON()); } ExecutorFuture<void> SetAllowMigrationsCoordinator::_runImpl( diff --git a/src/mongo/db/s/set_allow_migrations_coordinator.h b/src/mongo/db/s/set_allow_migrations_coordinator.h index 9f7915f888b..78d2e03696a 100644 --- a/src/mongo/db/s/set_allow_migrations_coordinator.h +++ b/src/mongo/db/s/set_allow_migrations_coordinator.h @@ -44,14 +44,12 @@ class SetAllowMigrationsCoordinator final public: SetAllowMigrationsCoordinator(ShardingDDLCoordinatorService* service, const BSONObj& initialState) - : ShardingDDLCoordinatorImpl(service, initialState), + : ShardingDDLCoordinatorImpl(service, "SetAllowMigrationsCoordinator", initialState), _allowMigrations(_doc.getAllowMigrations()) {} void checkIfOptionsConflict(const BSONObj& coorDoc) const override; - boost::optional<BSONObj> reportForCurrentOp( - MongoProcessInterface::CurrentOpConnectionsMode connMode, - MongoProcessInterface::CurrentOpSessionsMode sessionMode) noexcept override; + void appendCommandInfo(BSONObjBuilder* cmdInfoBuilder) const override; bool canAlwaysStartWhenUserWritesAreDisabled() const override { return true; diff --git a/src/mongo/db/s/sharding_ddl_coordinator.h b/src/mongo/db/s/sharding_ddl_coordinator.h index 11be5152036..51dcc023f60 100644 --- a/src/mongo/db/s/sharding_ddl_coordinator.h +++ b/src/mongo/db/s/sharding_ddl_coordinator.h @@ -174,11 +174,19 @@ private: template <class StateDoc> class ShardingDDLCoordinatorImpl : public ShardingDDLCoordinator { +public: + boost::optional<BSONObj> reportForCurrentOp( + MongoProcessInterface::CurrentOpConnectionsMode connMode, + MongoProcessInterface::CurrentOpSessionsMode sessionMode) noexcept override { + return basicReportBuilder().obj(); + } protected: ShardingDDLCoordinatorImpl(ShardingDDLCoordinatorService* service, + const std::string& name, const BSONObj& initialStateDoc) : ShardingDDLCoordinator(service, initialStateDoc), + _coordinatorName(name), _initialState(initialStateDoc.getOwned()), _doc(StateDoc::parse(IDLParserErrorContext("CoordinatorDocument"), _initialState)) {} @@ -186,6 +194,34 @@ protected: return _doc.getShardingDDLCoordinatorMetadata(); } + + virtual void appendCommandInfo(BSONObjBuilder* cmdInfoBuilder) const {}; + + virtual BSONObjBuilder basicReportBuilder() const noexcept { + BSONObjBuilder bob; + + // Append static info + bob.append("type", "op"); + bob.append("ns", nss().toString()); + bob.append("desc", _coordinatorName); + bob.append("op", "command"); + bob.append("active", true); + + // Create command description + BSONObjBuilder cmdInfoBuilder; + { + stdx::lock_guard lk{_docMutex}; + if (const auto& optComment = getForwardableOpMetadata().getComment()) { + cmdInfoBuilder.append(optComment.get().firstElement()); + } + } + appendCommandInfo(&cmdInfoBuilder); + bob.append("command", cmdInfoBuilder.obj()); + + return bob; + } + + const std::string _coordinatorName; const BSONObj _initialState; mutable Mutex _docMutex = MONGO_MAKE_LATCH("ShardingDDLCoordinator::_docMutex"); StateDoc _doc; @@ -193,14 +229,14 @@ protected: template <class StateDoc, class Phase> class RecoverableShardingDDLCoordinator : public ShardingDDLCoordinatorImpl<StateDoc> { - protected: using ShardingDDLCoordinatorImpl<StateDoc>::_doc; using ShardingDDLCoordinatorImpl<StateDoc>::_docMutex; RecoverableShardingDDLCoordinator(ShardingDDLCoordinatorService* service, + const std::string& name, const BSONObj& initialStateDoc) - : ShardingDDLCoordinatorImpl<StateDoc>(service, initialStateDoc) {} + : ShardingDDLCoordinatorImpl<StateDoc>(service, name, initialStateDoc) {} virtual StringData serializePhase(const Phase& phase) const = 0; @@ -245,6 +281,18 @@ protected: } } + BSONObjBuilder basicReportBuilder() const noexcept override { + auto baseReportBuilder = ShardingDDLCoordinatorImpl<StateDoc>::basicReportBuilder(); + + const auto currPhase = [&]() { + stdx::lock_guard l{_docMutex}; + return _doc.getPhase(); + }(); + + baseReportBuilder.append("currentPhase", serializePhase(currPhase)); + return baseReportBuilder; + } + void _insertStateDocument(OperationContext* opCtx, StateDoc&& newDoc) { auto copyMetadata = newDoc.getShardingDDLCoordinatorMetadata(); copyMetadata.setRecoveredFromDisk(true); |