summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaolo Polato <paolo.polato@mongodb.com>2022-09-12 08:52:40 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-11-04 08:43:11 +0000
commita7d307ecb1a97c286c2e1084a92dead054ebd270 (patch)
tree99a43419c04bd2ac6da3cf45f4dd231247ff9e63
parentc1158a7d97c4603beca884b4f3a990c95d5f455f (diff)
downloadmongo-a7d307ecb1a97c286c2e1084a92dead054ebd270.tar.gz
SERVER-68126 Check constraints for maxChunkSize param in auto/splitVector commands
(cherry picked from commit 50b526fecf6e13b2ac8541b69564f368ac17a8ac) (cherry picked from commit a80813750a255a19690ef3335438091415f8b525)
-rw-r--r--src/mongo/db/s/auto_split_vector_command.cpp10
-rw-r--r--src/mongo/db/s/split_vector_command.cpp8
2 files changed, 18 insertions, 0 deletions
diff --git a/src/mongo/db/s/auto_split_vector_command.cpp b/src/mongo/db/s/auto_split_vector_command.cpp
index df88204dc0b..1aac404e8f1 100644
--- a/src/mongo/db/s/auto_split_vector_command.cpp
+++ b/src/mongo/db/s/auto_split_vector_command.cpp
@@ -36,6 +36,9 @@
namespace mongo {
namespace {
+static constexpr int64_t kSmallestChunkSizeBytesSupported = 1024 * 1024;
+static constexpr int64_t kBiggestChunkSizeBytesSupported = 1024 * 1024 * 1024;
+
class AutoSplitVectorCommand final : public TypedCommand<AutoSplitVectorCommand> {
public:
AllowedOnSecondary secondaryAllowed(ServiceContext*) const override {
@@ -63,6 +66,13 @@ public:
const auto& req = request();
+ uassert(ErrorCodes::ErrorCodes::InvalidOptions,
+ str::stream() << "maxChunksSizeBytes must lie within the range ["
+ << kSmallestChunkSizeBytesSupported / (1024 * 1024) << "MB, "
+ << kBiggestChunkSizeBytesSupported / (1024 * 1024) << "MB]",
+ req.getMaxChunkSizeBytes() >= kSmallestChunkSizeBytesSupported &&
+ req.getMaxChunkSizeBytes() <= kBiggestChunkSizeBytesSupported);
+
auto splitKeys = autoSplitVector(opCtx,
ns(),
req.getKeyPattern(),
diff --git a/src/mongo/db/s/split_vector_command.cpp b/src/mongo/db/s/split_vector_command.cpp
index 0b65dc3fc14..03c45cf4471 100644
--- a/src/mongo/db/s/split_vector_command.cpp
+++ b/src/mongo/db/s/split_vector_command.cpp
@@ -127,12 +127,20 @@ public:
BSONElement maxSizeElem = jsobj["maxChunkSize"];
if (maxSizeElem.isNumber()) {
maxChunkSize = maxSizeElem.numberLong();
+ if (*maxChunkSize < 1 || *maxChunkSize > 1024) {
+ errmsg = "The specified max chunk size must lie within the range [1MB, 1024MB]";
+ return false;
+ }
}
boost::optional<long long> maxChunkSizeBytes;
maxSizeElem = jsobj["maxChunkSizeBytes"];
if (maxSizeElem.isNumber()) {
maxChunkSizeBytes = maxSizeElem.numberLong();
+ if (*maxChunkSizeBytes < 1024 * 1024 || *maxChunkSizeBytes > 1024 * 1024 * 1024) {
+ errmsg = "The specified max chunk size must lie within the range [1MB, 1024MB]";
+ return false;
+ }
}
auto statusWithSplitKeys = splitVector(opCtx,