summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJordi Serra Torrens <jordi.serra-torrens@mongodb.com>2022-08-16 08:16:52 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-08-23 10:31:09 +0000
commit9c05fbc0ed4410d00d1ad32f74733660e4179c05 (patch)
treebb4281244c434b6aa2c9e9f7c450a234a5d73f43
parentb6a46beabe55c02587f3938278b970a3af4dc4c8 (diff)
downloadmongo-9c05fbc0ed4410d00d1ad32f74733660e4179c05.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.cpp8
-rw-r--r--src/mongo/db/s/split_vector.cpp16
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 9f4335f9f2b..d3ef36d9d1c 100644
--- a/src/mongo/db/s/auto_split_vector.cpp
+++ b/src/mongo/db/s/auto_split_vector.cpp
@@ -135,9 +135,11 @@ bool maxKeyEqualToMinKey(OperationContext* opCtx,
/*
* 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 68c55a8df1e..dbe4eb2567e 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
StatusWith<std::vector<BSONObj>> splitVector(OperationContext* opCtx,
@@ -222,16 +232,14 @@ StatusWith<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.