summaryrefslogtreecommitdiff
path: root/src/mongo/db/catalog/index_consistency.cpp
diff options
context:
space:
mode:
authorJames Wahlin <james@mongodb.com>2018-09-14 08:37:06 -0400
committerJames Wahlin <james@mongodb.com>2018-09-19 18:50:31 -0400
commitde786cd0b6253192bd202b7da8c514a3fc01cd78 (patch)
tree81f24e7f29bfd898e7fb947ef2e28a9f8f2e4dfd /src/mongo/db/catalog/index_consistency.cpp
parent480c3195536d7485ee543d46ab3a532531da1927 (diff)
downloadmongo-de786cd0b6253192bd202b7da8c514a3fc01cd78.tar.gz
SERVER-36444 Validate support for $** multikey metadata path index keys
Additionally, don't fail validation on encountering multiple index entries for a single RecordId for non-multikey $** indexes.
Diffstat (limited to 'src/mongo/db/catalog/index_consistency.cpp')
-rw-r--r--src/mongo/db/catalog/index_consistency.cpp54
1 files changed, 20 insertions, 34 deletions
diff --git a/src/mongo/db/catalog/index_consistency.cpp b/src/mongo/db/catalog/index_consistency.cpp
index 211f10dd9a8..8f499ceb386 100644
--- a/src/mongo/db/catalog/index_consistency.cpp
+++ b/src/mongo/db/catalog/index_consistency.cpp
@@ -114,34 +114,44 @@ void IndexConsistency::addDocKey(const KeyString& ks, int indexNumber) {
_addDocKey_inlock(ks, indexNumber);
}
-void IndexConsistency::removeDocKey(const KeyString& ks, int indexNumber) {
+void IndexConsistency::addIndexKey(const KeyString& ks, int indexNumber) {
if (indexNumber < 0 || indexNumber >= static_cast<int>(_indexesInfo.size())) {
return;
}
stdx::lock_guard<stdx::mutex> lock(_classMutex);
- _removeDocKey_inlock(ks, indexNumber);
+ _addIndexKey_inlock(ks, indexNumber);
}
-void IndexConsistency::addIndexKey(const KeyString& ks, int indexNumber) {
-
- if (indexNumber < 0 || indexNumber >= static_cast<int>(_indexesInfo.size())) {
+void IndexConsistency::addMultikeyMetadataPath(const KeyString& ks, int indexNumber) {
+ if (indexNumber < 0) {
return;
}
+ invariant(static_cast<size_t>(indexNumber) < _indexesInfo.size());
stdx::lock_guard<stdx::mutex> lock(_classMutex);
- _addIndexKey_inlock(ks, indexNumber);
+ _indexesInfo[indexNumber].hashedMultikeyMetadataPaths.emplace(_hashKeyString(ks, indexNumber));
}
-void IndexConsistency::removeIndexKey(const KeyString& ks, int indexNumber) {
-
- if (indexNumber < 0 || indexNumber >= static_cast<int>(_indexesInfo.size())) {
+void IndexConsistency::removeMultikeyMetadataPath(const KeyString& ks, int indexNumber) {
+ if (indexNumber < 0) {
return;
}
+ invariant(static_cast<size_t>(indexNumber) < _indexesInfo.size());
stdx::lock_guard<stdx::mutex> lock(_classMutex);
- _removeIndexKey_inlock(ks, indexNumber);
+ _indexesInfo[indexNumber].hashedMultikeyMetadataPaths.erase(_hashKeyString(ks, indexNumber));
+}
+
+size_t IndexConsistency::getMultikeyMetadataPathCount(int indexNumber) {
+ if (indexNumber < 0) {
+ return 0;
+ }
+ invariant(static_cast<size_t>(indexNumber) < _indexesInfo.size());
+
+ stdx::lock_guard<stdx::mutex> lock(_classMutex);
+ return _indexesInfo[indexNumber].hashedMultikeyMetadataPaths.size();
}
void IndexConsistency::addLongIndexKey(int indexNumber) {
@@ -245,18 +255,6 @@ void IndexConsistency::_addDocKey_inlock(const KeyString& ks, int indexNumber) {
_indexesInfo.at(indexNumber).numRecords++;
}
-void IndexConsistency::_removeDocKey_inlock(const KeyString& ks, int indexNumber) {
-
- // Ignore indexes that weren't ready before we started validation.
- if (!_indexesInfo.at(indexNumber).isReady) {
- return;
- }
-
- const uint32_t hash = _hashKeyString(ks, indexNumber);
- _indexKeyCount[hash]--;
- _indexesInfo.at(indexNumber).numRecords--;
-}
-
void IndexConsistency::_addIndexKey_inlock(const KeyString& ks, int indexNumber) {
// Ignore indexes that weren't ready before we started validation.
@@ -269,18 +267,6 @@ void IndexConsistency::_addIndexKey_inlock(const KeyString& ks, int indexNumber)
_indexesInfo.at(indexNumber).numKeys++;
}
-void IndexConsistency::_removeIndexKey_inlock(const KeyString& ks, int indexNumber) {
-
- // Ignore indexes that weren't ready before we started validation.
- if (!_indexesInfo.at(indexNumber).isReady) {
- return;
- }
-
- const uint32_t hash = _hashKeyString(ks, indexNumber);
- _indexKeyCount[hash]++;
- _indexesInfo.at(indexNumber).numKeys--;
-}
-
uint32_t IndexConsistency::_hashKeyString(const KeyString& ks, int indexNumber) const {
uint32_t indexNsHash = _indexesInfo.at(indexNumber).indexNsHash;