summaryrefslogtreecommitdiff
path: root/src/mongo/db/catalog
diff options
context:
space:
mode:
authorGeert Bosch <geert@mongodb.com>2019-02-14 09:50:31 -0500
committerGeert Bosch <geert@mongodb.com>2019-04-16 18:18:21 -0400
commit8914838187ee4124ce5512093109f457d23281b6 (patch)
treee38a62584e9ae042ae2e186d95d524be76a26313 /src/mongo/db/catalog
parenta9f798957c907ec118a635ff4a0cc9a1a55c7114 (diff)
downloadmongo-8914838187ee4124ce5512093109f457d23281b6.tar.gz
SERVER-39517 Only use Collection MODE_X for index creation and drop
Diffstat (limited to 'src/mongo/db/catalog')
-rw-r--r--src/mongo/db/catalog/drop_indexes.cpp8
-rw-r--r--src/mongo/db/catalog/index_build_block.cpp22
-rw-r--r--src/mongo/db/catalog/index_catalog_impl.h2
3 files changed, 9 insertions, 23 deletions
diff --git a/src/mongo/db/catalog/drop_indexes.cpp b/src/mongo/db/catalog/drop_indexes.cpp
index 56143447308..ef6074eaaff 100644
--- a/src/mongo/db/catalog/drop_indexes.cpp
+++ b/src/mongo/db/catalog/drop_indexes.cpp
@@ -200,7 +200,7 @@ Status dropIndexes(OperationContext* opCtx,
const BSONObj& cmdObj,
BSONObjBuilder* result) {
return writeConflictRetry(opCtx, "dropIndexes", nss.db(), [opCtx, &nss, &cmdObj, result] {
- AutoGetDb autoDb(opCtx, nss.db(), MODE_X);
+ AutoGetCollection autoColl(opCtx, nss, MODE_IX, MODE_X);
bool userInitiatedWritesAndNotPrimary = opCtx->writesAreReplicated() &&
!repl::ReplicationCoordinator::get(opCtx)->canAcceptWritesFor(opCtx, nss);
@@ -215,9 +215,9 @@ Status dropIndexes(OperationContext* opCtx,
}
// If db/collection does not exist, short circuit and return.
- Database* db = autoDb.getDb();
- Collection* collection = db ? db->getCollection(opCtx, nss) : nullptr;
- if (!db || !collection) {
+ Database* db = autoColl.getDb();
+ Collection* collection = autoColl.getCollection();
+ if (!collection) {
if (db && ViewCatalog::get(db)->lookup(opCtx, nss.ns())) {
return Status(ErrorCodes::CommandNotSupportedOnView,
str::stream() << "Cannot drop indexes on view " << nss);
diff --git a/src/mongo/db/catalog/index_build_block.cpp b/src/mongo/db/catalog/index_build_block.cpp
index af1bd77af68..46231723f62 100644
--- a/src/mongo/db/catalog/index_build_block.cpp
+++ b/src/mongo/db/catalog/index_build_block.cpp
@@ -50,7 +50,7 @@ IndexCatalogImpl::IndexBuildBlock::IndexBuildBlock(IndexCatalogImpl* catalog,
const NamespaceString& nss,
const BSONObj& spec,
IndexBuildMethod method)
- : _catalog(catalog), _ns(nss.ns()), _spec(spec.getOwned()), _method(method), _entry(nullptr) {}
+ : _catalog(catalog), _nss(nss), _spec(spec.getOwned()), _method(method), _entry(nullptr) {}
void IndexCatalogImpl::IndexBuildBlock::deleteTemporaryTables(OperationContext* opCtx) {
if (_indexBuildInterceptor) {
@@ -137,14 +137,7 @@ void IndexCatalogImpl::IndexBuildBlock::fail(OperationContext* opCtx,
invariant(opCtx->lockState()->inAWriteUnitOfWork());
fassert(17204, collection->ok()); // defensive
- NamespaceString ns(_indexNamespace);
- // TODO(SERVER-39520): Once createCollection does not need database IX lock, 'system.views' will
- // be no longer a special case.
- if (ns.coll().startsWith(NamespaceString::kSystemDotViewsCollectionName)) {
- invariant(opCtx->lockState()->isDbLockedForMode(ns.db(), MODE_IX));
- } else {
- invariant(opCtx->lockState()->isDbLockedForMode(ns.db(), MODE_X));
- }
+ invariant(opCtx->lockState()->isCollectionLockedForMode(_nss, MODE_X));
if (_entry) {
invariant(_catalog->_dropIndex(opCtx, _entry).isOK());
@@ -161,14 +154,7 @@ void IndexCatalogImpl::IndexBuildBlock::success(OperationContext* opCtx, Collect
invariant(opCtx->lockState()->inAWriteUnitOfWork());
fassert(17207, collection->ok());
- NamespaceString ns(_indexNamespace);
- // TODO(SERVER-39520): Once createCollection does not need database IX lock, 'system.views' will
- // be no longer a special case.
- if (ns.coll().startsWith(NamespaceString::kSystemDotViewsCollectionName)) {
- invariant(opCtx->lockState()->isDbLockedForMode(ns.db(), MODE_IX));
- } else {
- invariant(opCtx->lockState()->isDbLockedForMode(ns.db(), MODE_X));
- }
+ invariant(opCtx->lockState()->isCollectionLockedForMode(_nss, MODE_X));
if (_indexBuildInterceptor) {
// An index build should never be completed with writes remaining in the interceptor.
@@ -178,7 +164,7 @@ void IndexCatalogImpl::IndexBuildBlock::success(OperationContext* opCtx, Collect
invariant(_indexBuildInterceptor->areAllConstraintsChecked(opCtx));
}
- log() << "index build: done building index " << _indexName << " on ns " << _ns;
+ log() << "index build: done building index " << _indexName << " on ns " << _nss;
collection->indexBuildSuccess(opCtx, _entry);
diff --git a/src/mongo/db/catalog/index_catalog_impl.h b/src/mongo/db/catalog/index_catalog_impl.h
index 05d790b46b3..f7736b642fa 100644
--- a/src/mongo/db/catalog/index_catalog_impl.h
+++ b/src/mongo/db/catalog/index_catalog_impl.h
@@ -298,7 +298,7 @@ public:
private:
IndexCatalogImpl* const _catalog;
- const std::string _ns;
+ const NamespaceString& _nss;
BSONObj _spec;
IndexBuildMethod _method;