diff options
author | Simon Graetzer <simon.gratzer@mongodb.com> | 2021-07-30 11:41:40 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-07-30 12:09:37 +0000 |
commit | 66708080ab5db302558f7bd33293167d181f3858 (patch) | |
tree | 91dc9abafabbc7456b1db6d422087d2e04ba5bf2 /src/mongo/db/s/chunk_splitter.cpp | |
parent | a05959f3e16b909dd76f7935b7fb529d02942dff (diff) | |
download | mongo-66708080ab5db302558f7bd33293167d181f3858.tar.gz |
SERVER-58270 Create configureCollectionAutoSplitter command
Diffstat (limited to 'src/mongo/db/s/chunk_splitter.cpp')
-rw-r--r-- | src/mongo/db/s/chunk_splitter.cpp | 53 |
1 files changed, 30 insertions, 23 deletions
diff --git a/src/mongo/db/s/chunk_splitter.cpp b/src/mongo/db/s/chunk_splitter.cpp index 155b46a59ae..e3c3f69fe50 100644 --- a/src/mongo/db/s/chunk_splitter.cpp +++ b/src/mongo/db/s/chunk_splitter.cpp @@ -195,27 +195,6 @@ BSONObj findExtremeKeyForShard(OperationContext* opCtx, return shardKeyPattern.extractShardKeyFromDoc(end); } -/** - * Checks if autobalance is enabled on the current sharded collection. - */ -bool isAutoBalanceEnabled(OperationContext* opCtx, - const NamespaceString& nss, - BalancerConfiguration* balancerConfig) { - if (!balancerConfig->shouldBalanceForAutoSplit()) - return false; - - try { - return Grid::get(opCtx)->catalogClient()->getCollection(opCtx, nss).getAllowBalance(); - } catch (const DBException& ex) { - LOGV2(21903, - "Auto-split for {namespace} failed to load collection metadata: {error}", - "Auto-split failed to load collection metadata", - "namespace"_attr = nss, - "error"_attr = redact(ex)); - return false; - } -} - const auto getChunkSplitter = ServiceContext::declareDecoration<ChunkSplitter>(); } // namespace @@ -285,6 +264,28 @@ void ChunkSplitter::trySplitting(std::shared_ptr<ChunkSplitStateDriver> chunkSpl }); } +/** + * Checks if autobalance is enabled on the current sharded collection. + */ +bool isAutoBalanceEnabled(OperationContext* opCtx, + const NamespaceString& nss, + BalancerConfiguration* balancerConfig) { + if (!balancerConfig->shouldBalanceForAutoSplit()) { + return false; + } + + try { + return Grid::get(opCtx)->catalogClient()->getCollection(opCtx, nss).getAllowBalance(); + } catch (const DBException& ex) { + LOGV2(21903, + "Auto-split for {namespace} failed to load collection metadata: {error}", + "Auto-split failed to load collection metadata", + "namespace"_attr = nss, + "error"_attr = redact(ex)); + return false; + } +} + void ChunkSplitter::_runAutosplit(std::shared_ptr<ChunkSplitStateDriver> chunkSplitStateDriver, const NamespaceString& nss, const BSONObj& min, @@ -320,11 +321,17 @@ void ChunkSplitter::_runAutosplit(std::shared_ptr<ChunkSplitStateDriver> chunkSp // Ensure we have the most up-to-date balancer configuration uassertStatusOK(balancerConfig->refreshAndCheck(opCtx.get())); - if (!balancerConfig->getShouldAutoSplit()) { + if (!balancerConfig->getShouldAutoSplit() || !cm.allowAutoSplit()) { return; } - const uint64_t maxChunkSizeBytes = balancerConfig->getMaxChunkSizeBytes(); + const uint64_t maxChunkSizeBytes = [&] { + if (cm.maxChunkSizeBytes()) { + return *cm.maxChunkSizeBytes(); + } + return balancerConfig->getMaxChunkSizeBytes(); + }(); + invariant(ChunkSizeSettingsType::checkMaxChunkSizeValid(maxChunkSizeBytes)); LOGV2_DEBUG(21906, 1, |