From bf7adca3bd56959f320eccb610668fe21c196243 Mon Sep 17 00:00:00 2001 From: Pierlauro Sciarelli Date: Tue, 14 Dec 2021 13:08:43 +0000 Subject: SERVER-58750 get rid of unnecessary sorting of split keys --- src/mongo/db/s/auto_split_vector.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'src/mongo/db/s/auto_split_vector.cpp') diff --git a/src/mongo/db/s/auto_split_vector.cpp b/src/mongo/db/s/auto_split_vector.cpp index 5b964007714..062fb26cef8 100644 --- a/src/mongo/db/s/auto_split_vector.cpp +++ b/src/mongo/db/s/auto_split_vector.cpp @@ -240,7 +240,11 @@ std::vector autoSplitVector(OperationContext* opCtx, if (++numScannedKeys >= maxDocsPerChunk) { currentKey = orderShardKeyFields(keyPattern, currentKey); - if (currentKey.woCompare(lastSplitPoint) == 0) { + const auto compareWithPreviousSplitPoint = currentKey.woCompare(lastSplitPoint); + dassert(compareWithPreviousSplitPoint >= 0, + str::stream() << "Found split key smaller then the last one: " << currentKey + << " < " << lastSplitPoint); + if (compareWithPreviousSplitPoint == 0) { // Do not add again the same split point in case of frequent shard key. tooFrequentKeys.insert(currentKey.getOwned()); continue; @@ -310,6 +314,10 @@ std::vector autoSplitVector(OperationContext* opCtx, const auto compareWithPreviousSplitPoint = currentKey.woCompare(previousSplitPoint); + + dassert(compareWithPreviousSplitPoint >= 0, + str::stream() << "Found split key smaller then the previous one: " + << currentKey << " < " << previousSplitPoint); if (compareWithPreviousSplitPoint > 0) { const auto additionalKeySize = currentKey.objsize() + estimatedAdditionalBytesPerItemInBSONArray; @@ -362,11 +370,6 @@ std::vector autoSplitVector(OperationContext* opCtx, "duration"_attr = Milliseconds(elapsedMillisToFindSplitPoints)); } - // TODO SERVER-58750: investigate if it is really needed to sort the vector - // Make sure splitKeys is in ascending order - std::sort( - splitKeys.begin(), splitKeys.end(), SimpleBSONObjComparator::kInstance.makeLessThan()); - return splitKeys; } -- cgit v1.2.1