diff options
author | Jordi Serra Torrens <jordi.serra-torrens@mongodb.com> | 2022-08-16 08:16:52 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-08-23 10:11:38 +0000 |
commit | 233f00f74caa8cf4cf04ad8ca1343a7408949fab (patch) | |
tree | d20520b35b5c245618a56f842e3966b0e8c5f11e | |
parent | 590a646c81390f8877aa761d98d5d1ffd442ecfa (diff) | |
download | mongo-233f00f74caa8cf4cf04ad8ca1343a7408949fab.tar.gz |
SERVER-65382 Don't use clientReadable in AutoSplitVector when reordering shard key fields
(cherry picked from commit 56dab5c0dcfbebcc2f5910a82f78dd4678620532)
-rw-r--r-- | src/mongo/db/s/auto_split_vector.cpp | 8 | ||||
-rw-r--r-- | src/mongo/db/s/split_vector.cpp | 16 |
2 files changed, 17 insertions, 7 deletions
diff --git a/src/mongo/db/s/auto_split_vector.cpp b/src/mongo/db/s/auto_split_vector.cpp index 0100bd4e31f..30a8934dbbb 100644 --- a/src/mongo/db/s/auto_split_vector.cpp +++ b/src/mongo/db/s/auto_split_vector.cpp @@ -93,9 +93,11 @@ const std::tuple<BSONObj, BSONObj> getMinMaxExtendedBounds(const IndexDescriptor /* * Reshuffle fields according to the shard key pattern. */ -auto orderShardKeyFields(const BSONObj& keyPattern, BSONObj& key) { - return dotted_path_support::extractElementsBasedOnTemplate( - prettyKey(keyPattern, key.getOwned()), keyPattern); +auto orderShardKeyFields(const BSONObj& keyPattern, const BSONObj& key) { + // Note: It is correct to hydrate the indexKey 'key' with 'keyPattern', because the index key + // pattern is a prefix of 'keyPattern'. + return dotted_path_support::extractElementsBasedOnTemplate(key.replaceFieldNames(keyPattern), + keyPattern); } } // namespace diff --git a/src/mongo/db/s/split_vector.cpp b/src/mongo/db/s/split_vector.cpp index 57d4743e93d..f7cbf3e677c 100644 --- a/src/mongo/db/s/split_vector.cpp +++ b/src/mongo/db/s/split_vector.cpp @@ -56,6 +56,16 @@ BSONObj prettyKey(const BSONObj& keyPattern, const BSONObj& key) { return key.replaceFieldNames(keyPattern).clientReadable(); } +/* + * Reshuffle fields according to the shard key pattern. + */ +auto orderShardKeyFields(const BSONObj& keyPattern, const BSONObj& key) { + // Note: It is correct to hydrate the indexKey 'key' with 'keyPattern', because the index key + // pattern is a prefix of 'keyPattern'. + return dotted_path_support::extractElementsBasedOnTemplate(key.replaceFieldNames(keyPattern), + keyPattern); +} + } // namespace std::vector<BSONObj> splitVector(OperationContext* opCtx, @@ -216,16 +226,14 @@ std::vector<BSONObj> splitVector(OperationContext* opCtx, // to be removed at the end. If a key appears more times than entries allowed on a // chunk, we issue a warning and split on the following key. auto tooFrequentKeys = SimpleBSONObjComparator::kInstance.makeBSONObjSet(); - splitKeys.push_back(dotted_path_support::extractElementsBasedOnTemplate( - prettyKey(idx->keyPattern(), currKey.getOwned()), keyPattern)); + splitKeys.push_back(orderShardKeyFields(keyPattern, currKey.getOwned())); while (1) { while (PlanExecutor::ADVANCED == state) { currCount++; if (currCount > keyCount && !force) { - currKey = dotted_path_support::extractElementsBasedOnTemplate( - prettyKey(idx->keyPattern(), currKey.getOwned()), keyPattern); + currKey = orderShardKeyFields(keyPattern, currKey.getOwned()); // Do not use this split key if it is the same used in the previous split // point. |