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/mongo/s/commands | |
parent | ac55d9ad9fcf1a7d55e811ad351540f700a5bcc2 (diff) | |
download | mongo-0ab12830d07bc60523d4a21eb216ba4ab70a2be2.tar.gz |
SERVER-47018 Attach topology version to shutdown errors while in quiesce mode
Diffstat (limited to 'src/mongo/s/commands')
-rw-r--r-- | src/mongo/s/commands/strategy.cpp | 24 |
1 files changed, 24 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()); } |