diff options
author | Gregory Wlodarek <gregory.wlodarek@mongodb.com> | 2019-09-13 01:01:44 +0000 |
---|---|---|
committer | evergreen <evergreen@mongodb.com> | 2019-09-13 01:01:44 +0000 |
commit | 4acaa3f536fe2f3fc2355c7a3e860663201c6f37 (patch) | |
tree | d03fb6e0d16c8b17bc7d071230f8861bf012c0ce | |
parent | 268ab18867527611aac1b515dbc90e6f588879e0 (diff) | |
download | mongo-4acaa3f536fe2f3fc2355c7a3e860663201c6f37.tar.gz |
SERVER-42357 Add additional state to the IndexCatalogEntry to track when it is dropped
-rw-r--r-- | src/mongo/db/catalog/index_catalog_entry.h | 3 | ||||
-rw-r--r-- | src/mongo/db/catalog/index_catalog_entry_impl.cpp | 1 | ||||
-rw-r--r-- | src/mongo/db/catalog/index_catalog_entry_impl.h | 13 | ||||
-rw-r--r-- | src/mongo/db/catalog/index_catalog_impl.cpp | 1 | ||||
-rw-r--r-- | src/mongo/dbtests/indexcatalogtests.cpp | 50 |
5 files changed, 66 insertions, 2 deletions
diff --git a/src/mongo/db/catalog/index_catalog_entry.h b/src/mongo/db/catalog/index_catalog_entry.h index 07246e14f03..f4d55c60880 100644 --- a/src/mongo/db/catalog/index_catalog_entry.h +++ b/src/mongo/db/catalog/index_catalog_entry.h @@ -90,6 +90,9 @@ public: virtual void setIsReady(const bool newIsReady) = 0; + virtual void setDropped() = 0; + virtual bool isDropped() const = 0; + // -- /** diff --git a/src/mongo/db/catalog/index_catalog_entry_impl.cpp b/src/mongo/db/catalog/index_catalog_entry_impl.cpp index b203f3f1fb2..69da31c0ae2 100644 --- a/src/mongo/db/catalog/index_catalog_entry_impl.cpp +++ b/src/mongo/db/catalog/index_catalog_entry_impl.cpp @@ -66,6 +66,7 @@ IndexCatalogEntryImpl::IndexCatalogEntryImpl(OperationContext* const opCtx, _queryInfo(queryInfo), _ordering(Ordering::make(_descriptor->keyPattern())), _isReady(false), + _isDropped(false), _prefix(DurableCatalog::get(opCtx)->getIndexPrefix( opCtx, _descriptor->parentNS(), _descriptor->indexName())) { _descriptor->_cachedEntry = this; diff --git a/src/mongo/db/catalog/index_catalog_entry_impl.h b/src/mongo/db/catalog/index_catalog_entry_impl.h index e11322d63e3..df7f053537f 100644 --- a/src/mongo/db/catalog/index_catalog_entry_impl.h +++ b/src/mongo/db/catalog/index_catalog_entry_impl.h @@ -113,6 +113,14 @@ public: void setIsReady(bool newIsReady) final; + void setDropped() final { + _isDropped.store(true); + } + + bool isDropped() const final { + return _isDropped.load(); + } + // -- /** @@ -199,8 +207,9 @@ private: // cached stuff - Ordering _ordering; // TODO: this might be b-tree specific - bool _isReady; // cache of NamespaceDetails info + Ordering _ordering; // TODO: this might be b-tree specific + bool _isReady; // cache of NamespaceDetails info + AtomicWord<bool> _isDropped; // Whether the index drop is committed. // Set to true if this index supports path-level multikey tracking. // '_indexTracksPathLevelMultikeyInfo' is effectively const after IndexCatalogEntry::init() is diff --git a/src/mongo/db/catalog/index_catalog_impl.cpp b/src/mongo/db/catalog/index_catalog_impl.cpp index 04066249e50..088950236d3 100644 --- a/src/mongo/db/catalog/index_catalog_impl.cpp +++ b/src/mongo/db/catalog/index_catalog_impl.cpp @@ -881,6 +881,7 @@ public: // future, and we will need to do another write to reach the minimum visible snapshot. commitTime = LogicalClock::getClusterTimeForReplicaSet(_opCtx).asTimestamp(); } + _entry->setDropped(); _collection->setMinimumVisibleSnapshot(commitTime.get()); } diff --git a/src/mongo/dbtests/indexcatalogtests.cpp b/src/mongo/dbtests/indexcatalogtests.cpp index 802a200ead9..f51a4e2852a 100644 --- a/src/mongo/dbtests/indexcatalogtests.cpp +++ b/src/mongo/dbtests/indexcatalogtests.cpp @@ -108,6 +108,55 @@ private: Database* _db; }; +class IndexCatalogEntryDroppedTest { +public: + IndexCatalogEntryDroppedTest() { + const ServiceContext::UniqueOperationContext opCtxPtr = cc().makeOperationContext(); + OperationContext& opCtx = *opCtxPtr; + Lock::DBLock lk(&opCtx, _nss.db(), MODE_X); + OldClientContext ctx(&opCtx, _nss.ns()); + WriteUnitOfWork wuow(&opCtx); + + _db = ctx.db(); + _coll = _db->createCollection(&opCtx, _nss); + _catalog = _coll->getIndexCatalog(); + wuow.commit(); + } + + void run() { + const ServiceContext::UniqueOperationContext opCtxPtr = cc().makeOperationContext(); + OperationContext& opCtx = *opCtxPtr; + dbtests::WriteContextForTests ctx(&opCtx, _nss.ns()); + + const IndexDescriptor* idDesc = _catalog->findIdIndex(&opCtx); + std::shared_ptr<const IndexCatalogEntry> entry = _catalog->getEntryShared(idDesc); + + ASSERT_FALSE(entry->isDropped()); + + { + Lock::CollectionLock lk(&opCtx, _nss, MODE_X); + WriteUnitOfWork wuow(&opCtx); + ASSERT_OK(_db->dropCollection(&opCtx, _nss)); + ASSERT_FALSE(entry->isDropped()); + } + + ASSERT_FALSE(entry->isDropped()); + + { + Lock::CollectionLock lk(&opCtx, _nss, MODE_X); + WriteUnitOfWork wuow(&opCtx); + ASSERT_OK(_db->dropCollection(&opCtx, _nss)); + wuow.commit(); + ASSERT_TRUE(entry->isDropped()); + } + } + +private: + IndexCatalog* _catalog; + Collection* _coll; + Database* _db; +}; + /** * Test for IndexCatalog::refreshEntry(). */ @@ -187,6 +236,7 @@ public: IndexCatalogTests() : Suite("indexcatalogtests") {} void setupTests() { add<IndexIteratorTests>(); + add<IndexCatalogEntryDroppedTest>(); add<RefreshEntry>(); } }; |