summaryrefslogtreecommitdiff
path: root/src/mongo/db/commands/create_indexes.cpp
diff options
context:
space:
mode:
authorBenety Goh <benety@mongodb.com>2015-02-11 12:22:10 -0500
committerRamon Fernandez <ramon@mongodb.com>2015-02-11 16:00:59 -0500
commitf411d9d96ce7ff0c7802e99f0b28129ac16b1f70 (patch)
treed438ef113e02dd5e935848f06f7e1c0e69da337a /src/mongo/db/commands/create_indexes.cpp
parent3dd69dcf53681c19e4e755175b2f374816199883 (diff)
downloadmongo-f411d9d96ce7ff0c7802e99f0b28129ac16b1f70.tar.gz
SERVER-17205 check for primary step down after obtaining write lock
(cherry picked from commit d6ad41d4b7ef7bee4a28bc4c7e1013f1319d63c1)
Diffstat (limited to 'src/mongo/db/commands/create_indexes.cpp')
-rw-r--r--src/mongo/db/commands/create_indexes.cpp16
1 files changed, 16 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",