summaryrefslogtreecommitdiff
path: root/src/mongo/s/shard_util.cpp
diff options
context:
space:
mode:
authorKaloian Manassiev <kaloian.manassiev@mongodb.com>2017-01-24 16:54:18 -0500
committerKaloian Manassiev <kaloian.manassiev@mongodb.com>2017-01-25 17:13:38 -0500
commit5d2fbb084e463ef3417dffac0f01246698c1a404 (patch)
tree5f4e0009cde02904e5e7a29910ef516099f2a1cc /src/mongo/s/shard_util.cpp
parent4e127648494ef32a1e77c2b4941673c1b99c62c8 (diff)
downloadmongo-5d2fbb084e463ef3417dffac0f01246698c1a404.tar.gz
SERVER-27809 Move chunk 'at median' split to the cluster split command
This is the only place where it is used.
Diffstat (limited to 'src/mongo/s/shard_util.cpp')
-rw-r--r--src/mongo/s/shard_util.cpp73
1 files changed, 23 insertions, 50 deletions
diff --git a/src/mongo/s/shard_util.cpp b/src/mongo/s/shard_util.cpp
index ff5ecba7442..65ad93d48ea 100644
--- a/src/mongo/s/shard_util.cpp
+++ b/src/mongo/s/shard_util.cpp
@@ -80,61 +80,18 @@ StatusWith<long long> retrieveTotalShardSize(OperationContext* txn, const ShardI
return totalSizeElem.numberLong();
}
-StatusWith<BSONObj> selectMedianKey(OperationContext* txn,
- const ShardId& shardId,
- const NamespaceString& nss,
- const ShardKeyPattern& shardKeyPattern,
- const BSONObj& minKey,
- const BSONObj& maxKey) {
- BSONObjBuilder cmd;
- cmd.append("splitVector", nss.ns());
- cmd.append("keyPattern", shardKeyPattern.toBSON());
- cmd.append(kMinKey, minKey);
- cmd.append(kMaxKey, maxKey);
- cmd.appendBool("force", true);
-
- auto shardStatus = Grid::get(txn)->shardRegistry()->getShard(txn, shardId);
- if (!shardStatus.isOK()) {
- return shardStatus.getStatus();
- }
-
- auto cmdStatus = shardStatus.getValue()->runCommandWithFixedRetryAttempts(
- txn,
- ReadPreferenceSetting{ReadPreference::PrimaryPreferred},
- "admin",
- cmd.obj(),
- Shard::RetryPolicy::kIdempotent);
- if (!cmdStatus.isOK()) {
- return std::move(cmdStatus.getStatus());
- }
- 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();
- }
-
- return BSONObj();
-}
-
StatusWith<std::vector<BSONObj>> selectChunkSplitPoints(OperationContext* txn,
const ShardId& shardId,
const NamespaceString& nss,
const ShardKeyPattern& shardKeyPattern,
- const BSONObj& minKey,
- const BSONObj& maxKey,
+ const ChunkRange& chunkRange,
long long chunkSizeBytes,
int maxPoints,
int maxObjs) {
BSONObjBuilder cmd;
cmd.append("splitVector", nss.ns());
cmd.append("keyPattern", shardKeyPattern.toBSON());
- cmd.append(kMinKey, minKey);
- cmd.append(kMaxKey, maxKey);
+ chunkRange.append(&cmd);
cmd.append("maxChunkSizeBytes", chunkSizeBytes);
cmd.append("maxSplitPoints", maxPoints);
cmd.append("maxChunkObjects", maxObjs);
@@ -175,11 +132,9 @@ StatusWith<boost::optional<ChunkRange>> splitChunkAtMultiplePoints(
const NamespaceString& nss,
const ShardKeyPattern& shardKeyPattern,
ChunkVersion collectionVersion,
- const BSONObj& minKey,
- const BSONObj& maxKey,
+ const ChunkRange& chunkRange,
const std::vector<BSONObj>& splitPoints) {
invariant(!splitPoints.empty());
- invariant(minKey.woCompare(maxKey) < 0);
const size_t kMaxSplitPoints = 8192;
@@ -189,6 +144,25 @@ StatusWith<boost::optional<ChunkRange>> splitChunkAtMultiplePoints(
<< " parts at a time."};
}
+ // Sanity check that we are not attempting to split at the boundaries of the chunk. This check
+ // is already performed at chunk split commit time, but we are performing it here for parity
+ // with old auto-split code, which might rely on it.
+ if (SimpleBSONObjComparator::kInstance.evaluate(chunkRange.getMin() == splitPoints.front())) {
+ const std::string msg(str::stream() << "not splitting chunk " << chunkRange.toString()
+ << ", split point "
+ << splitPoints.front()
+ << " is exactly on chunk bounds");
+ return {ErrorCodes::CannotSplit, msg};
+ }
+
+ if (SimpleBSONObjComparator::kInstance.evaluate(chunkRange.getMax() == splitPoints.back())) {
+ const std::string msg(str::stream() << "not splitting chunk " << chunkRange.toString()
+ << ", split point "
+ << splitPoints.back()
+ << " is exactly on chunk bounds");
+ return {ErrorCodes::CannotSplit, msg};
+ }
+
BSONObjBuilder cmd;
cmd.append("splitChunk", nss.ns());
cmd.append("configdb",
@@ -196,8 +170,7 @@ StatusWith<boost::optional<ChunkRange>> splitChunkAtMultiplePoints(
cmd.append("from", shardId.toString());
cmd.append("keyPattern", shardKeyPattern.toBSON());
collectionVersion.appendForCommands(&cmd);
- cmd.append(kMinKey, minKey);
- cmd.append(kMaxKey, maxKey);
+ chunkRange.append(&cmd);
cmd.append("splitKeys", splitPoints);
BSONObj cmdObj = cmd.obj();