diff options
| author | Randolph Tan <randolph@10gen.com> | 2014-07-07 16:04:56 -0400 |
|---|---|---|
| committer | Randolph Tan <randolph@10gen.com> | 2014-07-23 16:25:23 -0400 |
| commit | 0e8a436fdedc9a56ddd4e773d45d7963a8f358a6 (patch) | |
| tree | b50e5a3a32d58c358f0baf83b534326f49ee9b75 /src/mongo/s/shard_key_pattern.cpp | |
| parent | eda239c6d3caeb6f68189672cf331e80bbc7faae (diff) | |
| download | mongo-0e8a436fdedc9a56ddd4e773d45d7963a8f358a6.tar.gz | |
SERVER-14431 Invalid chunk data after splitting on a key that's too large to index
Diffstat (limited to 'src/mongo/s/shard_key_pattern.cpp')
| -rw-r--r-- | src/mongo/s/shard_key_pattern.cpp | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/src/mongo/s/shard_key_pattern.cpp b/src/mongo/s/shard_key_pattern.cpp index 5b052898af7..b60f16ab603 100644 --- a/src/mongo/s/shard_key_pattern.cpp +++ b/src/mongo/s/shard_key_pattern.cpp @@ -28,10 +28,13 @@ #include "mongo/s/shard_key_pattern.h" +#include "mongo/db/keypattern.h" +#include "mongo/util/mongoutils/str.h" + namespace mongo { - bool isUniqueIndexCompatible( const BSONObj shardKeyPattern, - const BSONObj uIndexKeyPattern ) { + bool isUniqueIndexCompatible(const BSONObj& shardKeyPattern, + const BSONObj& uIndexKeyPattern) { if ( !uIndexKeyPattern.isEmpty() && string( "_id" ) == uIndexKeyPattern.firstElementFieldName() ) { @@ -40,4 +43,22 @@ namespace mongo { return shardKeyPattern.isFieldNamePrefixOf( uIndexKeyPattern ); } + + bool isShardDocSizeValid(const BSONObj& shardKey, const BSONObj& doc, string* errMsg) { + string dummy; + if (errMsg == NULL) { + errMsg = &dummy; + } + + const KeyPattern shardKeyPattern(shardKey); + BSONObj key = shardKeyPattern.extractSingleKey(doc); + + if (key.objsize() > kMaxShardKeySize) { + *errMsg = str::stream() << "key is larger than " << kMaxShardKeySize + << " bytes: " << key.objsize(); + return false; + } + + return true; + } } |
