diff options
author | Mathias Stearn <mathias@10gen.com> | 2017-05-19 15:35:02 -0400 |
---|---|---|
committer | Mathias Stearn <mathias@10gen.com> | 2017-06-07 13:28:58 -0400 |
commit | 8a1fa422145b2c6bf517497fd88a20fff935c218 (patch) | |
tree | 03e1cbbbdbba8cb2bc6447e9a049b096ca0ed85b | |
parent | f22a377c53b445281635b569a93eec04aa8d3bb3 (diff) | |
download | mongo-8a1fa422145b2c6bf517497fd88a20fff935c218.tar.gz |
SERVER-29319 Move mongos runCommand higher in file to eliminate forward declaration
-rw-r--r-- | src/mongo/s/commands/strategy.cpp | 104 |
1 files changed, 48 insertions, 56 deletions
diff --git a/src/mongo/s/commands/strategy.cpp b/src/mongo/s/commands/strategy.cpp index 1748d6380f0..5dc3edc8ab2 100644 --- a/src/mongo/s/commands/strategy.cpp +++ b/src/mongo/s/commands/strategy.cpp @@ -295,6 +295,54 @@ void runAgainstRegistered(OperationContext* opCtx, execCommandClient(opCtx, c, db, jsobj, anObjBuilder); } + +void runCommand(OperationContext* opCtx, StringData db, BSONObj cmdObj, BSONObjBuilder&& builder) { + // Handle command option maxTimeMS. + uassert(ErrorCodes::InvalidOptions, + "no such command option $maxTimeMs; use maxTimeMS instead", + cmdObj[QueryRequest::queryOptionMaxTimeMS].eoo()); + + const int maxTimeMS = + uassertStatusOK(QueryRequest::parseMaxTimeMS(cmdObj[QueryRequest::cmdOptionMaxTimeMS])); + if (maxTimeMS > 0) { + opCtx->setDeadlineAfterNowBy(Milliseconds{maxTimeMS}); + } + + int loops = 5; + + while (true) { + builder.resetToEmpty(); + try { + runAgainstRegistered(opCtx, db, cmdObj, builder); + return; + } catch (const StaleConfigException& e) { + if (loops <= 0) + throw e; + + loops--; + + log() << "Retrying command " << redact(cmdObj) << causedBy(e); + + // For legacy reasons, ns may not actually be set in the exception + const std::string staleNS(e.getns().empty() ? NamespaceString(db).getCommandNS().ns() + : e.getns()); + + ShardConnection::checkMyConnectionVersions(opCtx, staleNS); + if (loops < 4) { + const NamespaceString staleNSS(staleNS); + if (staleNSS.isValid()) { + Grid::get(opCtx)->catalogCache()->invalidateShardedCollection(staleNSS); + } + } + continue; + } catch (const DBException& e) { + builder.resetToEmpty(); + Command::appendCommandStatus(builder, e.toStatus()); + return; + } + MONGO_UNREACHABLE; + } +} } // namespace DbResponse Strategy::queryOp(OperationContext* opCtx, const NamespaceString& nss, DbMessage* dbm) { @@ -381,11 +429,6 @@ DbResponse Strategy::queryOp(OperationContext* opCtx, const NamespaceString& nss cursorId.getValue())}; } -static void runCommand(OperationContext* opCtx, - StringData db, - BSONObj cmdObj, - BSONObjBuilder&& builder); - DbResponse Strategy::clientOpQueryCommand(OperationContext* opCtx, NamespaceString nss, DbMessage* dbm) { @@ -468,57 +511,6 @@ DbResponse Strategy::clientOpQueryCommand(OperationContext* opCtx, return DbResponse{reply.toCommandReply()}; } -static void runCommand(OperationContext* opCtx, - StringData db, - BSONObj cmdObj, - BSONObjBuilder&& builder) { - // Handle command option maxTimeMS. - uassert(ErrorCodes::InvalidOptions, - "no such command option $maxTimeMs; use maxTimeMS instead", - cmdObj[QueryRequest::queryOptionMaxTimeMS].eoo()); - - const int maxTimeMS = - uassertStatusOK(QueryRequest::parseMaxTimeMS(cmdObj[QueryRequest::cmdOptionMaxTimeMS])); - if (maxTimeMS > 0) { - opCtx->setDeadlineAfterNowBy(Milliseconds{maxTimeMS}); - } - - int loops = 5; - - while (true) { - builder.resetToEmpty(); - try { - runAgainstRegistered(opCtx, db, cmdObj, builder); - return; - } catch (const StaleConfigException& e) { - if (loops <= 0) - throw e; - - loops--; - - log() << "Retrying command " << redact(cmdObj) << causedBy(e); - - // For legacy reasons, ns may not actually be set in the exception - const std::string staleNS(e.getns().empty() ? NamespaceString(db).getCommandNS().ns() - : e.getns()); - - ShardConnection::checkMyConnectionVersions(opCtx, staleNS); - if (loops < 4) { - const NamespaceString staleNSS(staleNS); - if (staleNSS.isValid()) { - Grid::get(opCtx)->catalogCache()->invalidateShardedCollection(staleNSS); - } - } - continue; - } catch (const DBException& e) { - builder.resetToEmpty(); - Command::appendCommandStatus(builder, e.toStatus()); - return; - } - MONGO_UNREACHABLE; - } -} - DbResponse Strategy::clientOpMsgCommand(OperationContext* opCtx, const Message& m) { auto request = OpMsg::parse(m); OpMsgBuilder reply; |