diff options
Diffstat (limited to 'src/mongo/db/s')
-rw-r--r-- | src/mongo/db/s/chunk_splitter.cpp | 45 |
1 files changed, 14 insertions, 31 deletions
diff --git a/src/mongo/db/s/chunk_splitter.cpp b/src/mongo/db/s/chunk_splitter.cpp index 814c24c227a..94ff2e4bc81 100644 --- a/src/mongo/db/s/chunk_splitter.cpp +++ b/src/mongo/db/s/chunk_splitter.cpp @@ -284,25 +284,13 @@ void ChunkSplitter::_runAutosplit(const NamespaceString& nss, const auto routingInfo = uassertStatusOK( Grid::get(opCtx.get())->catalogCache()->getCollectionRoutingInfo(opCtx.get(), nss)); + const auto cm = routingInfo.cm(); uassert(ErrorCodes::NamespaceNotSharded, "Could not split chunk. Collection is no longer sharded", - routingInfo.cm()); + cm); - const auto cm = routingInfo.cm(); const auto chunk = cm->findIntersectingChunkWithSimpleCollation(min); - - // Stop if chunk's range differs from the range we were expecting to split. - if ((0 != chunk.getMin().woCompare(min)) || (0 != chunk.getMax().woCompare(max)) || - (chunk.getShardId() != ShardingState::get(opCtx.get())->getShardName())) { - LOG(1) << "Cannot auto-split chunk with range '" - << redact(ChunkRange(min, max).toString()) << "' for nss '" << nss - << "' on shard '" << ShardingState::get(opCtx.get())->getShardName() - << "' because since scheduling auto-split the chunk has been changed to '" - << redact(chunk.toString()) << "'"; - return; - } - - const ChunkRange chunkRange(chunk.getMin(), chunk.getMax()); + const auto& shardKeyPattern = cm->getShardKeyPattern(); const auto balancerConfig = Grid::get(opCtx.get())->getBalancerConfiguration(); // Ensure we have the most up-to-date balancer configuration @@ -320,7 +308,7 @@ void ChunkSplitter::_runAutosplit(const NamespaceString& nss, auto splitPoints = uassertStatusOK(splitVector(opCtx.get(), nss, - cm->getShardKeyPattern().toBSON(), + shardKeyPattern.toBSON(), chunk.getMin(), chunk.getMax(), false, @@ -344,23 +332,19 @@ void ChunkSplitter::_runAutosplit(const NamespaceString& nss, // Keeps track of the minKey of the top chunk after the split so we can migrate the chunk. BSONObj topChunkMinKey; - - if (KeyPattern::isOrderedKeyPattern(cm->getShardKeyPattern().toBSON())) { - if (0 == - cm->getShardKeyPattern().getKeyPattern().globalMin().woCompare(chunk.getMin())) { + const auto skpGlobalMin = shardKeyPattern.getKeyPattern().globalMin(); + const auto skpGlobalMax = shardKeyPattern.getKeyPattern().globalMax(); + if (KeyPattern::isOrderedKeyPattern(shardKeyPattern.toBSON())) { + if (skpGlobalMin.woCompare(min) == 0) { // MinKey is infinity (This is the first chunk on the collection) - BSONObj key = - findExtremeKeyForShard(opCtx.get(), nss, cm->getShardKeyPattern(), true); + BSONObj key = findExtremeKeyForShard(opCtx.get(), nss, shardKeyPattern, true); if (!key.isEmpty()) { splitPoints.front() = key.getOwned(); - topChunkMinKey = cm->getShardKeyPattern().getKeyPattern().globalMin(); + topChunkMinKey = skpGlobalMin; } - } else if (0 == - cm->getShardKeyPattern().getKeyPattern().globalMax().woCompare( - chunk.getMax())) { + } else if (skpGlobalMax.woCompare(max) == 0) { // MaxKey is infinity (This is the last chunk on the collection) - BSONObj key = - findExtremeKeyForShard(opCtx.get(), nss, cm->getShardKeyPattern(), false); + BSONObj key = findExtremeKeyForShard(opCtx.get(), nss, shardKeyPattern, false); if (!key.isEmpty()) { splitPoints.back() = key.getOwned(); topChunkMinKey = key.getOwned(); @@ -371,9 +355,9 @@ void ChunkSplitter::_runAutosplit(const NamespaceString& nss, uassertStatusOK(splitChunkAtMultiplePoints(opCtx.get(), chunk.getShardId(), nss, - cm->getShardKeyPattern(), + shardKeyPattern, cm->getVersion(), - chunkRange, + ChunkRange(min, max), splitPoints)); const bool shouldBalance = isAutoBalanceEnabled(opCtx.get(), nss, balancerConfig); @@ -386,7 +370,6 @@ void ChunkSplitter::_runAutosplit(const NamespaceString& nss, // Balance the resulting chunks if the autobalance option is enabled and if we split at the // first or last chunk on the collection as part of top chunk optimization. - if (!shouldBalance || topChunkMinKey.isEmpty()) { return; } |