Skip to content
Permalink
Browse files

SERVER-42357 Add additional state to the IndexCatalogEntry to track w…

…hen it is dropped
  • Loading branch information
GWlodarek authored and evergreen committed Sep 13, 2019
1 parent 268ab18 commit 4acaa3f536fe2f3fc2355c7a3e860663201c6f37
@@ -90,6 +90,9 @@ class IndexCatalogEntry {

virtual void setIsReady(const bool newIsReady) = 0;

virtual void setDropped() = 0;
virtual bool isDropped() const = 0;

// --

/**
@@ -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;
@@ -113,6 +113,14 @@ class IndexCatalogEntryImpl : public IndexCatalogEntry {

void setIsReady(bool newIsReady) final;

void setDropped() final {
_isDropped.store(true);
}

bool isDropped() const final {
return _isDropped.load();
}

// --

/**
@@ -199,8 +207,9 @@ class IndexCatalogEntryImpl : public IndexCatalogEntry {

// 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
@@ -881,6 +881,7 @@ class IndexRemoveChange final : public RecoveryUnit::Change {
// 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());
}

@@ -108,6 +108,55 @@ class IndexIteratorTests {
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 @@ class IndexCatalogTests : public Suite {
IndexCatalogTests() : Suite("indexcatalogtests") {}
void setupTests() {
add<IndexIteratorTests>();
add<IndexCatalogEntryDroppedTest>();
add<RefreshEntry>();
}
};

0 comments on commit 4acaa3f

Please sign in to comment.
You can’t perform that action at this time.