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:16:31 +0000 |
commit | 90ae9880af957e70cf104548c446a7cbb760f69c (patch) | |
tree | 31868e458d7b3e4e90273f520f7e647f51ac5523 | |
parent | d9646a90f318f7dfc824039462dc431ecf7af886 (diff) | |
download | mongo-90ae9880af957e70cf104548c446a7cbb760f69c.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 | 17 |
2 files changed, 17 insertions, 8 deletions
diff --git a/src/mongo/db/s/auto_split_vector.cpp b/src/mongo/db/s/auto_split_vector.cpp index 0f9544cc25e..2dcb509f156 100644 --- a/src/mongo/db/s/auto_split_vector.cpp +++ b/src/mongo/db/s/auto_split_vector.cpp @@ -94,9 +94,11 @@ const std::tuple<BSONObj, BSONObj> getMinMaxExtendedBounds(const ShardKeyIndex& /* * 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 276b91951e7..8b232db42a5 100644 --- a/src/mongo/db/s/split_vector.cpp +++ b/src/mongo/db/s/split_vector.cpp @@ -57,6 +57,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, @@ -222,17 +232,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(shardKeyIdx->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(shardKeyIdx->keyPattern(), currKey.getOwned()), keyPattern); - + currKey = orderShardKeyFields(keyPattern, currKey.getOwned()); const auto compareWithPreviousSplitPoint = currKey.woCompare(splitKeys.back()); dassert(compareWithPreviousSplitPoint >= 0, |