diff options
author | Spencer T Brody <spencer@mongodb.com> | 2016-04-27 17:38:50 -0400 |
---|---|---|
committer | Spencer T Brody <spencer@mongodb.com> | 2016-05-02 18:45:07 -0400 |
commit | 52d9ecc1106023bb3e749ac7368391d780d3b3a2 (patch) | |
tree | 9ab26e92490727787c0ef7a7278d7d6862d89f21 /src/mongo/s/shard_util.cpp | |
parent | 070f32758b680425b0a6995b881fcb843a7db6cf (diff) | |
download | mongo-52d9ecc1106023bb3e749ac7368391d780d3b3a2.tar.gz |
SERVER-23211 Remove all callers of ShardRegistry::runIdempotentCommandOnShard
Diffstat (limited to 'src/mongo/s/shard_util.cpp')
-rw-r--r-- | src/mongo/s/shard_util.cpp | 98 |
1 files changed, 62 insertions, 36 deletions
diff --git a/src/mongo/s/shard_util.cpp b/src/mongo/s/shard_util.cpp index beb84eee609..3083b8f251c 100644 --- a/src/mongo/s/shard_util.cpp +++ b/src/mongo/s/shard_util.cpp @@ -52,18 +52,25 @@ const char kShouldMigrate[] = "shouldMigrate"; } StatusWith<long long> retrieveTotalShardSize(OperationContext* txn, const ShardId& shardId) { - auto shardRegistry = Grid::get(txn)->shardRegistry(); - auto listDatabasesStatus = shardRegistry->runIdempotentCommandOnShard( - txn, - shardId, - ReadPreferenceSetting{ReadPreference::PrimaryPreferred}, - "admin", - BSON("listDatabases" << 1)); + auto shard = Grid::get(txn)->shardRegistry()->getShard(txn, shardId); + if (!shard) { + return Status(ErrorCodes::ShardNotFound, + str::stream() << "shard " << shardId << " not found"); + } + auto listDatabasesStatus = + shard->runCommand(txn, + ReadPreferenceSetting{ReadPreference::PrimaryPreferred}, + "admin", + BSON("listDatabases" << 1), + Shard::RetryPolicy::kIdempotent); if (!listDatabasesStatus.isOK()) { - return listDatabasesStatus.getStatus(); + return std::move(listDatabasesStatus.getStatus()); + } + if (!listDatabasesStatus.getValue().commandStatus.isOK()) { + return std::move(listDatabasesStatus.getValue().commandStatus); } - BSONElement totalSizeElem = listDatabasesStatus.getValue()["totalSize"]; + BSONElement totalSizeElem = listDatabasesStatus.getValue().response["totalSize"]; if (!totalSizeElem.isNumber()) { return {ErrorCodes::NoSuchKey, "totalSize field not found in listDatabases"}; } @@ -84,20 +91,25 @@ StatusWith<BSONObj> selectMedianKey(OperationContext* txn, cmd.append("max", maxKey); cmd.appendBool("force", true); - auto shardRegistry = Grid::get(txn)->shardRegistry(); - auto cmdStatus = shardRegistry->runIdempotentCommandOnShard( - txn, shardId, ReadPreferenceSetting{ReadPreference::PrimaryPreferred}, "admin", cmd.obj()); + auto shard = Grid::get(txn)->shardRegistry()->getShard(txn, shardId); + if (!shard) { + return Status(ErrorCodes::ShardNotFound, + str::stream() << "shard " << shardId << " not found"); + } + auto cmdStatus = shard->runCommand(txn, + ReadPreferenceSetting{ReadPreference::PrimaryPreferred}, + "admin", + cmd.obj(), + Shard::RetryPolicy::kIdempotent); if (!cmdStatus.isOK()) { - return cmdStatus.getStatus(); + return std::move(cmdStatus.getStatus()); } - - const auto response = std::move(cmdStatus.getValue()); - - Status status = getStatusFromCommandResult(response); - if (!status.isOK()) { - return status; + if (!cmdStatus.getValue().commandStatus.isOK()) { + return std::move(cmdStatus.getValue().commandStatus); } + const auto response = std::move(cmdStatus.getValue().response); + BSONObjIterator it(response.getObjectField("splitKeys")); if (it.more()) { return it.next().Obj().getOwned(); @@ -124,20 +136,25 @@ StatusWith<std::vector<BSONObj>> selectChunkSplitPoints(OperationContext* txn, cmd.append("maxSplitPoints", maxPoints); cmd.append("maxChunkObjects", maxObjs); - auto shardRegistry = Grid::get(txn)->shardRegistry(); - auto cmdStatus = shardRegistry->runIdempotentCommandOnShard( - txn, shardId, ReadPreferenceSetting{ReadPreference::PrimaryPreferred}, "admin", cmd.obj()); + auto shard = Grid::get(txn)->shardRegistry()->getShard(txn, shardId); + if (!shard) { + return Status(ErrorCodes::ShardNotFound, + str::stream() << "shard " << shardId << " not found"); + } + auto cmdStatus = shard->runCommand(txn, + ReadPreferenceSetting{ReadPreference::PrimaryPreferred}, + "admin", + cmd.obj(), + Shard::RetryPolicy::kIdempotent); if (!cmdStatus.isOK()) { - return cmdStatus.getStatus(); + return std::move(cmdStatus.getStatus()); } - - const auto response = std::move(cmdStatus.getValue()); - - Status status = getStatusFromCommandResult(response); - if (!status.isOK()) { - return status; + if (!cmdStatus.getValue().commandStatus.isOK()) { + return std::move(cmdStatus.getValue().commandStatus); } + const auto response = std::move(cmdStatus.getValue().response); + std::vector<BSONObj> splitPoints; BSONObjIterator it(response.getObjectField("splitKeys")); @@ -181,13 +198,24 @@ StatusWith<boost::optional<std::pair<BSONObj, BSONObj>>> splitChunkAtMultiplePoi BSONObj cmdObj = cmd.obj(); Status status{ErrorCodes::InternalError, "Uninitialized value"}; + BSONObj cmdResponse; - auto cmdStatus = Grid::get(txn)->shardRegistry()->runIdempotentCommandOnShard( - txn, shardId, ReadPreferenceSetting{ReadPreference::PrimaryOnly}, "admin", cmdObj); - if (!cmdStatus.isOK()) { - status = std::move(cmdStatus.getStatus()); + auto shard = Grid::get(txn)->shardRegistry()->getShard(txn, shardId); + if (!shard) { + status = + Status(ErrorCodes::ShardNotFound, str::stream() << "shard " << shardId << " not found"); } else { - status = getStatusFromCommandResult(cmdStatus.getValue()); + auto cmdStatus = shard->runCommand(txn, + ReadPreferenceSetting{ReadPreference::PrimaryOnly}, + "admin", + cmdObj, + Shard::RetryPolicy::kNotIdempotent); + if (!cmdStatus.isOK()) { + status = std::move(cmdStatus.getStatus()); + } else { + status = std::move(cmdStatus.getValue().commandStatus); + cmdResponse = std::move(cmdStatus.getValue().response); + } } if (!status.isOK()) { @@ -195,8 +223,6 @@ StatusWith<boost::optional<std::pair<BSONObj, BSONObj>>> splitChunkAtMultiplePoi return {status.code(), str::stream() << "split failed due to " << status.toString()}; } - BSONObj cmdResponse = std::move(cmdStatus.getValue()); - BSONElement shouldMigrateElement; status = bsonExtractTypedField(cmdResponse, kShouldMigrate, Object, &shouldMigrateElement); if (status.isOK()) { |