diff options
author | Spencer T Brody <spencer@mongodb.com> | 2015-09-30 14:32:46 -0400 |
---|---|---|
committer | Spencer T Brody <spencer@mongodb.com> | 2015-10-07 12:50:51 -0400 |
commit | 0cf1be838e229b4385ac4313e994040a230857e5 (patch) | |
tree | 5236f89d7410122cee8a99a7ee232554203673f6 | |
parent | 60b2e7ffce5f91093d39c6d80701aa3f7c36b5c3 (diff) | |
download | mongo-0cf1be838e229b4385ac4313e994040a230857e5.tar.gz |
SERVER-20700 Sort split keys returned by splitVector
-rw-r--r-- | src/mongo/db/s/collection_metadata.cpp | 16 | ||||
-rw-r--r-- | src/mongo/s/d_split.cpp | 5 |
2 files changed, 20 insertions, 1 deletions
diff --git a/src/mongo/db/s/collection_metadata.cpp b/src/mongo/db/s/collection_metadata.cpp index b8c9cfa7b7a..d0bb88be073 100644 --- a/src/mongo/db/s/collection_metadata.cpp +++ b/src/mongo/db/s/collection_metadata.cpp @@ -323,7 +323,21 @@ CollectionMetadata* CollectionMetadata::cloneSplit(const ChunkType& chunk, BSONObj startKey = chunk.getMin(); for (vector<BSONObj>::const_iterator it = splitKeys.begin(); it != splitKeys.end(); ++it) { BSONObj split = *it; - invariant(split.woCompare(startKey) > 0); + if (split.woCompare(startKey) <= 0) { + // The split keys came in out of order, this probably indicates a bug, so fail the + // operation. Re-iterate splitKeys to build a useful error message including the + // array of splitKeys in the order received. + std::stringstream ss; + ss << "Invalid input to splitChunk, split keys must be in order, got: ["; + for (auto it2 = splitKeys.cbegin(); it2 != splitKeys.cend(); ++it2) { + if (it2 != splitKeys.begin()) { + ss << ", "; + } + ss << it2->toString(); + } + ss << "]"; + uasserted(28821, ss.str()); + } metadata->_chunksMap[startKey] = split.getOwned(); metadata->_chunksMap.insert(make_pair(split.getOwned(), chunk.getMax().getOwned())); metadata->_shardVersion.incMinor(); diff --git a/src/mongo/s/d_split.cpp b/src/mongo/s/d_split.cpp index 16eec736bfa..0a7c367b2ca 100644 --- a/src/mongo/s/d_split.cpp +++ b/src/mongo/s/d_split.cpp @@ -30,6 +30,7 @@ #include "mongo/platform/basic.h" +#include <algorithm> #include <map> #include <string> #include <vector> @@ -508,6 +509,10 @@ public: result.append("timeMillis", timer.millis()); } + // Make sure splitKeys is in ascending order + std::sort(splitKeys.begin(), + splitKeys.end(), + [](const BSONObj& lhs, const BSONObj& rhs) -> bool { return lhs < rhs; }); result.append("splitKeys", splitKeys); return true; } |