diff options
author | Spencer T Brody <spencer@mongodb.com> | 2016-08-26 17:47:07 -0400 |
---|---|---|
committer | Spencer T Brody <spencer@mongodb.com> | 2016-08-29 18:13:12 -0400 |
commit | 973a02dac92d3d192fd5e98011c4c4704356c3e2 (patch) | |
tree | 84546958e4e5ba49f4e2a2839e274bbb7233ec3e /src/mongo/s/client | |
parent | 3f7812c99ded16e6286e1fd40323e57c939797ed (diff) | |
download | mongo-973a02dac92d3d192fd5e98011c4c4704356c3e2.tar.gz |
SERVER-25832 Rename Shard::runCommand to Shard::runCommandWithFixedRetryAttempts
Diffstat (limited to 'src/mongo/s/client')
-rw-r--r-- | src/mongo/s/client/shard.cpp | 22 | ||||
-rw-r--r-- | src/mongo/s/client/shard.h | 25 | ||||
-rw-r--r-- | src/mongo/s/client/shard_local_test.cpp | 22 |
3 files changed, 58 insertions, 11 deletions
diff --git a/src/mongo/s/client/shard.cpp b/src/mongo/s/client/shard.cpp index 445b63b3dbe..622c6ea7c50 100644 --- a/src/mongo/s/client/shard.cpp +++ b/src/mongo/s/client/shard.cpp @@ -106,7 +106,7 @@ StatusWith<Shard::CommandResponse> Shard::runCommand(OperationContext* txn, const std::string& dbName, const BSONObj& cmdObj, RetryPolicy retryPolicy) { - return runCommand(txn, readPref, dbName, cmdObj, Milliseconds::max(), retryPolicy); + MONGO_UNREACHABLE; } StatusWith<Shard::CommandResponse> Shard::runCommand(OperationContext* txn, @@ -115,6 +115,26 @@ StatusWith<Shard::CommandResponse> Shard::runCommand(OperationContext* txn, const BSONObj& cmdObj, Milliseconds maxTimeMSOverride, RetryPolicy retryPolicy) { + MONGO_UNREACHABLE; +} + +StatusWith<Shard::CommandResponse> Shard::runCommandWithFixedRetryAttempts( + OperationContext* txn, + const ReadPreferenceSetting& readPref, + const std::string& dbName, + const BSONObj& cmdObj, + RetryPolicy retryPolicy) { + return runCommandWithFixedRetryAttempts( + txn, readPref, dbName, cmdObj, Milliseconds::max(), retryPolicy); +} + +StatusWith<Shard::CommandResponse> Shard::runCommandWithFixedRetryAttempts( + OperationContext* txn, + const ReadPreferenceSetting& readPref, + const std::string& dbName, + const BSONObj& cmdObj, + Milliseconds maxTimeMSOverride, + RetryPolicy retryPolicy) { for (int retry = 1; retry <= kOnErrorNumRetries; ++retry) { auto hostWithResponse = _runCommand(txn, readPref, dbName, maxTimeMSOverride, cmdObj); auto swCmdResponse = std::move(hostWithResponse.commandResponse); diff --git a/src/mongo/s/client/shard.h b/src/mongo/s/client/shard.h index 96dfecd204c..1f3866e84e3 100644 --- a/src/mongo/s/client/shard.h +++ b/src/mongo/s/client/shard.h @@ -160,6 +160,31 @@ public: RetryPolicy retryPolicy); /** + * Same as runCommand, but will only retry failed operations up to 3 times, regardless of + * the retryPolicy or the remaining maxTimeMs. + * Wherever possible this method should be avoided in favor of runCommand. + */ + StatusWith<CommandResponse> runCommandWithFixedRetryAttempts( + OperationContext* txn, + const ReadPreferenceSetting& readPref, + const std::string& dbName, + const BSONObj& cmdObj, + RetryPolicy retryPolicy); + + /** + * Same as runCommand, but will only retry failed operations up to 3 times, regardless of + * the retryPolicy or the remaining maxTimeMs. + * Wherever possible this method should be avoided in favor of runCommand. + */ + StatusWith<CommandResponse> runCommandWithFixedRetryAttempts( + OperationContext* txn, + const ReadPreferenceSetting& readPref, + const std::string& dbName, + const BSONObj& cmdObj, + Milliseconds maxTimeMSOverride, + RetryPolicy retryPolicy); + + /** * Expects a single-entry batch wrtie command and runs it on the config server's primary using * the specified retry policy. */ diff --git a/src/mongo/s/client/shard_local_test.cpp b/src/mongo/s/client/shard_local_test.cpp index 409d8dba86d..3bd026db9ed 100644 --- a/src/mongo/s/client/shard_local_test.cpp +++ b/src/mongo/s/client/shard_local_test.cpp @@ -103,19 +103,21 @@ StatusWith<Shard::CommandResponse> ShardLocalTest::runFindAndModifyRunCommand(Na findAndModifyRequest.setWriteConcern(WriteConcernOptions( WriteConcernOptions::kMajority, WriteConcernOptions::SyncMode::UNSET, Seconds(15))); - return _shardLocal->runCommand(_txn.get(), - ReadPreferenceSetting{ReadPreference::PrimaryOnly}, - nss.db().toString(), - findAndModifyRequest.toBSON(), - Shard::RetryPolicy::kNoRetry); + return _shardLocal->runCommandWithFixedRetryAttempts( + _txn.get(), + ReadPreferenceSetting{ReadPreference::PrimaryOnly}, + nss.db().toString(), + findAndModifyRequest.toBSON(), + Shard::RetryPolicy::kNoRetry); } StatusWith<std::vector<BSONObj>> ShardLocalTest::getIndexes(NamespaceString nss) { - auto response = _shardLocal->runCommand(_txn.get(), - ReadPreferenceSetting{ReadPreference::PrimaryOnly}, - nss.db().toString(), - BSON("listIndexes" << nss.coll().toString()), - Shard::RetryPolicy::kIdempotent); + auto response = _shardLocal->runCommandWithFixedRetryAttempts( + _txn.get(), + ReadPreferenceSetting{ReadPreference::PrimaryOnly}, + nss.db().toString(), + BSON("listIndexes" << nss.coll().toString()), + Shard::RetryPolicy::kIdempotent); if (!response.isOK()) { return response.getStatus(); } |