summaryrefslogtreecommitdiff
path: root/src/mongo/db/catalog/index_build_block.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/catalog/index_build_block.cpp')
-rw-r--r--src/mongo/db/catalog/index_build_block.cpp59
1 files changed, 21 insertions, 38 deletions
diff --git a/src/mongo/db/catalog/index_build_block.cpp b/src/mongo/db/catalog/index_build_block.cpp
index 34dbf0c49ad..6174e891b64 100644
--- a/src/mongo/db/catalog/index_build_block.cpp
+++ b/src/mongo/db/catalog/index_build_block.cpp
@@ -44,6 +44,7 @@
#include "mongo/db/query/collection_index_usage_tracker_decoration.h"
#include "mongo/db/query/collection_query_info.h"
#include "mongo/db/storage/durable_catalog.h"
+#include "mongo/db/storage/storage_parameters_gen.h"
#include "mongo/db/ttl_collection_cache.h"
#include "mongo/db/vector_clock.h"
#include "mongo/logv2/log.h"
@@ -57,7 +58,14 @@ IndexBuildBlock::IndexBuildBlock(const NamespaceString& nss,
const BSONObj& spec,
IndexBuildMethod method,
boost::optional<UUID> indexBuildUUID)
- : _nss(nss), _spec(spec.getOwned()), _method(method), _buildUUID(indexBuildUUID) {}
+ : _nss(nss),
+ _spec(spec.getOwned()),
+ _method(method),
+ _buildUUID(indexBuildUUID),
+ _pooledBuilder(
+ gOperationMemoryPoolBlockInitialSizeKB.loadRelaxed() * static_cast<size_t>(1024),
+ SharedBufferFragmentBuilder::DoubleGrowStrategy(
+ gOperationMemoryPoolBlockMaxSizeKB.loadRelaxed() * static_cast<size_t>(1024))) {}
void IndexBuildBlock::keepTemporaryTables() {
if (_indexBuildInterceptor) {
@@ -75,11 +83,6 @@ void IndexBuildBlock::_completeInit(OperationContext* opCtx, Collection* collect
.registerIndex(desc->indexName(),
desc->keyPattern(),
IndexFeatures::make(desc, collection->ns().isOnInternalDb()));
- opCtx->recoveryUnit()->onRollback(
- [collectionDecorations = collection->getSharedDecorations(), indexName = _indexName] {
- CollectionIndexUsageTrackerDecoration::get(collectionDecorations)
- .unregisterIndex(indexName);
- });
}
Status IndexBuildBlock::initForResume(OperationContext* opCtx,
@@ -89,9 +92,7 @@ Status IndexBuildBlock::initForResume(OperationContext* opCtx,
_indexName = _spec.getStringField("name").toString();
auto descriptor = collection->getIndexCatalog()->findIndexByName(
- opCtx,
- _indexName,
- IndexCatalog::InclusionPolicy::kReady | IndexCatalog::InclusionPolicy::kUnfinished);
+ opCtx, _indexName, true /* includeUnfinishedIndexes */);
auto indexCatalogEntry = descriptor->getEntry();
@@ -127,7 +128,7 @@ Status IndexBuildBlock::initForResume(OperationContext* opCtx,
return Status::OK();
}
-Status IndexBuildBlock::init(OperationContext* opCtx, Collection* collection, bool forRecovery) {
+Status IndexBuildBlock::init(OperationContext* opCtx, Collection* collection) {
// Being in a WUOW means all timestamping responsibility can be pushed up to the caller.
invariant(opCtx->lockState()->inAWriteUnitOfWork());
@@ -155,25 +156,14 @@ Status IndexBuildBlock::init(OperationContext* opCtx, Collection* collection, bo
!replCoord->getMemberState().primary() && isBackgroundIndex;
}
- if (!forRecovery) {
- // Setup on-disk structures. We skip this during startup recovery for unfinished indexes as
- // everything is already in-place.
- Status status = collection->prepareForIndexBuild(
- opCtx, descriptor.get(), _buildUUID, isBackgroundSecondaryBuild);
- if (!status.isOK())
- return status;
- }
+ // Setup on-disk structures.
+ Status status = collection->prepareForIndexBuild(
+ opCtx, descriptor.get(), _buildUUID, isBackgroundSecondaryBuild);
+ if (!status.isOK())
+ return status;
- auto indexCatalog = collection->getIndexCatalog();
- IndexCatalogEntry* indexCatalogEntry = nullptr;
- if (forRecovery) {
- auto desc = indexCatalog->findIndexByName(
- opCtx, _indexName, IndexCatalog::InclusionPolicy::kUnfinished);
- indexCatalogEntry = desc->getEntry();
- } else {
- indexCatalogEntry = indexCatalog->createIndexEntry(
- opCtx, collection, std::move(descriptor), CreateIndexEntryFlags::kNone);
- }
+ auto indexCatalogEntry = collection->getIndexCatalog()->createIndexEntry(
+ opCtx, collection, std::move(descriptor), CreateIndexEntryFlags::kNone);
if (_method == IndexBuildMethod::kHybrid) {
_indexBuildInterceptor = std::make_unique<IndexBuildInterceptor>(opCtx, indexCatalogEntry);
@@ -284,10 +274,7 @@ void IndexBuildBlock::success(OperationContext* opCtx, Collection* collection) {
// Note that TTL deletion is supported on capped clustered collections via bounded
// collection scan, which does not use an index.
if (spec.hasField(IndexDescriptor::kExpireAfterSecondsFieldName) && !coll->isCapped()) {
- TTLCollectionCache::get(svcCtx).registerTTLInfo(
- coll->uuid(),
- TTLCollectionCache::Info{
- indexName, spec[IndexDescriptor::kExpireAfterSecondsFieldName].isNaN()});
+ TTLCollectionCache::get(svcCtx).registerTTLInfo(coll->uuid(), indexName);
}
});
}
@@ -295,18 +282,14 @@ void IndexBuildBlock::success(OperationContext* opCtx, Collection* collection) {
const IndexCatalogEntry* IndexBuildBlock::getEntry(OperationContext* opCtx,
const CollectionPtr& collection) const {
auto descriptor = collection->getIndexCatalog()->findIndexByName(
- opCtx,
- _indexName,
- IndexCatalog::InclusionPolicy::kReady | IndexCatalog::InclusionPolicy::kUnfinished);
+ opCtx, _indexName, true /* includeUnfinishedIndexes */);
return descriptor->getEntry();
}
IndexCatalogEntry* IndexBuildBlock::getEntry(OperationContext* opCtx, Collection* collection) {
auto descriptor = collection->getIndexCatalog()->findIndexByName(
- opCtx,
- _indexName,
- IndexCatalog::InclusionPolicy::kReady | IndexCatalog::InclusionPolicy::kUnfinished);
+ opCtx, _indexName, true /* includeUnfinishedIndexes */);
return descriptor->getEntry();
}