diff options
author | Pavi Vetriselvan <pvselvan@umich.edu> | 2020-05-14 09:07:42 -0400 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-05-21 04:49:46 +0000 |
commit | 0ab12830d07bc60523d4a21eb216ba4ab70a2be2 (patch) | |
tree | 6859137c7648be803bef85ffe319d2b399b643af /src | |
parent | ac55d9ad9fcf1a7d55e811ad351540f700a5bcc2 (diff) | |
download | mongo-0ab12830d07bc60523d4a21eb216ba4ab70a2be2.tar.gz |
SERVER-47018 Attach topology version to shutdown errors while in quiesce mode
Diffstat (limited to 'src')
-rw-r--r-- | src/mongo/s/commands/strategy.cpp | 24 | ||||
-rw-r--r-- | src/mongo/s/mongos_topology_coordinator.h | 6 | ||||
-rw-r--r-- | src/mongo/s/server.cpp | 7 |
3 files changed, 37 insertions, 0 deletions
diff --git a/src/mongo/s/commands/strategy.cpp b/src/mongo/s/commands/strategy.cpp index 2334232a604..23b21731fa6 100644 --- a/src/mongo/s/commands/strategy.cpp +++ b/src/mongo/s/commands/strategy.cpp @@ -77,6 +77,7 @@ #include "mongo/s/cluster_commands_helpers.h" #include "mongo/s/commands/cluster_explain.h" #include "mongo/s/grid.h" +#include "mongo/s/mongos_topology_coordinator.h" #include "mongo/s/query/cluster_cursor_manager.h" #include "mongo/s/query/cluster_find.h" #include "mongo/s/session_catalog_router.h" @@ -891,6 +892,26 @@ void runCommand(OperationContext* opCtx, } } +/** + * Attaches the topology version to the response. + */ +void attachTopologyVersionDuringShutdown(OperationContext* opCtx, + const DBException& ex, + BSONObjBuilder* errorBuilder) { + // Only attach the topology version if the mongos is in quiesce mode. If the mongos is in + // quiesce mode, this shutdown error is due to mongos rather than a shard. + auto code = ex.code(); + if (code && ErrorCodes::isA<ErrorCategory::ShutdownError>(code)) { + if (auto mongosTopCoord = MongosTopologyCoordinator::get(opCtx); + mongosTopCoord && mongosTopCoord->inQuiesceMode()) { + // Append the topology version to the response. + const auto topologyVersion = mongosTopCoord->getTopologyVersion(); + BSONObjBuilder topologyVersionBuilder(errorBuilder->subobjStart("topologyVersion")); + topologyVersion.serialize(&topologyVersionBuilder); + } + } +} + } // namespace DbResponse Strategy::queryOp(OperationContext* opCtx, const NamespaceString& nss, DbMessage* dbm) { @@ -1078,10 +1099,13 @@ DbResponse Strategy::clientCommand(OperationContext* opCtx, const Message& m) { if (propagateException) { throw; } + reply->reset(); auto bob = reply->getBodyBuilder(); CommandHelpers::appendCommandStatusNoThrow(bob, ex.toStatus()); appendRequiredFieldsToResponse(opCtx, &bob); + + attachTopologyVersionDuringShutdown(opCtx, ex, &errorBuilder); bob.appendElements(errorBuilder.obj()); } diff --git a/src/mongo/s/mongos_topology_coordinator.h b/src/mongo/s/mongos_topology_coordinator.h index eccf83c8a31..6d9ddc0f286 100644 --- a/src/mongo/s/mongos_topology_coordinator.h +++ b/src/mongo/s/mongos_topology_coordinator.h @@ -81,6 +81,12 @@ public: return _topologyVersion; } + bool inQuiesceMode() const { + stdx::lock_guard lk(_mutex); + return _inQuiesceMode; + } + + private: using SharedPromiseOfMongosIsMasterResponse = SharedPromise<std::shared_ptr<const MongosIsMasterResponse>>; diff --git a/src/mongo/s/server.cpp b/src/mongo/s/server.cpp index 05d228e5ba3..cf86f70a63d 100644 --- a/src/mongo/s/server.cpp +++ b/src/mongo/s/server.cpp @@ -138,6 +138,8 @@ MONGO_FAIL_POINT_DEFINE(failReplicaSetChangeConfigServerUpdateHook); namespace { +MONGO_FAIL_POINT_DEFINE(pauseWhileKillingOperationsAtShutdown); + #if defined(_WIN32) const ntservice::NtServiceDefaultStrings defaultServiceStrings = { L"MongoS", L"MongoDB Router", L"MongoDB Sharding Router"}; @@ -315,6 +317,11 @@ void cleanupTask(const ShutdownTaskArgs& shutdownArgs) { if (serviceContext) { serviceContext->setKillAllOperations(); + + if (MONGO_unlikely(pauseWhileKillingOperationsAtShutdown.shouldFail())) { + LOGV2(4701800, "pauseWhileKillingOperationsAtShutdown failpoint enabled"); + sleepsecs(1); + } } // Perform all shutdown operations after setKillAllOperations is called in order to ensure |