Skip to content

Commit

Permalink
SERVER-38548 dropping an index removes catalog entry immediately and …
Browse files Browse the repository at this point in the history
…defers ident drop

If drop-pending idents are supported by the storage engine, catalog::openCatalog() will not need
to rebuild the indexes on rollback/recovery. Instead, the storage engine will manage the removal
of the idents from disk.
  • Loading branch information
benety committed Jan 1, 2019
1 parent 46dd8e0 commit 671f529
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/mongo/db/storage/kv/SConscript
Expand Up @@ -27,6 +27,7 @@ env.Library(
'$BUILD_DIR/mongo/db/namespace_string',
'$BUILD_DIR/mongo/db/storage/bson_collection_catalog_entry',
'$BUILD_DIR/mongo/db/catalog/uuid_catalog',
'kv_drop_pending_ident_reaper',
'kv_prefix',
],
)
Expand Down
20 changes: 17 additions & 3 deletions src/mongo/db/storage/kv/kv_collection_catalog_entry.cpp
Expand Up @@ -30,16 +30,21 @@
* it in the license file.
*/

#include <memory>
#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kStorage

#include "mongo/platform/basic.h"

#include "mongo/db/storage/kv/kv_collection_catalog_entry.h"

#include <memory>

#include "mongo/db/catalog/uuid_catalog.h"
#include "mongo/db/index/index_descriptor.h"
#include "mongo/db/storage/kv/kv_catalog.h"
#include "mongo/db/storage/kv/kv_catalog_feature_tracker.h"
#include "mongo/db/storage/kv/kv_engine.h"
#include "mongo/db/storage/kv/kv_storage_engine.h"
#include "mongo/util/log.h"

namespace mongo {

Expand Down Expand Up @@ -84,11 +89,20 @@ class KVCollectionCatalogEntry::RemoveIndexChange : public RecoveryUnit::Change
_ident(ident.toString()) {}

virtual void rollback() {}
virtual void commit(boost::optional<Timestamp>) {
virtual void commit(boost::optional<Timestamp> commitTimestamp) {
// Intentionally ignoring failure here. Since we've removed the metadata pointing to the
// index, we should never see it again anyway.
// TODO(SERVER-38800): Remove special case for _id index. The rollback process is unable to
// fix collection counts and currently relies on catalog::openCatalog() to update the
// collection count as it rebuilds missing indexes. Removing the ident for the _id index
// immediately ensures that we have at least one index to rebuild coming out of rollback.
auto engine = _cce->_engine;
{
auto storageEngine = engine->getStorageEngine();
if (storageEngine->supportsPendingDrops() && commitTimestamp && _indexName != "_id_") {
log() << "Deferring ident drop for " << _ident << " (" << _indexNss
<< ") with commit timestamp: " << commitTimestamp->toBSON();
engine->addDropPendingIdent(*commitTimestamp, _indexNss, _ident);
} else {
auto kvEngine = engine->getEngine();
MONGO_COMPILER_VARIABLE_UNUSED auto status = kvEngine->dropIdent(_opCtx, _ident);
}
Expand Down

0 comments on commit 671f529

Please sign in to comment.