diff options
Diffstat (limited to 'src/mongo')
-rw-r--r-- | src/mongo/s/client/shard.cpp | 3 | ||||
-rw-r--r-- | src/mongo/s/client/shard.h | 4 | ||||
-rw-r--r-- | src/mongo/s/client/shard_local.cpp | 7 | ||||
-rw-r--r-- | src/mongo/s/client/shard_local.h | 3 | ||||
-rw-r--r-- | src/mongo/s/client/shard_local_test.cpp | 1 | ||||
-rw-r--r-- | src/mongo/s/client/shard_registry.cpp | 41 | ||||
-rw-r--r-- | src/mongo/s/client/shard_registry.h | 1 | ||||
-rw-r--r-- | src/mongo/s/client/shard_remote.cpp | 26 | ||||
-rw-r--r-- | src/mongo/s/client/shard_remote.h | 12 |
9 files changed, 45 insertions, 53 deletions
diff --git a/src/mongo/s/client/shard.cpp b/src/mongo/s/client/shard.cpp index 19c49fa7dd6..036405581ca 100644 --- a/src/mongo/s/client/shard.cpp +++ b/src/mongo/s/client/shard.cpp @@ -75,10 +75,9 @@ StatusWith<Shard::CommandResponse> Shard::runCommand(OperationContext* txn, const ReadPreferenceSetting& readPref, const std::string& dbName, const BSONObj& cmdObj, - const BSONObj& metadata, RetryPolicy retryPolicy) { for (int retry = 1; retry <= kOnErrorNumRetries; ++retry) { - auto swCmdResponse = _runCommand(txn, readPref, dbName, cmdObj, metadata); + auto swCmdResponse = _runCommand(txn, readPref, dbName, cmdObj); auto commandStatus = _getEffectiveCommandStatus(swCmdResponse); if (retry < kOnErrorNumRetries && _isRetriableError(commandStatus.code(), retryPolicy)) { diff --git a/src/mongo/s/client/shard.h b/src/mongo/s/client/shard.h index 92b183d5ad7..9624ff8555a 100644 --- a/src/mongo/s/client/shard.h +++ b/src/mongo/s/client/shard.h @@ -127,7 +127,6 @@ public: const ReadPreferenceSetting& readPref, const std::string& dbName, const BSONObj& cmdObj, - const BSONObj& metadata, RetryPolicy retryPolicy); /** @@ -157,8 +156,7 @@ private: virtual StatusWith<CommandResponse> _runCommand(OperationContext* txn, const ReadPreferenceSetting& readPref, const std::string& dbname, - const BSONObj& cmdObj, - const BSONObj& metadata) = 0; + const BSONObj& cmdObj) = 0; virtual StatusWith<QueryResponse> _exhaustiveFindOnConfig(OperationContext* txn, const ReadPreferenceSetting& readPref, diff --git a/src/mongo/s/client/shard_local.cpp b/src/mongo/s/client/shard_local.cpp index 3ed9d31cc8f..b4ec88e636a 100644 --- a/src/mongo/s/client/shard_local.cpp +++ b/src/mongo/s/client/shard_local.cpp @@ -87,12 +87,11 @@ bool ShardLocal::_isRetriableError(ErrorCodes::Error code, RetryPolicy options) StatusWith<Shard::CommandResponse> ShardLocal::_runCommand(OperationContext* txn, const ReadPreferenceSetting& unused, const std::string& dbName, - const BSONObj& cmdObj, - const BSONObj& metadata) { + const BSONObj& cmdObj) { try { DBDirectClient client(txn); - rpc::UniqueReply commandResponse = - client.runCommandWithMetadata(dbName, cmdObj.firstElementFieldName(), metadata, cmdObj); + rpc::UniqueReply commandResponse = client.runCommandWithMetadata( + dbName, cmdObj.firstElementFieldName(), rpc::makeEmptyMetadata(), cmdObj); BSONObj responseReply = commandResponse->getCommandReply().getOwned(); BSONObj responseMetadata = commandResponse->getMetadata().getOwned(); diff --git a/src/mongo/s/client/shard_local.h b/src/mongo/s/client/shard_local.h index e725e8dfe13..a5e990a7927 100644 --- a/src/mongo/s/client/shard_local.h +++ b/src/mongo/s/client/shard_local.h @@ -60,8 +60,7 @@ private: StatusWith<Shard::CommandResponse> _runCommand(OperationContext* txn, const ReadPreferenceSetting& unused, const std::string& dbName, - const BSONObj& cmdObj, - const BSONObj& metadata) final; + const BSONObj& cmdObj) final; StatusWith<Shard::QueryResponse> _exhaustiveFindOnConfig( OperationContext* txn, diff --git a/src/mongo/s/client/shard_local_test.cpp b/src/mongo/s/client/shard_local_test.cpp index 709aa7fb7fc..214202d4a7d 100644 --- a/src/mongo/s/client/shard_local_test.cpp +++ b/src/mongo/s/client/shard_local_test.cpp @@ -99,7 +99,6 @@ StatusWith<Shard::CommandResponse> ShardLocalTest::runFindAndModifyRunCommand(Na ReadPreferenceSetting{ReadPreference::PrimaryOnly}, nss.db().toString(), findAndModifyRequest.toBSON(), - BSONObj(), Shard::RetryPolicy::kNoRetry); } diff --git a/src/mongo/s/client/shard_registry.cpp b/src/mongo/s/client/shard_registry.cpp index 3825d56c603..a26ea13dc13 100644 --- a/src/mongo/s/client/shard_registry.cpp +++ b/src/mongo/s/client/shard_registry.cpp @@ -82,24 +82,6 @@ const char kCmdResponseWriteConcernField[] = "writeConcernError"; const Seconds kConfigCommandTimeout{30}; const int kOnErrorNumRetries = 3; -// TODO: This has been moved into Shard(Remote). Remove this from here once -// ShardRegistry::runIdempotentCommandOnConfig and ShardRegistry::runCommandOnConfigWithRetries -// are removed. -const BSONObj kReplMetadata(BSON(rpc::kReplSetMetadataFieldName << 1)); - -// TODO: This has been moved into Shard(Remote). Remove this from here once -// ShardRegistry::runIdempotentCommandOnShard is removed. -const BSONObj kSecondaryOkMetadata{rpc::ServerSelectionMetadata(true, boost::none).toBSON()}; - -// TODO: This has been moved into Shard(Remote). Remove this from here once -// ShardRegistry::runIdempotentCommandOnConfig is removed. -const BSONObj kReplSecondaryOkMetadata{[] { - BSONObjBuilder o; - o.appendElements(kSecondaryOkMetadata); - o.appendElements(kReplMetadata); - return o.obj(); -}()}; - BSONObj appendMaxTimeToCmdObj(long long maxTimeMicros, const BSONObj& cmdObj) { Seconds maxTime = kConfigCommandTimeout; @@ -503,9 +485,6 @@ StatusWith<BSONObj> ShardRegistry::runIdempotentCommandOnShard( readPref, dbName, cmdObj, - readPref.pref == ReadPreference::PrimaryOnly - ? rpc::makeEmptyMetadata() - : kSecondaryOkMetadata, kAllRetriableErrors); if (!response.isOK()) { return response.getStatus(); @@ -532,15 +511,13 @@ StatusWith<BSONObj> ShardRegistry::runIdempotentCommandOnConfig( const ReadPreferenceSetting& readPref, const std::string& dbName, const BSONObj& cmdObj) { - auto response = _runCommandWithRetries( - txn, - Grid::get(txn)->getExecutorPool()->getFixedExecutor(), - getConfigShard(), - readPref, - dbName, - cmdObj, - readPref.pref == ReadPreference::PrimaryOnly ? kReplMetadata : kReplSecondaryOkMetadata, - kAllRetriableErrors); + auto response = _runCommandWithRetries(txn, + Grid::get(txn)->getExecutorPool()->getFixedExecutor(), + getConfigShard(), + readPref, + dbName, + cmdObj, + kAllRetriableErrors); if (!response.isOK()) { return response.getStatus(); @@ -560,7 +537,6 @@ StatusWith<BSONObj> ShardRegistry::runCommandOnConfigWithRetries( ReadPreferenceSetting{ReadPreference::PrimaryOnly}, dbname, cmdObj, - kReplMetadata, errorsToCheck); if (!response.isOK()) { return response.getStatus(); @@ -576,7 +552,6 @@ StatusWith<Shard::CommandResponse> ShardRegistry::_runCommandWithRetries( const ReadPreferenceSetting& readPref, const std::string& dbname, const BSONObj& cmdObj, - const BSONObj& metadata, const ShardRegistry::ErrorCodesSet& errorsToCheck) { const bool isConfigShard = shard->isConfig(); @@ -586,7 +561,7 @@ StatusWith<Shard::CommandResponse> ShardRegistry::_runCommandWithRetries( : cmdObj); const auto swCmdResponse = shard->runCommand( - txn, readPref, dbname, cmdWithMaxTimeMS, metadata, Shard::RetryPolicy::kNoRetry); + txn, readPref, dbname, cmdWithMaxTimeMS, Shard::RetryPolicy::kNoRetry); // First, check if the request failed to even reach the shard, and if we should retry. Status requestStatus = swCmdResponse.getStatus(); diff --git a/src/mongo/s/client/shard_registry.h b/src/mongo/s/client/shard_registry.h index e144a85d199..46f6680a5db 100644 --- a/src/mongo/s/client/shard_registry.h +++ b/src/mongo/s/client/shard_registry.h @@ -291,7 +291,6 @@ private: const ReadPreferenceSetting& readPref, const std::string& dbname, const BSONObj& cmdObj, - const BSONObj& metadata, const ErrorCodesSet& errorsToCheck); // Factory to create shards. Never changed after startup so safe diff --git a/src/mongo/s/client/shard_remote.cpp b/src/mongo/s/client/shard_remote.cpp index 0f575533e88..c47a7607d59 100644 --- a/src/mongo/s/client/shard_remote.cpp +++ b/src/mongo/s/client/shard_remote.cpp @@ -67,6 +67,8 @@ const Status kInternalErrorStatus{ErrorCodes::InternalError, const Seconds kConfigCommandTimeout{30}; +const BSONObj kNoMetadata(rpc::makeEmptyMetadata()); + // Include kReplSetMetadataFieldName in a request to get the shard's ReplSetMetadata in the // response. const BSONObj kReplMetadata(BSON(rpc::kReplSetMetadataFieldName << 1)); @@ -203,11 +205,26 @@ std::string ShardRemote::toString() const { return getId() + ":" + _originalConnString.toString(); } +const BSONObj& ShardRemote::_getMetadataForCommand(const ReadPreferenceSetting& readPref) { + if (isConfig()) { + if (readPref.pref == ReadPreference::PrimaryOnly) { + return kReplMetadata; + } else { + return kReplSecondaryOkMetadata; + } + } else { + if (readPref.pref == ReadPreference::PrimaryOnly) { + return kNoMetadata; + } else { + return kSecondaryOkMetadata; + } + } +} + StatusWith<Shard::CommandResponse> ShardRemote::_runCommand(OperationContext* txn, const ReadPreferenceSetting& readPref, const string& dbName, - const BSONObj& cmdObj, - const BSONObj& metadata) { + const BSONObj& cmdObj) { const BSONObj cmdWithMaxTimeMS = (isConfig() ? appendMaxTimeToCmdObj(txn->getRemainingMaxTimeMicros(), cmdObj) : cmdObj); @@ -220,7 +237,7 @@ StatusWith<Shard::CommandResponse> ShardRemote::_runCommand(OperationContext* tx RemoteCommandRequest request(host.getValue(), dbName, cmdWithMaxTimeMS, - metadata, + _getMetadataForCommand(readPref), isConfig() ? kConfigCommandTimeout : executor::RemoteCommandRequest::kNoTimeout); StatusWith<RemoteCommandResponse> swResponse = @@ -354,8 +371,7 @@ StatusWith<Shard::QueryResponse> ShardRemote::_exhaustiveFindOnConfig( nss, findCmdBuilder.done(), fetcherCallback, - readPref.pref == ReadPreference::PrimaryOnly ? kReplMetadata - : kReplSecondaryOkMetadata, + _getMetadataForCommand(readPref), maxTime); Status scheduleStatus = fetcher.schedule(); if (!scheduleStatus.isOK()) { diff --git a/src/mongo/s/client/shard_remote.h b/src/mongo/s/client/shard_remote.h index 3e081e10a6c..a2ec30a9e9d 100644 --- a/src/mongo/s/client/shard_remote.h +++ b/src/mongo/s/client/shard_remote.h @@ -71,11 +71,19 @@ public: private: bool _isRetriableError(ErrorCodes::Error code, RetryPolicy options) final; + /** + * Returns the metadata that should be used when running commands against this shard with + * the given read preference. + * + * NOTE: This method returns a reference to a constant defined in shard_remote.cpp. Be careful + * to never change it to return a reference to a temporary. + */ + const BSONObj& _getMetadataForCommand(const ReadPreferenceSetting& readPref); + StatusWith<CommandResponse> _runCommand(OperationContext* txn, const ReadPreferenceSetting& readPref, const std::string& dbname, - const BSONObj& cmdObj, - const BSONObj& metadata) final; + const BSONObj& cmdObj) final; StatusWith<QueryResponse> _exhaustiveFindOnConfig(OperationContext* txn, const ReadPreferenceSetting& readPref, |