diff options
author | Kaloian Manassiev <kaloian.manassiev@mongodb.com> | 2016-05-09 15:24:03 -0400 |
---|---|---|
committer | Kaloian Manassiev <kaloian.manassiev@mongodb.com> | 2016-05-10 10:20:32 -0400 |
commit | 1d897277a9226a374a084c86a922096071ad0b1b (patch) | |
tree | 587f4775d4917e4a65212a59e7bfb3cd3cca544a /src | |
parent | 9f00caa5498c7b885035b83cd0ee6b661e24004a (diff) | |
download | mongo-1d897277a9226a374a084c86a922096071ad0b1b.tar.gz |
SERVER-24071 Use ChunkRange for parsing and creating chunk bounds
Diffstat (limited to 'src')
-rw-r--r-- | src/mongo/s/balancer/balancer.cpp | 3 | ||||
-rw-r--r-- | src/mongo/s/catalog/type_chunk.cpp | 8 | ||||
-rw-r--r-- | src/mongo/s/move_chunk_request.cpp | 50 | ||||
-rw-r--r-- | src/mongo/s/move_chunk_request.h | 17 | ||||
-rw-r--r-- | src/mongo/s/move_chunk_request_test.cpp | 3 |
5 files changed, 33 insertions, 48 deletions
diff --git a/src/mongo/s/balancer/balancer.cpp b/src/mongo/s/balancer/balancer.cpp index 95215846a5f..f65b5c88157 100644 --- a/src/mongo/s/balancer/balancer.cpp +++ b/src/mongo/s/balancer/balancer.cpp @@ -180,8 +180,7 @@ Status executeSingleMigration(OperationContext* txn, Grid::get(txn)->shardRegistry()->getConfigServerConnectionString(), migrateInfo.from, migrateInfo.to, - c->getMin(), - c->getMax(), + ChunkRange(c->getMin(), c->getMax()), maxChunkSizeBytes, secondaryThrottle, waitForDelete); diff --git a/src/mongo/s/catalog/type_chunk.cpp b/src/mongo/s/catalog/type_chunk.cpp index c366f1b1514..07e07fdf370 100644 --- a/src/mongo/s/catalog/type_chunk.cpp +++ b/src/mongo/s/catalog/type_chunk.cpp @@ -70,6 +70,10 @@ StatusWith<ChunkRange> ChunkRange::fromBSON(const BSONObj& obj) { return {minKeyStatus.code(), str::stream() << "Invalid min key due to " << minKeyStatus.reason()}; } + + if (minKey.Obj().isEmpty()) { + return {ErrorCodes::BadValue, "The min key cannot be empty"}; + } } BSONElement maxKey; @@ -79,6 +83,10 @@ StatusWith<ChunkRange> ChunkRange::fromBSON(const BSONObj& obj) { return {maxKeyStatus.code(), str::stream() << "Invalid max key due to " << maxKeyStatus.reason()}; } + + if (maxKey.Obj().isEmpty()) { + return {ErrorCodes::BadValue, "The max key cannot be empty"}; + } } return ChunkRange(minKey.Obj().getOwned(), maxKey.Obj().getOwned()); diff --git a/src/mongo/s/move_chunk_request.cpp b/src/mongo/s/move_chunk_request.cpp index 026193e365b..a60bd2a06d0 100644 --- a/src/mongo/s/move_chunk_request.cpp +++ b/src/mongo/s/move_chunk_request.cpp @@ -40,16 +40,17 @@ const char kMoveChunk[] = "moveChunk"; const char kConfigServerConnectionString[] = "configdb"; const char kFromShardId[] = "fromShard"; const char kToShardId[] = "toShard"; -const char kChunkMinKey[] = "min"; -const char kChunkMaxKey[] = "max"; const char kMaxChunkSizeBytes[] = "maxChunkSizeBytes"; const char kWaitForDelete[] = "waitForDelete"; } // namespace MoveChunkRequest::MoveChunkRequest(NamespaceString nss, + ChunkRange range, MigrationSecondaryThrottleOptions secondaryThrottle) - : _nss(std::move(nss)), _secondaryThrottle(std::move(secondaryThrottle)) {} + : _nss(std::move(nss)), + _range(std::move(range)), + _secondaryThrottle(std::move(secondaryThrottle)) {} StatusWith<MoveChunkRequest> MoveChunkRequest::createFromCommand(NamespaceString nss, const BSONObj& obj) { @@ -58,7 +59,14 @@ StatusWith<MoveChunkRequest> MoveChunkRequest::createFromCommand(NamespaceString return secondaryThrottleStatus.getStatus(); } - MoveChunkRequest request(std::move(nss), std::move(secondaryThrottleStatus.getValue())); + auto rangeStatus = ChunkRange::fromBSON(obj); + if (!rangeStatus.isOK()) { + return rangeStatus.getStatus(); + } + + MoveChunkRequest request(std::move(nss), + std::move(rangeStatus.getValue()), + std::move(secondaryThrottleStatus.getValue())); { std::string configServerConnectionString; @@ -91,34 +99,6 @@ StatusWith<MoveChunkRequest> MoveChunkRequest::createFromCommand(NamespaceString } { - BSONElement elem; - Status status = bsonExtractTypedField(obj, kChunkMinKey, BSONType::Object, &elem); - if (!status.isOK()) { - return status; - } - - request._minKey = elem.Obj().getOwned(); - - if (request._minKey.isEmpty()) { - return Status(ErrorCodes::UnsupportedFormat, "The chunk min key cannot be empty"); - } - } - - { - BSONElement elem; - Status status = bsonExtractTypedField(obj, kChunkMaxKey, BSONType::Object, &elem); - if (!status.isOK()) { - return status; - } - - request._maxKey = elem.Obj().getOwned(); - - if (request._maxKey.isEmpty()) { - return Status(ErrorCodes::UnsupportedFormat, "The chunk max key cannot be empty"); - } - } - - { Status status = bsonExtractBooleanFieldWithDefault(obj, kWaitForDelete, false, &request._waitForDelete); if (!status.isOK()) { @@ -145,8 +125,7 @@ void MoveChunkRequest::appendAsCommand(BSONObjBuilder* builder, const ConnectionString& configServerConnectionString, const std::string& fromShardId, const std::string& toShardId, - const BSONObj& chunkMinKey, - const BSONObj& chunkMaxKey, + const ChunkRange& range, int64_t maxChunkSizeBytes, const MigrationSecondaryThrottleOptions& secondaryThrottle, bool waitForDelete) { @@ -158,8 +137,7 @@ void MoveChunkRequest::appendAsCommand(BSONObjBuilder* builder, builder->append(kConfigServerConnectionString, configServerConnectionString.toString()); builder->append(kFromShardId, fromShardId); builder->append(kToShardId, toShardId); - builder->append(kChunkMinKey, chunkMinKey); - builder->append(kChunkMaxKey, chunkMaxKey); + range.append(builder); builder->append(kMaxChunkSizeBytes, static_cast<long long>(maxChunkSizeBytes)); secondaryThrottle.append(builder); builder->append(kWaitForDelete, waitForDelete); diff --git a/src/mongo/s/move_chunk_request.h b/src/mongo/s/move_chunk_request.h index 4c0632eeb8f..0df7c7a8dee 100644 --- a/src/mongo/s/move_chunk_request.h +++ b/src/mongo/s/move_chunk_request.h @@ -32,6 +32,7 @@ #include "mongo/client/connection_string.h" #include "mongo/db/namespace_string.h" +#include "mongo/s/catalog/type_chunk.h" #include "mongo/s/chunk_version.h" #include "mongo/s/migration_secondary_throttle_options.h" @@ -67,8 +68,7 @@ public: const ConnectionString& configServerConnectionString, const std::string& fromShardId, const std::string& toShardId, - const BSONObj& chunkMinKey, - const BSONObj& chunkMaxKey, + const ChunkRange& range, int64_t maxChunkSizeBytes, const MigrationSecondaryThrottleOptions& secondaryThrottle, bool waitForDelete); @@ -90,11 +90,11 @@ public: } const BSONObj& getMinKey() const { - return _minKey; + return _range.getMin(); } const BSONObj& getMaxKey() const { - return _maxKey; + return _range.getMax(); } int64_t getMaxChunkSizeBytes() const { @@ -110,7 +110,9 @@ public: } private: - MoveChunkRequest(NamespaceString nss, MigrationSecondaryThrottleOptions secondaryThrottle); + MoveChunkRequest(NamespaceString nss, + ChunkRange range, + MigrationSecondaryThrottleOptions secondaryThrottle); // The collection for which this request applies NamespaceString _nss; @@ -126,9 +128,8 @@ private: // The recipient shard id std::string _toShardId; - // Exact min and max key of the chunk being moved - BSONObj _minKey; - BSONObj _maxKey; + // Range of chunk chunk being moved + ChunkRange _range; // This value is used by the migration source to determine the data size threshold above which a // chunk would be considered jumbo and migrations will not proceed. diff --git a/src/mongo/s/move_chunk_request_test.cpp b/src/mongo/s/move_chunk_request_test.cpp index 1fbee88bfa9..e674288920d 100644 --- a/src/mongo/s/move_chunk_request_test.cpp +++ b/src/mongo/s/move_chunk_request_test.cpp @@ -47,8 +47,7 @@ TEST(MoveChunkRequest, CreateAsCommandComplete) { assertGet(ConnectionString::parse("TestConfigRS/CS1:12345,CS2:12345,CS3:12345")), "shard0001", "shard0002", - BSON("Key" << -100), - BSON("Key" << 100), + ChunkRange(BSON("Key" << -100), BSON("Key" << 100)), 1024, MigrationSecondaryThrottleOptions::create(MigrationSecondaryThrottleOptions::kOff), true); |