diff options
Diffstat (limited to 'src/mongo')
-rw-r--r-- | src/mongo/db/commands/create_indexes.cpp | 16 | ||||
-rw-r--r-- | src/mongo/s/d_migrate.cpp | 10 |
2 files changed, 26 insertions, 0 deletions
diff --git a/src/mongo/db/commands/create_indexes.cpp b/src/mongo/db/commands/create_indexes.cpp index 4ccf4974c6f..635de8a5fc5 100644 --- a/src/mongo/db/commands/create_indexes.cpp +++ b/src/mongo/db/commands/create_indexes.cpp @@ -229,6 +229,16 @@ namespace mongo { // that day, to avoid data corruption due to lack of index cleanup. txn->recoveryUnit()->commitAndRestart(); dbLock.relockWithMode(MODE_X); + if (!fromRepl && + !repl::getGlobalReplicationCoordinator()->canAcceptWritesForDatabase( + dbname)) { + return appendCommandStatus( + result, + Status(ErrorCodes::NotMaster, str::stream() + << "Not primary while creating background indexes in " + << ns.ns() << ": cleaning up index build failure due to " + << e.toString())); + } } catch (...) { std::terminate(); @@ -240,6 +250,12 @@ namespace mongo { if (indexer.getBuildInBackground()) { txn->recoveryUnit()->commitAndRestart(); dbLock.relockWithMode(MODE_X); + uassert(ErrorCodes::NotMaster, + str::stream() << "Not primary while completing index build in " << dbname, + fromRepl || + repl::getGlobalReplicationCoordinator()->canAcceptWritesForDatabase( + dbname)); + Database* db = dbHolder().get(txn, ns.db()); uassert(28551, "database dropped during index build", db); uassert(28552, "collection dropped during index build", diff --git a/src/mongo/s/d_migrate.cpp b/src/mongo/s/d_migrate.cpp index 22611714860..fd10272b316 100644 --- a/src/mongo/s/d_migrate.cpp +++ b/src/mongo/s/d_migrate.cpp @@ -1903,6 +1903,16 @@ namespace mongo { { // 0. copy system.namespaces entry if collection doesn't already exist Client::WriteContext ctx(txn, ns ); + + if (!repl::getGlobalReplicationCoordinator()->canAcceptWritesForDatabase( + nsToDatabaseSubstring(ns))) { + errmsg = str::stream() << "Not primary during migration: " << ns + << ": checking if collection exists"; + warning() << errmsg; + setState(FAIL); + return; + } + // Only copy if ns doesn't already exist Database* db = ctx.ctx().db(); Collection* collection = db->getCollection( ns ); |