summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuis Osta <luis.osta@mongodb.com>2021-07-27 14:33:22 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-07-27 14:56:51 +0000
commitca7a3ba8e51377f3cf9e8fdf3e1883c1ea8bfdb5 (patch)
tree0196cdd044a33eba17beda6a2ba8a17fbfcd305b
parent154008633e31b5d947f97e97f72a397b4221e16b (diff)
downloadmongo-ca7a3ba8e51377f3cf9e8fdf3e1883c1ea8bfdb5.tar.gz
SERVER-58048 Resharding's initial split points for hashed shard keys don't match the sampled values (cherry picked from commit a0fe43ef0713bf923884e6afa1b11bab992f1ca9)
-rw-r--r--src/mongo/db/s/config/initial_split_policy.cpp6
-rw-r--r--src/mongo/db/s/config/initial_split_policy_test.cpp6
2 files changed, 8 insertions, 4 deletions
diff --git a/src/mongo/db/s/config/initial_split_policy.cpp b/src/mongo/db/s/config/initial_split_policy.cpp
index df5005db193..0a1653aaf15 100644
--- a/src/mongo/db/s/config/initial_split_policy.cpp
+++ b/src/mongo/db/s/config/initial_split_policy.cpp
@@ -34,6 +34,7 @@
#include "mongo/db/s/config/initial_split_policy.h"
#include "mongo/client/read_preference.h"
+#include "mongo/db/bson/dotted_path_support.h"
#include "mongo/db/catalog/collection_catalog.h"
#include "mongo/db/curop.h"
#include "mongo/db/pipeline/lite_parsed_pipeline.h"
@@ -833,7 +834,10 @@ void ReshardingSplitPolicy::_appendSplitPointsFromSample(BSONObjSet* splitPoints
auto nextKey = _samples->getNext();
while (nextKey && nRemaining > 0) {
- auto result = splitPoints->insert(shardKey.extractShardKeyFromDoc(*nextKey));
+ // if key is hashed, nextKey values are already hashed
+ auto result = splitPoints->insert(
+ dotted_path_support::extractElementsBasedOnTemplate(*nextKey, shardKey.toBSON())
+ .getOwned());
if (result.second) {
nRemaining--;
diff --git a/src/mongo/db/s/config/initial_split_policy_test.cpp b/src/mongo/db/s/config/initial_split_policy_test.cpp
index fcc1e9eec9b..f47e34d2562 100644
--- a/src/mongo/db/s/config/initial_split_policy_test.cpp
+++ b/src/mongo/db/s/config/initial_split_policy_test.cpp
@@ -1864,9 +1864,9 @@ TEST_F(ReshardingInitSplitTest, HashedShardKey) {
shardRegistry()->reload(operationContext());
std::list<BSONObj> mockSamples;
- mockSamples.push_back(BSON("x" << 10 << "y" << 10));
- mockSamples.push_back(BSON("x" << 10 << "y" << 20));
- mockSamples.push_back(BSON("x" << 10 << "y" << 30));
+ mockSamples.push_back(BSON("x" << 10 << "y" << 7766103514953448109LL));
+ mockSamples.push_back(BSON("x" << 10 << "y" << -9117533237618642180LL));
+ mockSamples.push_back(BSON("x" << 10 << "y" << -1196399207910989725LL));
auto mockSampleSource = std::make_unique<MockPipelineSource>(std::move(mockSamples));