summaryrefslogtreecommitdiff
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
parent3dd69dcf53681c19e4e755175b2f374816199883 (diff)
downloadmongo-f411d9d96ce7ff0c7802e99f0b28129ac16b1f70.tar.gz
SERVER-17205 check for primary step down after obtaining write lock
(cherry picked from commit d6ad41d4b7ef7bee4a28bc4c7e1013f1319d63c1)
-rw-r--r--src/mongo/db/commands/create_indexes.cpp16
-rw-r--r--src/mongo/s/d_migrate.cpp10
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 );