diff options
author | Andrew Morrow <acm@10gen.com> | 2013-10-11 10:11:08 -0400 |
---|---|---|
committer | Andrew Morrow <acm@10gen.com> | 2013-10-11 12:34:47 -0400 |
commit | bfead9163f1cd1ca06d7c358a93fedbe48e9f512 (patch) | |
tree | ae4f566cfabd4584df5918de87c4d047738bee81 /src/mongo/db/field_ref_set.cpp | |
parent | f3e324f10697bd4f0c9bdebced4a1e69d91cdd89 (diff) | |
download | mongo-bfead9163f1cd1ca06d7c358a93fedbe48e9f512.tar.gz |
SERVER-7379 Prohibit shard key mutation in updates
Diffstat (limited to 'src/mongo/db/field_ref_set.cpp')
-rw-r--r-- | src/mongo/db/field_ref_set.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/mongo/db/field_ref_set.cpp b/src/mongo/db/field_ref_set.cpp index 65e81344300..c1a3c79cff5 100644 --- a/src/mongo/db/field_ref_set.cpp +++ b/src/mongo/db/field_ref_set.cpp @@ -56,6 +56,28 @@ namespace mongo { FieldRefSet::FieldRefSet() { } + void FieldRefSet::getConflicts(const FieldRef* toCheck, FieldRefSet* conflicts) const { + + // If the set is empty, there is no work to do. + if (_fieldSet.empty()) + return; + + StringData prefixStr = safeFirstPart(toCheck); + FieldRef prefixField; + prefixField.parse(prefixStr); + + FieldSet::iterator it = _fieldSet.lower_bound(&prefixField); + // Now, iterate over all the present fields in the set that have the same prefix. + + while (it != _fieldSet.end() && safeFirstPart(*it) == prefixStr) { + size_t common = (*it)->commonPrefixSize(*toCheck); + if ((*it)->numParts() == common || toCheck->numParts() == common) { + conflicts->_fieldSet.insert(*it); + } + ++it; + } + } + bool FieldRefSet::insert(const FieldRef* toInsert, const FieldRef** conflict) { // We can determine if two fields conflict by checking their common prefix. |