diff options
author | Misha Tyulenev <misha.tyulenev@mongodb.com> | 2020-07-21 23:42:09 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-07-22 01:45:22 +0000 |
commit | c0cc8994d2f8343a08928be10873f4ae3220fb45 (patch) | |
tree | b99b2744234a4da1267a83f4c2877640b625ddee /src/mongo/db/catalog | |
parent | d2df671032c1822ac1daef2c2cfc306c9314b21c (diff) | |
download | mongo-c0cc8994d2f8343a08928be10873f4ae3220fb45.tar.gz |
SERVER-49765 fail with MovePrimaryInProgress for dropIndexes, create view, modify view commands
Diffstat (limited to 'src/mongo/db/catalog')
-rw-r--r-- | src/mongo/db/catalog/coll_mod.cpp | 4 | ||||
-rw-r--r-- | src/mongo/db/catalog/database_impl.cpp | 19 | ||||
-rw-r--r-- | src/mongo/db/catalog/drop_indexes.cpp | 30 |
3 files changed, 52 insertions, 1 deletions
diff --git a/src/mongo/db/catalog/coll_mod.cpp b/src/mongo/db/catalog/coll_mod.cpp index 25d9db7db51..ad98c2d9531 100644 --- a/src/mongo/db/catalog/coll_mod.cpp +++ b/src/mongo/db/catalog/coll_mod.cpp @@ -367,6 +367,10 @@ Status _collModInternal(OperationContext* opCtx, } } + if (view) { + Lock::CollectionLock collLock(opCtx, view->viewOn(), MODE_IS); + assertMovePrimaryInProgress(opCtx, view->viewOn()); + } // This can kill all cursors so don't allow running it while a background operation is in // progress. if (coll) { diff --git a/src/mongo/db/catalog/database_impl.cpp b/src/mongo/db/catalog/database_impl.cpp index 7a0e74071ba..bfaf0151fd1 100644 --- a/src/mongo/db/catalog/database_impl.cpp +++ b/src/mongo/db/catalog/database_impl.cpp @@ -62,6 +62,7 @@ #include "mongo/db/repl/drop_pending_collection_reaper.h" #include "mongo/db/repl/oplog.h" #include "mongo/db/repl/replication_coordinator.h" +#include "mongo/db/s/collection_sharding_state.h" #include "mongo/db/s/database_sharding_state.h" #include "mongo/db/s/operation_sharding_state.h" #include "mongo/db/server_options.h" @@ -579,7 +580,6 @@ void DatabaseImpl::_checkCanCreateCollection(OperationContext* opCtx, str::stream() << "Cannot create collection " << nss << " - database is in the process of being dropped.", !_dropPending.load()); - assertMovePrimaryInProgress(opCtx, nss); } Status DatabaseImpl::createView(OperationContext* opCtx, @@ -593,6 +593,22 @@ Status DatabaseImpl::createView(OperationContext* opCtx, NamespaceString viewOnNss(viewName.db(), options.viewOn); _checkCanCreateCollection(opCtx, viewName, options); + + try { + Lock::CollectionLock collLock(opCtx, viewOnNss, MODE_IS); + const auto collDesc = + CollectionShardingState::get(opCtx, viewOnNss)->getCollectionDescription(opCtx); + if (!collDesc.isSharded()) { + assertMovePrimaryInProgress(opCtx, viewOnNss); + } + } catch (const DBException& ex) { + if (ex.toStatus() == ErrorCodes::MovePrimaryInProgress) { + throw; + } else { + LOGV2(4909101, "Error when getting colleciton description", "what"_attr = ex.what()); + } + } + audit::logCreateCollection(&cc(), viewName.toString()); if (viewName.isOplog()) @@ -659,6 +675,7 @@ Collection* DatabaseImpl::createCollection(OperationContext* opCtx, } _checkCanCreateCollection(opCtx, nss, optionsWithUUID); + assertMovePrimaryInProgress(opCtx, nss); audit::logCreateCollection(&cc(), nss.ns()); LOGV2(20320, diff --git a/src/mongo/db/catalog/drop_indexes.cpp b/src/mongo/db/catalog/drop_indexes.cpp index f64d6b3b821..498c9421d1e 100644 --- a/src/mongo/db/catalog/drop_indexes.cpp +++ b/src/mongo/db/catalog/drop_indexes.cpp @@ -43,6 +43,8 @@ #include "mongo/db/op_observer.h" #include "mongo/db/repl/replication_coordinator.h" #include "mongo/db/repl_set_member_in_standalone_mode.h" +#include "mongo/db/s/collection_sharding_state.h" +#include "mongo/db/s/database_sharding_state.h" #include "mongo/db/service_context.h" #include "mongo/db/views/view_catalog.h" #include "mongo/logv2/log.h" @@ -283,6 +285,33 @@ Status dropReadyIndexes(OperationContext* opCtx, return Status::OK(); } +void assertMovePrimaryInProgress(OperationContext* opCtx, const NamespaceString& ns) { + auto dss = DatabaseShardingState::get(opCtx, ns.db()); + auto dssLock = DatabaseShardingState::DSSLock::lockShared(opCtx, dss); + + try { + const auto collDesc = + CollectionShardingState::get(opCtx, ns)->getCollectionDescription(opCtx); + if (!collDesc.isSharded()) { + auto mpsm = dss->getMovePrimarySourceManager(dssLock); + + if (mpsm) { + LOGV2( + 4976500, "assertMovePrimaryInProgress", "movePrimaryNss"_attr = ns.toString()); + + uasserted(ErrorCodes::MovePrimaryInProgress, + "movePrimary is in progress for namespace " + ns.toString()); + } + } + } catch (const DBException& ex) { + if (ex.toStatus() != ErrorCodes::MovePrimaryInProgress) { + LOGV2(4976501, "Error when getting colleciton description", "what"_attr = ex.what()); + return; + } + throw; + } +} + } // namespace Status dropIndexes(OperationContext* opCtx, @@ -400,6 +429,7 @@ Status dropIndexes(OperationContext* opCtx, } if (!abortAgain) { + assertMovePrimaryInProgress(opCtx, nss); break; } } |