diff options
author | Gregory Wlodarek <gregory.wlodarek@mongodb.com> | 2020-03-13 17:15:17 -0400 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-03-13 21:30:48 +0000 |
commit | 7ce09a820efeceb4f0a3a70140748aaf88309452 (patch) | |
tree | 256383f537adf21608bb80662051cf07c0892fb5 /src/mongo/db | |
parent | ec6f811d1aaad207ad72de79887d02553993d07f (diff) | |
download | mongo-7ce09a820efeceb4f0a3a70140748aaf88309452.tar.gz |
SERVER-46640 Register index information in TTLCollectionCache upon a successful index build
Diffstat (limited to 'src/mongo/db')
-rw-r--r-- | src/mongo/db/catalog/index_build_block.cpp | 18 | ||||
-rw-r--r-- | src/mongo/db/catalog/index_catalog_impl.cpp | 4 |
2 files changed, 13 insertions, 9 deletions
diff --git a/src/mongo/db/catalog/index_build_block.cpp b/src/mongo/db/catalog/index_build_block.cpp index ec9bd924517..32cfb4a88d8 100644 --- a/src/mongo/db/catalog/index_build_block.cpp +++ b/src/mongo/db/catalog/index_build_block.cpp @@ -81,11 +81,6 @@ Status IndexBuildBlock::init(OperationContext* opCtx, Collection* collection) { _indexName = descriptor->indexName(); - if (_spec.hasField("expireAfterSeconds")) { - TTLCollectionCache::get(getGlobalServiceContext()) - .registerTTLInfo(std::make_pair(collection->uuid(), _indexName)); - } - bool isBackgroundIndex = _method == IndexBuildMethod::kHybrid || _method == IndexBuildMethod::kBackground; bool isBackgroundSecondaryBuild = false; @@ -186,8 +181,11 @@ void IndexBuildBlock::success(OperationContext* opCtx, Collection* collection) { collection->indexBuildSuccess(opCtx, _indexCatalogEntry); auto svcCtx = opCtx->getClient()->getServiceContext(); - opCtx->recoveryUnit()->onCommit([svcCtx, entry = _indexCatalogEntry, coll = collection]( - boost::optional<Timestamp> commitTime) { + opCtx->recoveryUnit()->onCommit([svcCtx, + indexName = _indexName, + spec = _spec, + entry = _indexCatalogEntry, + coll = collection](boost::optional<Timestamp> commitTime) { // Note: this runs after the WUOW commits but before we release our X lock on the // collection. This means that any snapshot created after this must include the full // index, and no one can try to read this index before we set the visibility. @@ -203,6 +201,12 @@ void IndexBuildBlock::success(OperationContext* opCtx, Collection* collection) { // This prevents reads in the past from reading inconsistent metadata. We should be // able to remove this when the catalog is versioned. coll->setMinimumVisibleSnapshot(commitTime.get()); + + // Add the index to the TTLCollectionCache upon successfully committing the index build. + if (spec.hasField(IndexDescriptor::kExpireAfterSecondsFieldName)) { + TTLCollectionCache::get(svcCtx).registerTTLInfo( + std::make_pair(coll->uuid(), indexName)); + } }); } diff --git a/src/mongo/db/catalog/index_catalog_impl.cpp b/src/mongo/db/catalog/index_catalog_impl.cpp index f1010b7fccb..a92afae3d21 100644 --- a/src/mongo/db/catalog/index_catalog_impl.cpp +++ b/src/mongo/db/catalog/index_catalog_impl.cpp @@ -109,8 +109,8 @@ Status IndexCatalogImpl::init(OperationContext* opCtx) { BSONObj keyPattern = spec.getObjectField("key"); auto descriptor = std::make_unique<IndexDescriptor>(_collection, _getAccessMethodName(keyPattern), spec); - if (spec.hasField("expireAfterSeconds")) { - TTLCollectionCache::get(getGlobalServiceContext()) + if (spec.hasField(IndexDescriptor::kExpireAfterSecondsFieldName)) { + TTLCollectionCache::get(opCtx->getServiceContext()) .registerTTLInfo(std::make_pair(_collection->uuid(), indexName)); } |