summaryrefslogtreecommitdiff
path: root/src/mongo/db
diff options
context:
space:
mode:
authorLouis Williams <louis.williams@mongodb.com>2018-11-12 12:04:25 -0500
committerLouis Williams <louis.williams@mongodb.com>2018-12-19 19:22:55 -0500
commit145078f2e5076fb4a032d36d30b7c71b33706802 (patch)
treed1909714d54286ae78ed17d404413d630b1633b1 /src/mongo/db
parent51ab5eb0c500d0013ac6265de40ab7dbc3d52131 (diff)
downloadmongo-145078f2e5076fb4a032d36d30b7c71b33706802.tar.gz
SERVER-38091 IndexCatalog iterators and accessors should return const entries
Diffstat (limited to 'src/mongo/db')
-rw-r--r--src/mongo/db/catalog/coll_mod.cpp2
-rw-r--r--src/mongo/db/catalog/collection_compact.cpp19
-rw-r--r--src/mongo/db/catalog/collection_impl.cpp18
-rw-r--r--src/mongo/db/catalog/collection_info_cache_impl.cpp9
-rw-r--r--src/mongo/db/catalog/database_impl.cpp2
-rw-r--r--src/mongo/db/catalog/drop_indexes.cpp4
-rw-r--r--src/mongo/db/catalog/index_catalog.cpp6
-rw-r--r--src/mongo/db/catalog/index_catalog.h62
-rw-r--r--src/mongo/db/catalog/index_catalog_impl.cpp87
-rw-r--r--src/mongo/db/catalog/index_catalog_impl.h32
-rw-r--r--src/mongo/db/catalog/index_catalog_noop.h29
-rw-r--r--src/mongo/db/catalog/private/record_store_validate_adaptor.cpp4
-rw-r--r--src/mongo/db/catalog/private/record_store_validate_adaptor.h4
-rw-r--r--src/mongo/db/catalog/rename_collection.cpp2
-rw-r--r--src/mongo/db/commands/dbcommands.cpp2
-rw-r--r--src/mongo/db/commands/dbhash.cpp2
-rw-r--r--src/mongo/db/commands/haystack.cpp8
-rw-r--r--src/mongo/db/commands/mr.cpp4
-rw-r--r--src/mongo/db/dbhelpers.cpp4
-rw-r--r--src/mongo/db/exec/stagedebug_cmd.cpp13
-rw-r--r--src/mongo/db/index/haystack_access_method.cpp2
-rw-r--r--src/mongo/db/index/haystack_access_method.h2
-rw-r--r--src/mongo/db/index/index_access_method.cpp2
-rw-r--r--src/mongo/db/index/index_access_method.h6
-rw-r--r--src/mongo/db/matcher/expression_text.cpp8
-rw-r--r--src/mongo/db/pipeline/pipeline_d.cpp2
-rw-r--r--src/mongo/db/pipeline/process_interface_standalone.cpp2
-rw-r--r--src/mongo/db/query/get_executor.cpp6
-rw-r--r--src/mongo/db/query/stage_builder.cpp10
-rw-r--r--src/mongo/db/repl/dbcheck.cpp2
-rw-r--r--src/mongo/db/repl/idempotency_test_fixture.cpp2
-rw-r--r--src/mongo/db/repl/rs_rollback_test.cpp6
-rw-r--r--src/mongo/db/repl/storage_interface_impl.cpp4
-rw-r--r--src/mongo/db/repl/storage_interface_impl_test.cpp4
-rw-r--r--src/mongo/db/s/check_sharding_index_command.cpp2
-rw-r--r--src/mongo/db/s/collection_range_deleter.cpp3
-rw-r--r--src/mongo/db/s/migration_chunk_cloner_source_legacy.cpp2
-rw-r--r--src/mongo/db/s/split_chunk.cpp2
-rw-r--r--src/mongo/db/s/split_vector.cpp2
-rw-r--r--src/mongo/db/stats/storage_stats.cpp6
-rw-r--r--src/mongo/db/system_index.cpp4
-rw-r--r--src/mongo/db/transaction_participant.cpp2
-rw-r--r--src/mongo/db/ttl.cpp2
43 files changed, 210 insertions, 186 deletions
diff --git a/src/mongo/db/catalog/coll_mod.cpp b/src/mongo/db/catalog/coll_mod.cpp
index a874c594874..6a782ac4df7 100644
--- a/src/mongo/db/catalog/coll_mod.cpp
+++ b/src/mongo/db/catalog/coll_mod.cpp
@@ -147,7 +147,7 @@ StatusWith<CollModRequest> parseCollModRequest(OperationContext* opCtx,
<< nss.ns());
}
} else {
- std::vector<IndexDescriptor*> indexes;
+ std::vector<const IndexDescriptor*> indexes;
coll->getIndexCatalog()->findIndexesByKeyPattern(
opCtx, keyPattern, false, &indexes);
diff --git a/src/mongo/db/catalog/collection_compact.cpp b/src/mongo/db/catalog/collection_compact.cpp
index a7d13797fea..6170ac334d1 100644
--- a/src/mongo/db/catalog/collection_compact.cpp
+++ b/src/mongo/db/catalog/collection_compact.cpp
@@ -66,20 +66,9 @@ StatusWith<CompactStats> compactCollection(OperationContext* opCtx,
return StatusWith<CompactStats>(status);
// Compact all indexes (not including unfinished indexes)
- std::unique_ptr<IndexCatalog::IndexIterator> ii(
- indexCatalog->getIndexIterator(opCtx, false));
- while (ii->more()) {
- IndexCatalogEntry* entry = ii->next();
- IndexDescriptor* descriptor = entry->descriptor();
- IndexAccessMethod* iam = entry->accessMethod();
-
- LOG(1) << "compacting index: " << descriptor->toString();
- Status status = iam->compact(opCtx);
- if (!status.isOK()) {
- error() << "failed to compact index: " << descriptor->toString();
- return status;
- }
- }
+ status = indexCatalog->compactIndexes(opCtx);
+ if (!status.isOK())
+ return StatusWith<CompactStats>(status);
return StatusWith<CompactStats>(stats);
}
@@ -93,7 +82,7 @@ StatusWith<CompactStats> compactCollection(OperationContext* opCtx,
std::unique_ptr<IndexCatalog::IndexIterator> ii(
indexCatalog->getIndexIterator(opCtx, false));
while (ii->more()) {
- IndexDescriptor* descriptor = ii->next()->descriptor();
+ const IndexDescriptor* descriptor = ii->next()->descriptor();
// Compact always creates the new index in the foreground.
const BSONObj spec =
diff --git a/src/mongo/db/catalog/collection_impl.cpp b/src/mongo/db/catalog/collection_impl.cpp
index 377fb669bd0..79503488959 100644
--- a/src/mongo/db/catalog/collection_impl.cpp
+++ b/src/mongo/db/catalog/collection_impl.cpp
@@ -757,9 +757,9 @@ uint64_t CollectionImpl::getIndexSize(OperationContext* opCtx, BSONObjBuilder* d
uint64_t totalSize = 0;
while (ii->more()) {
- IndexCatalogEntry* entry = ii->next();
- IndexDescriptor* descriptor = entry->descriptor();
- IndexAccessMethod* iam = entry->accessMethod();
+ const IndexCatalogEntry* entry = ii->next();
+ const IndexDescriptor* descriptor = entry->descriptor();
+ const IndexAccessMethod* iam = entry->accessMethod();
long long ds = iam->getSpaceUsedBytes(opCtx);
@@ -996,9 +996,9 @@ void _validateIndexes(OperationContext* opCtx,
// Validate Indexes.
while (it->more()) {
opCtx->checkForInterrupt();
- IndexCatalogEntry* entry = it->next();
- IndexDescriptor* descriptor = entry->descriptor();
- IndexAccessMethod* iam = entry->accessMethod();
+ const IndexCatalogEntry* entry = it->next();
+ const IndexDescriptor* descriptor = entry->descriptor();
+ const IndexAccessMethod* iam = entry->accessMethod();
log(LogComponent::kIndex) << "validating index " << descriptor->indexNamespace() << endl;
ValidateResults& curIndexResults = (*indexNsResultsMap)[descriptor->indexNamespace()];
@@ -1060,7 +1060,7 @@ void _validateIndexKeyCount(OperationContext* opCtx,
std::unique_ptr<IndexCatalog::IndexIterator> indexIterator =
indexCatalog->getIndexIterator(opCtx, false);
while (indexIterator->more()) {
- IndexDescriptor* descriptor = indexIterator->next()->descriptor();
+ const IndexDescriptor* descriptor = indexIterator->next()->descriptor();
ValidateResults& curIndexResults = (*indexNsResultsMap)[descriptor->indexNamespace()];
if (curIndexResults.valid) {
@@ -1253,8 +1253,8 @@ Status CollectionImpl::touch(OperationContext* opCtx,
std::unique_ptr<IndexCatalog::IndexIterator> ii =
_indexCatalog->getIndexIterator(opCtx, false);
while (ii->more()) {
- IndexCatalogEntry* entry = ii->next();
- IndexAccessMethod* iam = entry->accessMethod();
+ const IndexCatalogEntry* entry = ii->next();
+ const IndexAccessMethod* iam = entry->accessMethod();
Status status = iam->touch(opCtx);
if (!status.isOK())
return status;
diff --git a/src/mongo/db/catalog/collection_info_cache_impl.cpp b/src/mongo/db/catalog/collection_info_cache_impl.cpp
index ecbca8a8509..0065fd0ad01 100644
--- a/src/mongo/db/catalog/collection_info_cache_impl.cpp
+++ b/src/mongo/db/catalog/collection_info_cache_impl.cpp
@@ -84,13 +84,14 @@ void CollectionInfoCacheImpl::computeIndexKeys(OperationContext* opCtx) {
std::unique_ptr<IndexCatalog::IndexIterator> it =
_collection->getIndexCatalog()->getIndexIterator(opCtx, true);
while (it->more()) {
- IndexCatalogEntry* entry = it->next();
- IndexDescriptor* descriptor = entry->descriptor();
- IndexAccessMethod* iam = entry->accessMethod();
+ const IndexCatalogEntry* entry = it->next();
+ const IndexDescriptor* descriptor = entry->descriptor();
+ const IndexAccessMethod* iam = entry->accessMethod();
if (descriptor->getAccessMethodName() == IndexNames::WILDCARD) {
// Obtain the projection used by the $** index's key generator.
- const auto* pathProj = static_cast<WildcardAccessMethod*>(iam)->getProjectionExec();
+ const auto* pathProj =
+ static_cast<const WildcardAccessMethod*>(iam)->getProjectionExec();
// If the projection is an exclusion, then we must check the new document's keys on all
// updates, since we do not exhaustively know the set of paths to be indexed.
if (pathProj->getType() == ProjectionExecAgg::ProjectionType::kExclusionProjection) {
diff --git a/src/mongo/db/catalog/database_impl.cpp b/src/mongo/db/catalog/database_impl.cpp
index 70e14b77e18..1eaa1b2934c 100644
--- a/src/mongo/db/catalog/database_impl.cpp
+++ b/src/mongo/db/catalog/database_impl.cpp
@@ -572,7 +572,7 @@ Status DatabaseImpl::dropCollectionEvenIfSystem(OperationContext* opCtx,
// rename. In the case that this collection drop gets rolled back, this will incur a
// performance hit, since those indexes will have to be rebuilt from scratch, but data
// integrity is maintained.
- std::vector<IndexDescriptor*> indexesToDrop;
+ std::vector<const IndexDescriptor*> indexesToDrop;
auto indexIter = collection->getIndexCatalog()->getIndexIterator(opCtx, true);
// Determine which index names are too long. Since we don't have the collection drop optime
diff --git a/src/mongo/db/catalog/drop_indexes.cpp b/src/mongo/db/catalog/drop_indexes.cpp
index 2c25819720b..34f3875155c 100644
--- a/src/mongo/db/catalog/drop_indexes.cpp
+++ b/src/mongo/db/catalog/drop_indexes.cpp
@@ -116,7 +116,7 @@ Status wrappedRun(OperationContext* opCtx,
}
if (indexElem.type() == Object) {
- std::vector<IndexDescriptor*> indexes;
+ std::vector<const IndexDescriptor*> indexes;
collection->getIndexCatalog()->findIndexesByKeyPattern(
opCtx, indexElem.embeddedObject(), false, &indexes);
if (indexes.empty()) {
@@ -134,7 +134,7 @@ Status wrappedRun(OperationContext* opCtx,
<< indexes[1]->infoObj());
}
- IndexDescriptor* desc = indexes[0];
+ const IndexDescriptor* desc = indexes[0];
if (desc->isIdIndex()) {
return Status(ErrorCodes::InvalidOptions, "cannot drop _id index");
}
diff --git a/src/mongo/db/catalog/index_catalog.cpp b/src/mongo/db/catalog/index_catalog.cpp
index 7f68b7ef77c..5dc19d473a2 100644
--- a/src/mongo/db/catalog/index_catalog.cpp
+++ b/src/mongo/db/catalog/index_catalog.cpp
@@ -49,7 +49,7 @@ bool IndexIterator::more() {
return _next != nullptr;
}
-IndexCatalogEntry* IndexIterator::next() {
+const IndexCatalogEntry* IndexIterator::next() {
if (!more())
return nullptr;
_prev = _next;
@@ -62,7 +62,7 @@ ReadyIndexesIterator::ReadyIndexesIterator(OperationContext* const opCtx,
IndexCatalogEntryContainer::const_iterator endIterator)
: _opCtx(opCtx), _iterator(beginIterator), _endIterator(endIterator) {}
-IndexCatalogEntry* ReadyIndexesIterator::_advance() {
+const IndexCatalogEntry* ReadyIndexesIterator::_advance() {
while (_iterator != _endIterator) {
IndexCatalogEntry* entry = _iterator->get();
++_iterator;
@@ -90,7 +90,7 @@ AllIndexesIterator::AllIndexesIterator(
_endIterator = _ownedContainer->end();
}
-IndexCatalogEntry* AllIndexesIterator::_advance() {
+const IndexCatalogEntry* AllIndexesIterator::_advance() {
if (_iterator == _endIterator) {
return nullptr;
}
diff --git a/src/mongo/db/catalog/index_catalog.h b/src/mongo/db/catalog/index_catalog.h
index 9d5faf431b8..32fe911962c 100644
--- a/src/mongo/db/catalog/index_catalog.h
+++ b/src/mongo/db/catalog/index_catalog.h
@@ -47,7 +47,6 @@ class Client;
class Collection;
class IndexDescriptor;
-class IndexAccessMethod;
struct InsertDeleteOptions;
struct BsonRecord {
@@ -80,19 +79,19 @@ public:
public:
virtual ~IndexIterator() = default;
bool more();
- IndexCatalogEntry* next();
+ const IndexCatalogEntry* next();
protected:
/**
* Advance the underlying iterator and returns the next index entry. Returns nullptr when
* the iterator is exhausted.
*/
- virtual IndexCatalogEntry* _advance() = 0;
+ virtual const IndexCatalogEntry* _advance() = 0;
private:
bool _start = true;
- IndexCatalogEntry* _prev = nullptr;
- IndexCatalogEntry* _next = nullptr;
+ const IndexCatalogEntry* _prev = nullptr;
+ const IndexCatalogEntry* _next = nullptr;
};
class ReadyIndexesIterator : public IndexIterator {
@@ -102,7 +101,7 @@ public:
IndexCatalogEntryContainer::const_iterator endIterator);
private:
- IndexCatalogEntry* _advance() override;
+ const IndexCatalogEntry* _advance() override;
OperationContext* const _opCtx;
IndexCatalogEntryContainer::const_iterator _iterator;
@@ -120,7 +119,7 @@ public:
std::unique_ptr<std::vector<IndexCatalogEntry*>> ownedContainer);
private:
- IndexCatalogEntry* _advance() override;
+ const IndexCatalogEntry* _advance() override;
OperationContext* const _opCtx;
std::vector<IndexCatalogEntry*>::const_iterator _iterator;
@@ -205,16 +204,17 @@ public:
*/
virtual BSONObj getDefaultIdIndexSpec() const = 0;
- virtual IndexDescriptor* findIdIndex(OperationContext* const opCtx) const = 0;
+ virtual const IndexDescriptor* findIdIndex(OperationContext* const opCtx) const = 0;
/**
* Find index by name. The index name uniquely identifies an index.
*
* @return null if cannot find
*/
- virtual IndexDescriptor* findIndexByName(OperationContext* const opCtx,
- const StringData name,
- const bool includeUnfinishedIndexes = false) const = 0;
+ virtual const IndexDescriptor* findIndexByName(
+ OperationContext* const opCtx,
+ const StringData name,
+ const bool includeUnfinishedIndexes = false) const = 0;
/**
* Find index by matching key pattern and collation spec. The key pattern and collation spec
@@ -226,7 +226,7 @@ public:
* @return null if cannot find index, otherwise the index with a matching key pattern and
* collation.
*/
- virtual IndexDescriptor* findIndexByKeyPatternAndCollationSpec(
+ virtual const IndexDescriptor* findIndexByKeyPatternAndCollationSpec(
OperationContext* const opCtx,
const BSONObj& key,
const BSONObj& collationSpec,
@@ -238,10 +238,11 @@ public:
*
* Consider using 'findIndexByName' if expecting to match one index.
*/
- virtual void findIndexesByKeyPattern(OperationContext* const opCtx,
- const BSONObj& key,
- const bool includeUnfinishedIndexes,
- std::vector<IndexDescriptor*>* const matches) const = 0;
+ virtual void findIndexesByKeyPattern(
+ OperationContext* const opCtx,
+ const BSONObj& key,
+ const bool includeUnfinishedIndexes,
+ std::vector<const IndexDescriptor*>* const matches) const = 0;
/**
* Returns an index suitable for shard key range scans.
@@ -256,13 +257,13 @@ public:
*
* If no such index exists, returns NULL.
*/
- virtual IndexDescriptor* findShardKeyPrefixedIndex(OperationContext* const opCtx,
- const BSONObj& shardKey,
- const bool requireSingleKey) const = 0;
+ virtual const IndexDescriptor* findShardKeyPrefixedIndex(OperationContext* const opCtx,
+ const BSONObj& shardKey,
+ const bool requireSingleKey) const = 0;
virtual void findIndexByType(OperationContext* const opCtx,
const std::string& type,
- std::vector<IndexDescriptor*>& matches,
+ std::vector<const IndexDescriptor*>& matches,
const bool includeUnfinishedIndexes = false) const = 0;
/**
@@ -298,10 +299,6 @@ public:
virtual std::vector<std::shared_ptr<const IndexCatalogEntry>> getAllReadyEntriesShared()
const = 0;
- virtual IndexAccessMethod* getIndex(const IndexDescriptor* const desc) = 0;
-
- virtual const IndexAccessMethod* getIndex(const IndexDescriptor* const desc) const = 0;
-
/**
* Returns a not-ok Status if there are any unfinished index builds. No new indexes should
* be built when in this state.
@@ -344,7 +341,7 @@ public:
stdx::function<void(const IndexDescriptor*)> onDropFn) = 0;
virtual void dropAllIndexes(OperationContext* opCtx, bool includingIdIndex) = 0;
- virtual Status dropIndex(OperationContext* const opCtx, IndexDescriptor* const desc) = 0;
+ virtual Status dropIndex(OperationContext* const opCtx, const IndexDescriptor* const desc) = 0;
/**
* Drops all incomplete indexes and returns specs. After this, the indexes can be rebuilt.
@@ -370,6 +367,15 @@ public:
virtual MultikeyPaths getMultikeyPaths(OperationContext* const opCtx,
const IndexDescriptor* const idx) = 0;
+ /**
+ * Sets the index 'desc' to be multikey with the provided 'multikeyPaths'.
+ *
+ * See IndexCatalogEntry::setMultikey().
+ */
+ virtual void setMultikeyPaths(OperationContext* const opCtx,
+ const IndexDescriptor* const desc,
+ const MultikeyPaths& multikeyPaths) = 0;
+
// ----- data modifiers ------
/**
@@ -405,6 +411,12 @@ public:
const bool noWarn,
int64_t* const keysDeletedOut) = 0;
+ /*
+ * Attempt compaction on all ready indexes to regain disk space, if the storage engine's index
+ * supports compaction in-place.
+ */
+ virtual Status compactIndexes(OperationContext* opCtx) = 0;
+
virtual std::string getAccessMethodName(const BSONObj& keyPattern) = 0;
/**
diff --git a/src/mongo/db/catalog/index_catalog_impl.cpp b/src/mongo/db/catalog/index_catalog_impl.cpp
index 2d656ba43df..610d199137d 100644
--- a/src/mongo/db/catalog/index_catalog_impl.cpp
+++ b/src/mongo/db/catalog/index_catalog_impl.cpp
@@ -701,7 +701,7 @@ Status IndexCatalogImpl::_doesSpecConflictWithExisting(OperationContext* opCtx,
// Collections should only have one text index.
string pluginName = IndexNames::findPluginName(key);
if (pluginName == IndexNames::TEXT) {
- vector<IndexDescriptor*> textIndexes;
+ vector<const IndexDescriptor*> textIndexes;
const bool includeUnfinishedIndexes = true;
findIndexByType(opCtx, IndexNames::TEXT, textIndexes, includeUnfinishedIndexes);
if (textIndexes.size() > 0) {
@@ -758,7 +758,7 @@ void IndexCatalogImpl::dropAllIndexes(OperationContext* opCtx,
std::unique_ptr<IndexIterator> ii = getIndexIterator(opCtx, true);
while (ii->more()) {
seen++;
- IndexDescriptor* desc = ii->next()->descriptor();
+ const IndexDescriptor* desc = ii->next()->descriptor();
if (desc->isIdIndex() && includingIdIndex == false) {
haveIdIndex = true;
continue;
@@ -770,7 +770,7 @@ void IndexCatalogImpl::dropAllIndexes(OperationContext* opCtx,
for (size_t i = 0; i < indexNamesToDrop.size(); i++) {
string indexName = indexNamesToDrop[i];
- IndexDescriptor* desc = findIndexByName(opCtx, indexName, true);
+ const IndexDescriptor* desc = findIndexByName(opCtx, indexName, true);
invariant(desc);
LOG(1) << "\t dropAllIndexes dropping: " << desc->toString();
IndexCatalogEntry* entry = _readyIndexes.find(desc);
@@ -813,7 +813,7 @@ void IndexCatalogImpl::dropAllIndexes(OperationContext* opCtx, bool includingIdI
dropAllIndexes(opCtx, includingIdIndex, {});
}
-Status IndexCatalogImpl::dropIndex(OperationContext* opCtx, IndexDescriptor* desc) {
+Status IndexCatalogImpl::dropIndex(OperationContext* opCtx, const IndexDescriptor* desc) {
invariant(opCtx->lockState()->isCollectionLockedForMode(_collection->ns().toString(), MODE_X));
BackgroundOperation::assertNoBgOpInProgForNs(_collection->ns().ns());
invariant(_buildingIndexes.size() == 0);
@@ -951,6 +951,17 @@ MultikeyPaths IndexCatalogImpl::getMultikeyPaths(OperationContext* opCtx,
return entry->getMultikeyPaths(opCtx);
}
+void IndexCatalogImpl::setMultikeyPaths(OperationContext* const opCtx,
+ const IndexDescriptor* desc,
+ const MultikeyPaths& multikeyPaths) {
+ IndexCatalogEntry* entry = _readyIndexes.find(desc);
+ if (!entry) {
+ entry = _buildingIndexes.find(desc);
+ }
+ invariant(entry);
+ entry->setMultikey(opCtx, multikeyPaths);
+};
+
// ---------------------------
bool IndexCatalogImpl::haveAnyIndexes() const {
@@ -964,7 +975,7 @@ int IndexCatalogImpl::numIndexesTotal(OperationContext* opCtx) const {
}
int IndexCatalogImpl::numIndexesReady(OperationContext* opCtx) const {
- std::vector<IndexDescriptor*> itIndexes;
+ std::vector<const IndexDescriptor*> itIndexes;
std::unique_ptr<IndexIterator> ii = getIndexIterator(opCtx, /*includeUnfinished*/ false);
while (ii->more()) {
itIndexes.push_back(ii->next()->descriptor());
@@ -977,7 +988,7 @@ int IndexCatalogImpl::numIndexesReady(OperationContext* opCtx) const {
// entry and the index catalog differ. Log as much information as possible here.
if (itIndexes.size() != completedIndexes.size()) {
log() << "index catalog reports: ";
- for (IndexDescriptor* i : itIndexes) {
+ for (const IndexDescriptor* i : itIndexes) {
log() << " index: " << i->toString();
}
@@ -998,36 +1009,36 @@ bool IndexCatalogImpl::haveIdIndex(OperationContext* opCtx) const {
return findIdIndex(opCtx) != nullptr;
}
-IndexDescriptor* IndexCatalogImpl::findIdIndex(OperationContext* opCtx) const {
+const IndexDescriptor* IndexCatalogImpl::findIdIndex(OperationContext* opCtx) const {
std::unique_ptr<IndexIterator> ii = getIndexIterator(opCtx, false);
while (ii->more()) {
- IndexDescriptor* desc = ii->next()->descriptor();
+ const IndexDescriptor* desc = ii->next()->descriptor();
if (desc->isIdIndex())
return desc;
}
return nullptr;
}
-IndexDescriptor* IndexCatalogImpl::findIndexByName(OperationContext* opCtx,
- StringData name,
- bool includeUnfinishedIndexes) const {
+const IndexDescriptor* IndexCatalogImpl::findIndexByName(OperationContext* opCtx,
+ StringData name,
+ bool includeUnfinishedIndexes) const {
std::unique_ptr<IndexIterator> ii = getIndexIterator(opCtx, includeUnfinishedIndexes);
while (ii->more()) {
- IndexDescriptor* desc = ii->next()->descriptor();
+ const IndexDescriptor* desc = ii->next()->descriptor();
if (desc->indexName() == name)
return desc;
}
return nullptr;
}
-IndexDescriptor* IndexCatalogImpl::findIndexByKeyPatternAndCollationSpec(
+const IndexDescriptor* IndexCatalogImpl::findIndexByKeyPatternAndCollationSpec(
OperationContext* opCtx,
const BSONObj& key,
const BSONObj& collationSpec,
bool includeUnfinishedIndexes) const {
std::unique_ptr<IndexIterator> ii = getIndexIterator(opCtx, includeUnfinishedIndexes);
while (ii->more()) {
- IndexDescriptor* desc = ii->next()->descriptor();
+ const IndexDescriptor* desc = ii->next()->descriptor();
if (SimpleBSONObjComparator::kInstance.evaluate(desc->keyPattern() == key) &&
SimpleBSONObjComparator::kInstance.evaluate(
desc->infoObj().getObjectField("collation") == collationSpec)) {
@@ -1040,25 +1051,25 @@ IndexDescriptor* IndexCatalogImpl::findIndexByKeyPatternAndCollationSpec(
void IndexCatalogImpl::findIndexesByKeyPattern(OperationContext* opCtx,
const BSONObj& key,
bool includeUnfinishedIndexes,
- std::vector<IndexDescriptor*>* matches) const {
+ std::vector<const IndexDescriptor*>* matches) const {
invariant(matches);
std::unique_ptr<IndexIterator> ii = getIndexIterator(opCtx, includeUnfinishedIndexes);
while (ii->more()) {
- IndexDescriptor* desc = ii->next()->descriptor();
+ const IndexDescriptor* desc = ii->next()->descriptor();
if (SimpleBSONObjComparator::kInstance.evaluate(desc->keyPattern() == key)) {
matches->push_back(desc);
}
}
}
-IndexDescriptor* IndexCatalogImpl::findShardKeyPrefixedIndex(OperationContext* opCtx,
- const BSONObj& shardKey,
- bool requireSingleKey) const {
- IndexDescriptor* best = nullptr;
+const IndexDescriptor* IndexCatalogImpl::findShardKeyPrefixedIndex(OperationContext* opCtx,
+ const BSONObj& shardKey,
+ bool requireSingleKey) const {
+ const IndexDescriptor* best = nullptr;
std::unique_ptr<IndexIterator> ii = getIndexIterator(opCtx, false);
while (ii->more()) {
- IndexDescriptor* desc = ii->next()->descriptor();
+ const IndexDescriptor* desc = ii->next()->descriptor();
bool hasSimpleCollation = desc->infoObj().getObjectField("collation").isEmpty();
if (desc->isPartial())
@@ -1079,31 +1090,17 @@ IndexDescriptor* IndexCatalogImpl::findShardKeyPrefixedIndex(OperationContext* o
void IndexCatalogImpl::findIndexByType(OperationContext* opCtx,
const string& type,
- vector<IndexDescriptor*>& matches,
+ vector<const IndexDescriptor*>& matches,
bool includeUnfinishedIndexes) const {
std::unique_ptr<IndexIterator> ii = getIndexIterator(opCtx, includeUnfinishedIndexes);
while (ii->more()) {
- IndexDescriptor* desc = ii->next()->descriptor();
+ const IndexDescriptor* desc = ii->next()->descriptor();
if (IndexNames::findPluginName(desc->keyPattern()) == type) {
matches.push_back(desc);
}
}
}
-IndexAccessMethod* IndexCatalogImpl::getIndex(const IndexDescriptor* desc) {
- IndexCatalogEntry* entry = _readyIndexes.find(desc);
- if (!entry) {
- entry = _buildingIndexes.find(desc);
- }
-
- massert(17334, "cannot find index entry", entry);
- return entry->accessMethod();
-}
-
-const IndexAccessMethod* IndexCatalogImpl::getIndex(const IndexDescriptor* desc) const {
- return getEntry(desc)->accessMethod();
-}
-
const IndexCatalogEntry* IndexCatalogImpl::getEntry(const IndexDescriptor* desc) const {
const IndexCatalogEntry* entry = _readyIndexes.find(desc);
if (!entry) {
@@ -1382,6 +1379,22 @@ void IndexCatalogImpl::unindexRecord(OperationContext* opCtx,
}
}
+Status IndexCatalogImpl::compactIndexes(OperationContext* opCtx) {
+ for (IndexCatalogEntryContainer::const_iterator it = _readyIndexes.begin();
+ it != _readyIndexes.end();
+ ++it) {
+ IndexCatalogEntry* entry = it->get();
+
+ LOG(1) << "compacting index: " << entry->descriptor()->toString();
+ Status status = entry->accessMethod()->compact(opCtx);
+ if (!status.isOK()) {
+ error() << "failed to compact index: " << entry->descriptor()->toString();
+ return status;
+ }
+ }
+ return Status::OK();
+}
+
std::unique_ptr<IndexCatalog::IndexBuildBlockInterface> IndexCatalogImpl::createIndexBuildBlock(
OperationContext* opCtx, const BSONObj& spec) {
return std::make_unique<IndexBuildBlock>(opCtx, _collection, this, spec);
diff --git a/src/mongo/db/catalog/index_catalog_impl.h b/src/mongo/db/catalog/index_catalog_impl.h
index 5bd37d309f8..b07097957d2 100644
--- a/src/mongo/db/catalog/index_catalog_impl.h
+++ b/src/mongo/db/catalog/index_catalog_impl.h
@@ -49,7 +49,6 @@ class Client;
class Collection;
class IndexDescriptor;
-class IndexAccessMethod;
struct InsertDeleteOptions;
/**
@@ -87,16 +86,16 @@ public:
*/
BSONObj getDefaultIdIndexSpec() const override;
- IndexDescriptor* findIdIndex(OperationContext* opCtx) const override;
+ const IndexDescriptor* findIdIndex(OperationContext* opCtx) const override;
/**
* Find index by name. The index name uniquely identifies an index.
*
* @return null if cannot find
*/
- IndexDescriptor* findIndexByName(OperationContext* opCtx,
- StringData name,
- bool includeUnfinishedIndexes = false) const override;
+ const IndexDescriptor* findIndexByName(OperationContext* opCtx,
+ StringData name,
+ bool includeUnfinishedIndexes = false) const override;
/**
* Find index by matching key pattern and collation spec. The key pattern and collation spec
@@ -108,7 +107,7 @@ public:
* @return null if cannot find index, otherwise the index with a matching key pattern and
* collation.
*/
- IndexDescriptor* findIndexByKeyPatternAndCollationSpec(
+ const IndexDescriptor* findIndexByKeyPatternAndCollationSpec(
OperationContext* opCtx,
const BSONObj& key,
const BSONObj& collationSpec,
@@ -123,7 +122,7 @@ public:
void findIndexesByKeyPattern(OperationContext* opCtx,
const BSONObj& key,
bool includeUnfinishedIndexes,
- std::vector<IndexDescriptor*>* matches) const override;
+ std::vector<const IndexDescriptor*>* matches) const override;
/**
* Returns an index suitable for shard key range scans.
@@ -138,13 +137,13 @@ public:
*
* If no such index exists, returns NULL.
*/
- IndexDescriptor* findShardKeyPrefixedIndex(OperationContext* opCtx,
- const BSONObj& shardKey,
- bool requireSingleKey) const override;
+ const IndexDescriptor* findShardKeyPrefixedIndex(OperationContext* opCtx,
+ const BSONObj& shardKey,
+ bool requireSingleKey) const override;
void findIndexByType(OperationContext* opCtx,
const std::string& type,
- std::vector<IndexDescriptor*>& matches,
+ std::vector<const IndexDescriptor*>& matches,
bool includeUnfinishedIndexes = false) const override;
@@ -168,9 +167,6 @@ public:
std::vector<std::shared_ptr<const IndexCatalogEntry>> getAllReadyEntriesShared() const override;
- IndexAccessMethod* getIndex(const IndexDescriptor* desc) override;
- const IndexAccessMethod* getIndex(const IndexDescriptor* desc) const override;
-
/**
* Returns a not-ok Status if there are any unfinished index builds. No new indexes should
* be built when in this state.
@@ -208,7 +204,7 @@ public:
stdx::function<void(const IndexDescriptor*)> onDropFn) override;
void dropAllIndexes(OperationContext* opCtx, bool includingIdIndex) override;
- Status dropIndex(OperationContext* opCtx, IndexDescriptor* desc) override;
+ Status dropIndex(OperationContext* opCtx, const IndexDescriptor* desc) override;
/**
* will drop all incompleted indexes and return specs
@@ -241,6 +237,10 @@ public:
*/
MultikeyPaths getMultikeyPaths(OperationContext* opCtx, const IndexDescriptor* idx) override;
+ void setMultikeyPaths(OperationContext* const opCtx,
+ const IndexDescriptor* desc,
+ const MultikeyPaths& multikeyPaths) override;
+
// --- these probably become private?
class IndexBuildBlock : public IndexCatalog::IndexBuildBlockInterface {
@@ -330,6 +330,8 @@ public:
bool noWarn,
int64_t* keysDeletedOut) override;
+ Status compactIndexes(OperationContext* opCtx) override;
+
inline std::string getAccessMethodName(const BSONObj& keyPattern) override {
return _getAccessMethodName(keyPattern);
}
diff --git a/src/mongo/db/catalog/index_catalog_noop.h b/src/mongo/db/catalog/index_catalog_noop.h
index 38ec89e7fc4..8005b1dc2a2 100644
--- a/src/mongo/db/catalog/index_catalog_noop.h
+++ b/src/mongo/db/catalog/index_catalog_noop.h
@@ -90,10 +90,11 @@ public:
return nullptr;
}
- void findIndexesByKeyPattern(OperationContext* const opCtx,
- const BSONObj& key,
- const bool includeUnfinishedIndexes,
- std::vector<IndexDescriptor*>* const matches) const override {}
+ void findIndexesByKeyPattern(
+ OperationContext* const opCtx,
+ const BSONObj& key,
+ const bool includeUnfinishedIndexes,
+ std::vector<const IndexDescriptor*>* const matches) const override {}
IndexDescriptor* findShardKeyPrefixedIndex(OperationContext* const opCtx,
const BSONObj& shardKey,
@@ -103,7 +104,7 @@ public:
void findIndexByType(OperationContext* const opCtx,
const std::string& type,
- std::vector<IndexDescriptor*>& matches,
+ std::vector<const IndexDescriptor*>& matches,
const bool includeUnfinishedIndexes = false) const override {}
const IndexDescriptor* refreshEntry(OperationContext* const opCtx,
@@ -124,14 +125,6 @@ public:
return {};
}
- IndexAccessMethod* getIndex(const IndexDescriptor* const desc) override {
- return nullptr;
- }
-
- const IndexAccessMethod* getIndex(const IndexDescriptor* const desc) const override {
- return nullptr;
- }
-
Status checkUnfinished() const override {
return Status::OK();
}
@@ -163,7 +156,7 @@ public:
void dropAllIndexes(OperationContext* opCtx, bool includingIdIndex) override {}
- Status dropIndex(OperationContext* const opCtx, IndexDescriptor* const desc) override {
+ Status dropIndex(OperationContext* const opCtx, const IndexDescriptor* const desc) override {
return Status::OK();
}
@@ -180,6 +173,10 @@ public:
return {};
}
+ void setMultikeyPaths(OperationContext* const opCtx,
+ const IndexDescriptor* const desc,
+ const MultikeyPaths& multikeyPaths) override {}
+
Status indexRecords(OperationContext* const opCtx,
const std::vector<BsonRecord>& bsonRecords,
int64_t* const keysInsertedOut) override {
@@ -201,6 +198,10 @@ public:
const bool noWarn,
int64_t* const keysDeletedOut) override {}
+ virtual Status compactIndexes(OperationContext* opCtx) override {
+ return Status::OK();
+ }
+
std::string getAccessMethodName(const BSONObj& keyPattern) override {
return "";
}
diff --git a/src/mongo/db/catalog/private/record_store_validate_adaptor.cpp b/src/mongo/db/catalog/private/record_store_validate_adaptor.cpp
index 826cbbe4ebf..bc7dace1981 100644
--- a/src/mongo/db/catalog/private/record_store_validate_adaptor.cpp
+++ b/src/mongo/db/catalog/private/record_store_validate_adaptor.cpp
@@ -89,7 +89,7 @@ Status RecordStoreValidateAdaptor::validate(const RecordId& recordId,
int indexNumber = _indexConsistency->getIndexNumber(indexNs);
ValidateResults curRecordResults;
- const IndexAccessMethod* iam = _indexCatalog->getIndex(descriptor);
+ const IndexAccessMethod* iam = _indexCatalog->getEntry(descriptor)->accessMethod();
if (descriptor->isPartial()) {
const IndexCatalogEntry* ice = _indexCatalog->getEntry(descriptor);
@@ -254,7 +254,7 @@ void RecordStoreValidateAdaptor::traverseRecordStore(RecordStore* recordStore,
output->appendNumber("nrecords", nrecords);
}
-void RecordStoreValidateAdaptor::validateIndexKeyCount(IndexDescriptor* idx,
+void RecordStoreValidateAdaptor::validateIndexKeyCount(const IndexDescriptor* idx,
int64_t numRecs,
ValidateResults& results) {
const std::string indexNs = idx->indexNamespace();
diff --git a/src/mongo/db/catalog/private/record_store_validate_adaptor.h b/src/mongo/db/catalog/private/record_store_validate_adaptor.h
index 767f0f4562b..a62d0d89041 100644
--- a/src/mongo/db/catalog/private/record_store_validate_adaptor.h
+++ b/src/mongo/db/catalog/private/record_store_validate_adaptor.h
@@ -91,7 +91,9 @@ public:
/**
* Validate that the number of document keys matches the number of index keys.
*/
- void validateIndexKeyCount(IndexDescriptor* idx, int64_t numRecs, ValidateResults& results);
+ void validateIndexKeyCount(const IndexDescriptor* idx,
+ int64_t numRecs,
+ ValidateResults& results);
private:
OperationContext* _opCtx; // Not owned.
diff --git a/src/mongo/db/catalog/rename_collection.cpp b/src/mongo/db/catalog/rename_collection.cpp
index 07326f7b5b0..17511b348b5 100644
--- a/src/mongo/db/catalog/rename_collection.cpp
+++ b/src/mongo/db/catalog/rename_collection.cpp
@@ -299,7 +299,7 @@ Status renameCollectionCommon(OperationContext* opCtx,
// drop-pending rename. In the case that this collection drop gets rolled back, this
// will incur a performance hit, since those indexes will have to be rebuilt from
// scratch, but data integrity is maintained.
- std::vector<IndexDescriptor*> indexesToDrop;
+ std::vector<const IndexDescriptor*> indexesToDrop;
auto indexIter = targetColl->getIndexCatalog()->getIndexIterator(opCtx, true);
// Determine which index names are too long. Since we don't have the collection
diff --git a/src/mongo/db/commands/dbcommands.cpp b/src/mongo/db/commands/dbcommands.cpp
index 5df659e062c..2190cdc3910 100644
--- a/src/mongo/db/commands/dbcommands.cpp
+++ b/src/mongo/db/commands/dbcommands.cpp
@@ -448,7 +448,7 @@ public:
keyPattern = Helpers::inferKeyPattern(min);
}
- IndexDescriptor* idx =
+ const IndexDescriptor* idx =
collection->getIndexCatalog()->findShardKeyPrefixedIndex(opCtx,
keyPattern,
true); // requireSingleKey
diff --git a/src/mongo/db/commands/dbhash.cpp b/src/mongo/db/commands/dbhash.cpp
index e3abe5437b4..5cbcc0015ba 100644
--- a/src/mongo/db/commands/dbhash.cpp
+++ b/src/mongo/db/commands/dbhash.cpp
@@ -246,7 +246,7 @@ private:
invariant(opCtx->lockState()->isDbLockedForMode(db->name(), MODE_S));
}
- IndexDescriptor* desc = collection->getIndexCatalog()->findIdIndex(opCtx);
+ auto desc = collection->getIndexCatalog()->findIdIndex(opCtx);
std::unique_ptr<PlanExecutor, PlanExecutor::Deleter> exec;
if (desc) {
diff --git a/src/mongo/db/commands/haystack.cpp b/src/mongo/db/commands/haystack.cpp
index 123e63d4e1c..56d145a3276 100644
--- a/src/mongo/db/commands/haystack.cpp
+++ b/src/mongo/db/commands/haystack.cpp
@@ -116,7 +116,7 @@ public:
return false;
}
- vector<IndexDescriptor*> idxs;
+ vector<const IndexDescriptor*> idxs;
collection->getIndexCatalog()->findIndexByType(opCtx, IndexNames::GEO_HAYSTACK, idxs);
if (idxs.size() == 0) {
errmsg = "no geoSearch index";
@@ -139,9 +139,9 @@ public:
if (cmdObj["limit"].isNumber())
limit = static_cast<unsigned>(cmdObj["limit"].numberInt());
- IndexDescriptor* desc = idxs[0];
- HaystackAccessMethod* ham =
- static_cast<HaystackAccessMethod*>(collection->getIndexCatalog()->getIndex(desc));
+ const IndexDescriptor* desc = idxs[0];
+ auto ham = static_cast<const HaystackAccessMethod*>(
+ collection->getIndexCatalog()->getEntry(desc)->accessMethod());
ham->searchCommand(opCtx,
collection,
nearElt.Obj(),
diff --git a/src/mongo/db/commands/mr.cpp b/src/mongo/db/commands/mr.cpp
index 0c3110cb97b..6d3ad0e9a50 100644
--- a/src/mongo/db/commands/mr.cpp
+++ b/src/mongo/db/commands/mr.cpp
@@ -536,7 +536,7 @@ void State::prepTempCollection() {
finalColl->getIndexCatalog()->getIndexIterator(_opCtx, true);
// Iterate over finalColl's indexes.
while (ii->more()) {
- IndexDescriptor* currIndex = ii->next()->descriptor();
+ const IndexDescriptor* currIndex = ii->next()->descriptor();
BSONObjBuilder b;
b.append("ns", _config.tempNamespace.ns());
@@ -1124,7 +1124,7 @@ void State::finalReduce(OperationContext* opCtx, CurOp* curOp, ProgressMeterHold
autoIncColl.getCollection()->getIndexCatalog()->getIndexIterator(_opCtx, true);
// Iterate over incColl's indexes.
while (ii->more()) {
- IndexDescriptor* currIndex = ii->next()->descriptor();
+ const IndexDescriptor* currIndex = ii->next()->descriptor();
BSONObj x = currIndex->infoObj();
if (sortKey.woCompare(x["key"].embeddedObject()) == 0) {
foundIndex = true;
diff --git a/src/mongo/db/dbhelpers.cpp b/src/mongo/db/dbhelpers.cpp
index 4c547d68a7e..d1b5b9518fa 100644
--- a/src/mongo/db/dbhelpers.cpp
+++ b/src/mongo/db/dbhelpers.cpp
@@ -165,7 +165,7 @@ bool Helpers::findById(OperationContext* opCtx,
if (indexFound)
*indexFound = 1;
- RecordId loc = catalog->getIndex(desc)->findSingle(opCtx, query["_id"].wrap());
+ RecordId loc = catalog->getEntry(desc)->accessMethod()->findSingle(opCtx, query["_id"].wrap());
if (loc.isNull())
return false;
result = collection->docFor(opCtx, loc).value();
@@ -179,7 +179,7 @@ RecordId Helpers::findById(OperationContext* opCtx,
IndexCatalog* catalog = collection->getIndexCatalog();
const IndexDescriptor* desc = catalog->findIdIndex(opCtx);
uassert(13430, "no _id index", desc);
- return catalog->getIndex(desc)->findSingle(opCtx, idquery["_id"].wrap());
+ return catalog->getEntry(desc)->accessMethod()->findSingle(opCtx, idquery["_id"].wrap());
}
bool Helpers::getSingleton(OperationContext* opCtx, const char* ns, BSONObj& result) {
diff --git a/src/mongo/db/exec/stagedebug_cmd.cpp b/src/mongo/db/exec/stagedebug_cmd.cpp
index ebcd2208952..2a9aa368cf3 100644
--- a/src/mongo/db/exec/stagedebug_cmd.cpp
+++ b/src/mongo/db/exec/stagedebug_cmd.cpp
@@ -274,11 +274,11 @@ public:
string nodeName = firstElt.fieldName();
if ("ixscan" == nodeName) {
- IndexDescriptor* desc;
+ const IndexDescriptor* desc;
if (BSONElement keyPatternElement = nodeArgs["keyPattern"]) {
// This'll throw if it's not an obj but that's OK.
BSONObj keyPatternObj = keyPatternElement.Obj();
- std::vector<IndexDescriptor*> indexes;
+ std::vector<const IndexDescriptor*> indexes;
collection->getIndexCatalog()->findIndexesByKeyPattern(
opCtx, keyPatternObj, false, &indexes);
uassert(16890,
@@ -453,13 +453,14 @@ public:
} else if ("text" == nodeName) {
string search = nodeArgs["search"].String();
- vector<IndexDescriptor*> idxMatches;
+ vector<const IndexDescriptor*> idxMatches;
collection->getIndexCatalog()->findIndexByType(opCtx, "text", idxMatches);
uassert(17194, "Expected exactly one text index", idxMatches.size() == 1);
- IndexDescriptor* index = idxMatches[0];
- FTSAccessMethod* fam =
- dynamic_cast<FTSAccessMethod*>(collection->getIndexCatalog()->getIndex(index));
+ const IndexDescriptor* index = idxMatches[0];
+ const FTSAccessMethod* fam = dynamic_cast<const FTSAccessMethod*>(
+ collection->getIndexCatalog()->getEntry(index)->accessMethod());
+ invariant(fam);
TextStageParams params(fam->getSpec());
params.index = index;
diff --git a/src/mongo/db/index/haystack_access_method.cpp b/src/mongo/db/index/haystack_access_method.cpp
index ed57097f0b5..117feda7bc8 100644
--- a/src/mongo/db/index/haystack_access_method.cpp
+++ b/src/mongo/db/index/haystack_access_method.cpp
@@ -78,7 +78,7 @@ void HaystackAccessMethod::searchCommand(OperationContext* opCtx,
double maxDistance,
const BSONObj& search,
BSONObjBuilder* result,
- unsigned limit) {
+ unsigned limit) const {
Timer t;
LOG(1) << "SEARCH near:" << redact(nearObj) << " maxDistance:" << maxDistance
diff --git a/src/mongo/db/index/haystack_access_method.h b/src/mongo/db/index/haystack_access_method.h
index bd328eb007a..547a0057785 100644
--- a/src/mongo/db/index/haystack_access_method.h
+++ b/src/mongo/db/index/haystack_access_method.h
@@ -68,7 +68,7 @@ protected:
double maxDistance,
const BSONObj& search,
BSONObjBuilder* result,
- unsigned limit);
+ unsigned limit) const;
private:
/**
diff --git a/src/mongo/db/index/index_access_method.cpp b/src/mongo/db/index/index_access_method.cpp
index 47d9846d58b..4092077bbac 100644
--- a/src/mongo/db/index/index_access_method.cpp
+++ b/src/mongo/db/index/index_access_method.cpp
@@ -378,7 +378,7 @@ RecordId AbstractIndexAccessMethod::findSingle(OperationContext* opCtx,
void AbstractIndexAccessMethod::validate(OperationContext* opCtx,
int64_t* numKeys,
- ValidateResults* fullResults) {
+ ValidateResults* fullResults) const {
long long keys = 0;
_newInterface->fullValidate(opCtx, &keys, fullResults);
*numKeys = keys;
diff --git a/src/mongo/db/index/index_access_method.h b/src/mongo/db/index/index_access_method.h
index 3c466486410..1edf7fdd209 100644
--- a/src/mongo/db/index/index_access_method.h
+++ b/src/mongo/db/index/index_access_method.h
@@ -188,7 +188,7 @@ public:
*/
virtual void validate(OperationContext* opCtx,
int64_t* numKeys,
- ValidateResults* fullResults) = 0;
+ ValidateResults* fullResults) const = 0;
/**
* Add custom statistics about this index to BSON object builder, for display.
@@ -500,7 +500,9 @@ public:
Status touch(OperationContext* opCtx) const final;
- void validate(OperationContext* opCtx, int64_t* numKeys, ValidateResults* fullResults) final;
+ void validate(OperationContext* opCtx,
+ int64_t* numKeys,
+ ValidateResults* fullResults) const final;
bool appendCustomStats(OperationContext* opCtx,
BSONObjBuilder* result,
diff --git a/src/mongo/db/matcher/expression_text.cpp b/src/mongo/db/matcher/expression_text.cpp
index 8f486314e5c..561aedd5465 100644
--- a/src/mongo/db/matcher/expression_text.cpp
+++ b/src/mongo/db/matcher/expression_text.cpp
@@ -77,7 +77,7 @@ TextMatchExpression::TextMatchExpression(OperationContext* opCtx,
<< "')",
collection);
- std::vector<IndexDescriptor*> idxMatches;
+ std::vector<const IndexDescriptor*> idxMatches;
collection->getIndexCatalog()->findIndexByType(opCtx, IndexNames::TEXT, idxMatches);
uassert(
@@ -87,9 +87,9 @@ TextMatchExpression::TextMatchExpression(OperationContext* opCtx,
idxMatches.size() < 2);
invariant(idxMatches.size() == 1);
- IndexDescriptor* index = idxMatches[0];
- const FTSAccessMethod* fam =
- static_cast<FTSAccessMethod*>(collection->getIndexCatalog()->getIndex(index));
+ const IndexDescriptor* index = idxMatches[0];
+ const FTSAccessMethod* fam = static_cast<const FTSAccessMethod*>(
+ collection->getIndexCatalog()->getEntry(index)->accessMethod());
invariant(fam);
// Extract version and default language from text index.
diff --git a/src/mongo/db/pipeline/pipeline_d.cpp b/src/mongo/db/pipeline/pipeline_d.cpp
index 9aaa69ce2c1..6e706c1e1f2 100644
--- a/src/mongo/db/pipeline/pipeline_d.cpp
+++ b/src/mongo/db/pipeline/pipeline_d.cpp
@@ -255,7 +255,7 @@ BSONObj removeSortKeyMetaProjection(BSONObj projectionObj) {
StringData extractGeoNearFieldFromIndexes(OperationContext* opCtx, Collection* collection) {
invariant(collection);
- std::vector<IndexDescriptor*> idxs;
+ std::vector<const IndexDescriptor*> idxs;
collection->getIndexCatalog()->findIndexByType(opCtx, IndexNames::GEO_2D, idxs);
uassert(ErrorCodes::IndexNotFound,
str::stream() << "There is more than one 2d index on " << collection->ns().ns()
diff --git a/src/mongo/db/pipeline/process_interface_standalone.cpp b/src/mongo/db/pipeline/process_interface_standalone.cpp
index bff692e7641..70330f1fe3b 100644
--- a/src/mongo/db/pipeline/process_interface_standalone.cpp
+++ b/src/mongo/db/pipeline/process_interface_standalone.cpp
@@ -505,7 +505,7 @@ bool MongoInterfaceStandalone::uniqueKeyIsSupportedByIndex(
auto indexIterator = collection->getIndexCatalog()->getIndexIterator(opCtx, false);
while (indexIterator->more()) {
- IndexCatalogEntry* entry = indexIterator->next();
+ const IndexCatalogEntry* entry = indexIterator->next();
if (supportsUniqueKey(expCtx, entry, uniqueKeyPaths)) {
return true;
}
diff --git a/src/mongo/db/query/get_executor.cpp b/src/mongo/db/query/get_executor.cpp
index 0e24ef31472..b9b1776f426 100644
--- a/src/mongo/db/query/get_executor.cpp
+++ b/src/mongo/db/query/get_executor.cpp
@@ -210,7 +210,7 @@ void fillOutPlannerParams(OperationContext* opCtx,
std::unique_ptr<IndexCatalog::IndexIterator> ii =
collection->getIndexCatalog()->getIndexIterator(opCtx, false);
while (ii->more()) {
- IndexCatalogEntry* ice = ii->next();
+ const IndexCatalogEntry* ice = ii->next();
plannerParams->indices.push_back(
indexEntryFromIndexCatalogEntry(opCtx, *ice, canonicalQuery));
}
@@ -1516,7 +1516,7 @@ QueryPlannerParams fillOutPlannerParamsForDistinct(OperationContext* opCtx,
collection->getIndexCatalog()->getIndexIterator(opCtx, false);
auto query = parsedDistinct.getQuery()->getQueryRequest().getFilter();
while (ii->more()) {
- IndexCatalogEntry* ice = ii->next();
+ const IndexCatalogEntry* ice = ii->next();
const IndexDescriptor* desc = ice->descriptor();
if (desc->keyPattern().hasField(parsedDistinct.getKey())) {
plannerParams.indices.push_back(
@@ -1524,7 +1524,7 @@ QueryPlannerParams fillOutPlannerParamsForDistinct(OperationContext* opCtx,
} else if (desc->getIndexType() == IndexType::INDEX_WILDCARD && !query.isEmpty()) {
// Check whether the $** projection captures the field over which we are distinct-ing.
const auto* proj =
- static_cast<WildcardAccessMethod*>(ice->accessMethod())->getProjectionExec();
+ static_cast<const WildcardAccessMethod*>(ice->accessMethod())->getProjectionExec();
if (proj->applyProjectionToOneField(parsedDistinct.getKey())) {
plannerParams.indices.push_back(
indexEntryFromIndexCatalogEntry(opCtx, *ice, parsedDistinct.getQuery()));
diff --git a/src/mongo/db/query/stage_builder.cpp b/src/mongo/db/query/stage_builder.cpp
index c6ff07b9783..511c9c32c26 100644
--- a/src/mongo/db/query/stage_builder.cpp
+++ b/src/mongo/db/query/stage_builder.cpp
@@ -246,7 +246,7 @@ PlanStage* buildStages(OperationContext* opCtx,
params.addPointMeta = node->addPointMeta;
params.addDistMeta = node->addDistMeta;
- IndexDescriptor* twoDIndex = collection->getIndexCatalog()->findIndexByName(
+ const IndexDescriptor* twoDIndex = collection->getIndexCatalog()->findIndexByName(
opCtx, node->index.identifier.catalogName);
invariant(twoDIndex);
@@ -264,7 +264,7 @@ PlanStage* buildStages(OperationContext* opCtx,
params.addPointMeta = node->addPointMeta;
params.addDistMeta = node->addDistMeta;
- IndexDescriptor* s2Index = collection->getIndexCatalog()->findIndexByName(
+ const IndexDescriptor* s2Index = collection->getIndexCatalog()->findIndexByName(
opCtx, node->index.identifier.catalogName);
invariant(s2Index);
@@ -272,11 +272,11 @@ PlanStage* buildStages(OperationContext* opCtx,
}
case STAGE_TEXT: {
const TextNode* node = static_cast<const TextNode*>(root);
- IndexDescriptor* desc = collection->getIndexCatalog()->findIndexByName(
+ const IndexDescriptor* desc = collection->getIndexCatalog()->findIndexByName(
opCtx, node->index.identifier.catalogName);
invariant(desc);
- const FTSAccessMethod* fam =
- static_cast<const FTSAccessMethod*>(collection->getIndexCatalog()->getIndex(desc));
+ const FTSAccessMethod* fam = static_cast<const FTSAccessMethod*>(
+ collection->getIndexCatalog()->getEntry(desc)->accessMethod());
invariant(fam);
TextStageParams params(fam->getSpec());
diff --git a/src/mongo/db/repl/dbcheck.cpp b/src/mongo/db/repl/dbcheck.cpp
index f07748076b0..798a751210a 100644
--- a/src/mongo/db/repl/dbcheck.cpp
+++ b/src/mongo/db/repl/dbcheck.cpp
@@ -190,7 +190,7 @@ DbCheckHasher::DbCheckHasher(OperationContext* opCtx,
md5_init(&_state);
// Get the _id index.
- IndexDescriptor* desc = collection->getIndexCatalog()->findIdIndex(opCtx);
+ const IndexDescriptor* desc = collection->getIndexCatalog()->findIdIndex(opCtx);
uassert(ErrorCodes::IndexNotFound, "dbCheck needs _id index", desc);
diff --git a/src/mongo/db/repl/idempotency_test_fixture.cpp b/src/mongo/db/repl/idempotency_test_fixture.cpp
index c95da4afa31..48e3d97f5c6 100644
--- a/src/mongo/db/repl/idempotency_test_fixture.cpp
+++ b/src/mongo/db/repl/idempotency_test_fixture.cpp
@@ -403,7 +403,7 @@ OplogEntry IdempotencyTest::dropIndex(const std::string& indexName) {
}
std::string IdempotencyTest::computeDataHash(Collection* collection) {
- IndexDescriptor* desc = collection->getIndexCatalog()->findIdIndex(_opCtx.get());
+ auto desc = collection->getIndexCatalog()->findIdIndex(_opCtx.get());
ASSERT_TRUE(desc);
auto exec = InternalPlanner::indexScan(_opCtx.get(),
collection,
diff --git a/src/mongo/db/repl/rs_rollback_test.cpp b/src/mongo/db/repl/rs_rollback_test.cpp
index c91e088be2d..51f266dfcf5 100644
--- a/src/mongo/db/repl/rs_rollback_test.cpp
+++ b/src/mongo/db/repl/rs_rollback_test.cpp
@@ -712,7 +712,7 @@ TEST_F(RSRollbackTest, RollingBackCreateIndexAndRenameWithLongName) {
ASSERT(indexCatalog);
ASSERT_EQUALS(1, indexCatalog->numIndexesReady(_opCtx.get()));
- std::vector<IndexDescriptor*> indexes;
+ std::vector<const IndexDescriptor*> indexes;
indexCatalog->findIndexesByKeyPattern(_opCtx.get(), BSON("b" << 1), false, &indexes);
ASSERT(indexes.size() == 0);
}
@@ -771,12 +771,12 @@ TEST_F(RSRollbackTest, RollingBackDropAndCreateOfSameIndexNameWithDifferentSpecs
<< ", UUID: "
<< options.uuid->toString()
<< ", index: a_1"));
- std::vector<IndexDescriptor*> indexes;
+ std::vector<const IndexDescriptor*> indexes;
indexCatalog->findIndexesByKeyPattern(_opCtx.get(), BSON("a" << 1), false, &indexes);
ASSERT(indexes.size() == 1);
ASSERT(indexes[0]->indexName() == "a_1");
- std::vector<IndexDescriptor*> indexes2;
+ std::vector<const IndexDescriptor*> indexes2;
indexCatalog->findIndexesByKeyPattern(_opCtx.get(), BSON("b" << 1), false, &indexes2);
ASSERT(indexes2.size() == 0);
}
diff --git a/src/mongo/db/repl/storage_interface_impl.cpp b/src/mongo/db/repl/storage_interface_impl.cpp
index a6ba88502bc..8d96d926e95 100644
--- a/src/mongo/db/repl/storage_interface_impl.cpp
+++ b/src/mongo/db/repl/storage_interface_impl.cpp
@@ -528,7 +528,7 @@ Status StorageInterfaceImpl::setIndexIsMultikey(OperationContext* opCtx,
<< nss.ns()
<< " to set to multikey.");
}
- collection->getIndexCatalog()->getIndex(idx)->setIndexIsMultikey(opCtx, paths);
+ collection->getIndexCatalog()->setMultikeyPaths(opCtx, idx, paths);
wunit.commit();
return Status::OK();
});
@@ -609,7 +609,7 @@ StatusWith<std::vector<BSONObj>> _findOrDeleteDocuments(
auto indexCatalog = collection->getIndexCatalog();
invariant(indexCatalog);
bool includeUnfinishedIndexes = false;
- IndexDescriptor* indexDescriptor =
+ const IndexDescriptor* indexDescriptor =
indexCatalog->findIndexByName(opCtx, *indexName, includeUnfinishedIndexes);
if (!indexDescriptor) {
return Result(ErrorCodes::IndexNotFound,
diff --git a/src/mongo/db/repl/storage_interface_impl_test.cpp b/src/mongo/db/repl/storage_interface_impl_test.cpp
index cc5702f542c..dbc679c9a4d 100644
--- a/src/mongo/db/repl/storage_interface_impl_test.cpp
+++ b/src/mongo/db/repl/storage_interface_impl_test.cpp
@@ -162,8 +162,8 @@ TimestampedBSONObj makeOplogEntry(OpTime opTime) {
/**
* Counts the number of keys in an index using an IndexAccessMethod::validate call.
*/
-int64_t getIndexKeyCount(OperationContext* opCtx, IndexCatalog* cat, IndexDescriptor* desc) {
- auto idx = cat->getIndex(desc);
+int64_t getIndexKeyCount(OperationContext* opCtx, IndexCatalog* cat, const IndexDescriptor* desc) {
+ auto idx = cat->getEntry(desc)->accessMethod();
int64_t numKeys;
ValidateResults fullRes;
idx->validate(opCtx, &numKeys, &fullRes);
diff --git a/src/mongo/db/s/check_sharding_index_command.cpp b/src/mongo/db/s/check_sharding_index_command.cpp
index 38e4b44a6d1..cf25be9b60e 100644
--- a/src/mongo/db/s/check_sharding_index_command.cpp
+++ b/src/mongo/db/s/check_sharding_index_command.cpp
@@ -118,7 +118,7 @@ public:
return false;
}
- IndexDescriptor* idx =
+ const IndexDescriptor* idx =
collection->getIndexCatalog()->findShardKeyPrefixedIndex(opCtx,
keyPattern,
true); // requireSingleKey
diff --git a/src/mongo/db/s/collection_range_deleter.cpp b/src/mongo/db/s/collection_range_deleter.cpp
index 8c9bfb4ccd7..8856d53d8a2 100644
--- a/src/mongo/db/s/collection_range_deleter.cpp
+++ b/src/mongo/db/s/collection_range_deleter.cpp
@@ -377,7 +377,8 @@ StatusWith<int> CollectionRangeDeleter::_doDeletion(OperationContext* opCtx,
LOG(1) << "begin removal of " << min << " to " << max << " in " << nss.ns();
const auto indexName = idx->indexName();
- IndexDescriptor* descriptor = collection->getIndexCatalog()->findIndexByName(opCtx, indexName);
+ const IndexDescriptor* descriptor =
+ collection->getIndexCatalog()->findIndexByName(opCtx, indexName);
if (!descriptor) {
std::string msg = str::stream() << "shard key index with name " << indexName << " on '"
<< nss.ns() << "' was dropped";
diff --git a/src/mongo/db/s/migration_chunk_cloner_source_legacy.cpp b/src/mongo/db/s/migration_chunk_cloner_source_legacy.cpp
index 2f1c79c58ad..716083aed25 100644
--- a/src/mongo/db/s/migration_chunk_cloner_source_legacy.cpp
+++ b/src/mongo/db/s/migration_chunk_cloner_source_legacy.cpp
@@ -548,7 +548,7 @@ Status MigrationChunkClonerSourceLegacy::_storeCurrentLocs(OperationContext* opC
// Allow multiKey based on the invariant that shard keys must be single-valued. Therefore, any
// multi-key index prefixed by shard key cannot be multikey over the shard key fields.
- IndexDescriptor* const idx =
+ const IndexDescriptor* idx =
collection->getIndexCatalog()->findShardKeyPrefixedIndex(opCtx,
_shardKeyPattern.toBSON(),
false); // requireSingleKey
diff --git a/src/mongo/db/s/split_chunk.cpp b/src/mongo/db/s/split_chunk.cpp
index d3c0a6908db..b1cb6c5a93e 100644
--- a/src/mongo/db/s/split_chunk.cpp
+++ b/src/mongo/db/s/split_chunk.cpp
@@ -230,7 +230,7 @@ StatusWith<boost::optional<ChunkRange>> splitChunk(OperationContext* opCtx,
// Allow multiKey based on the invariant that shard keys must be single-valued. Therefore,
// any multi-key index prefixed by shard key cannot be multikey over the shard key fields.
- IndexDescriptor* idx =
+ const IndexDescriptor* idx =
collection->getIndexCatalog()->findShardKeyPrefixedIndex(opCtx, keyPatternObj, false);
if (!idx) {
return boost::optional<ChunkRange>(boost::none);
diff --git a/src/mongo/db/s/split_vector.cpp b/src/mongo/db/s/split_vector.cpp
index 91d6804176b..8d759163347 100644
--- a/src/mongo/db/s/split_vector.cpp
+++ b/src/mongo/db/s/split_vector.cpp
@@ -85,7 +85,7 @@ StatusWith<std::vector<BSONObj>> splitVector(OperationContext* opCtx,
// Allow multiKey based on the invariant that shard keys must be single-valued. Therefore,
// any multi-key index prefixed by shard key cannot be multikey over the shard key fields.
- IndexDescriptor* idx =
+ const IndexDescriptor* idx =
collection->getIndexCatalog()->findShardKeyPrefixedIndex(opCtx, keyPattern, false);
if (idx == NULL) {
return {ErrorCodes::IndexNotFound,
diff --git a/src/mongo/db/stats/storage_stats.cpp b/src/mongo/db/stats/storage_stats.cpp
index 45db0f8439c..ca4d68e310a 100644
--- a/src/mongo/db/stats/storage_stats.cpp
+++ b/src/mongo/db/stats/storage_stats.cpp
@@ -93,9 +93,9 @@ Status appendCollectionStorageStats(OperationContext* opCtx,
std::unique_ptr<IndexCatalog::IndexIterator> it = indexCatalog->getIndexIterator(opCtx, false);
while (it->more()) {
- IndexCatalogEntry* entry = it->next();
- IndexDescriptor* descriptor = entry->descriptor();
- IndexAccessMethod* iam = entry->accessMethod();
+ const IndexCatalogEntry* entry = it->next();
+ const IndexDescriptor* descriptor = entry->descriptor();
+ const IndexAccessMethod* iam = entry->accessMethod();
invariant(iam);
BSONObjBuilder bob;
diff --git a/src/mongo/db/system_index.cpp b/src/mongo/db/system_index.cpp
index 1b7676b0596..8a5c3d93df2 100644
--- a/src/mongo/db/system_index.cpp
+++ b/src/mongo/db/system_index.cpp
@@ -169,7 +169,7 @@ Status verifySystemIndexes(OperationContext* opCtx) {
invariant(indexCatalog);
// Make sure the old unique index from v2.4 on system.users doesn't exist.
- std::vector<IndexDescriptor*> indexes;
+ std::vector<const IndexDescriptor*> indexes;
indexCatalog->findIndexesByKeyPattern(opCtx, v1SystemUsersKeyPattern, false, &indexes);
if (!indexes.empty()) {
@@ -198,7 +198,7 @@ Status verifySystemIndexes(OperationContext* opCtx) {
IndexCatalog* indexCatalog = collection->getIndexCatalog();
invariant(indexCatalog);
- std::vector<IndexDescriptor*> indexes;
+ std::vector<const IndexDescriptor*> indexes;
indexCatalog->findIndexesByKeyPattern(opCtx, v3SystemRolesKeyPattern, false, &indexes);
if (indexes.empty()) {
try {
diff --git a/src/mongo/db/transaction_participant.cpp b/src/mongo/db/transaction_participant.cpp
index 5929c41f752..6a5cab4eba2 100644
--- a/src/mongo/db/transaction_participant.cpp
+++ b/src/mongo/db/transaction_participant.cpp
@@ -219,7 +219,7 @@ void updateSessionEntry(OperationContext* opCtx, const UpdateRequest& updateRequ
<< NamespaceString::kSessionTransactionsTableNamespace.ns(),
idIndex);
- auto indexAccess = collection->getIndexCatalog()->getIndex(idIndex);
+ auto indexAccess = collection->getIndexCatalog()->getEntry(idIndex)->accessMethod();
// Since we are looking up a key inside the _id index, create a key object consisting of only
// the _id field.
auto idToFetch = updateRequest.getQuery().firstElement();
diff --git a/src/mongo/db/ttl.cpp b/src/mongo/db/ttl.cpp
index 99a1ef15a9c..0ad9cb0af35 100644
--- a/src/mongo/db/ttl.cpp
+++ b/src/mongo/db/ttl.cpp
@@ -207,7 +207,7 @@ private:
return;
}
- IndexDescriptor* desc = collection->getIndexCatalog()->findIndexByName(opCtx, name);
+ const IndexDescriptor* desc = collection->getIndexCatalog()->findIndexByName(opCtx, name);
if (!desc) {
LOG(1) << "index not found (index build in progress? index dropped?), skipping "
<< "ttl job for: " << idx;