summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenety Goh <benety@mongodb.com>2015-02-04 17:29:57 -0500
committerBenety Goh <benety@mongodb.com>2015-02-05 11:29:31 -0500
commitd4ab26fcfb6d4dc64d7067fd0b5ba08090cf5c59 (patch)
tree7fd0193685ade961c21ac2978cdfd6636db87f07
parent9399c2c04c0fcfa3ab1b2150c62ff75682d116a2 (diff)
downloadmongo-d4ab26fcfb6d4dc64d7067fd0b5ba08090cf5c59.tar.gz
SERVER-17179 check for primary step down in cloner
-rw-r--r--src/mongo/db/cloner.cpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/mongo/db/cloner.cpp b/src/mongo/db/cloner.cpp
index d4a6d892604..5e691f3b4c9 100644
--- a/src/mongo/db/cloner.cpp
+++ b/src/mongo/db/cloner.cpp
@@ -58,7 +58,9 @@
#include "mongo/db/repl/replication_coordinator_global.h"
#include "mongo/db/server_parameters.h"
#include "mongo/db/storage_options.h"
+#include "mongo/util/assert_util.h"
#include "mongo/util/log.h"
+#include "mongo/util/mongoutils/str.h"
namespace mongo {
@@ -124,6 +126,11 @@ namespace mongo {
// XXX: can probably take dblock instead
scoped_ptr<ScopedTransaction> scopedXact(new ScopedTransaction(txn, MODE_X));
scoped_ptr<Lock::GlobalWrite> globalWriteLock(new Lock::GlobalWrite(txn->lockState()));
+ uassert(ErrorCodes::NotMaster,
+ str::stream() << "Not primary while cloning collection " << from_collection.ns()
+ << " to " << to_collection.ns(),
+ !logForRepl ||
+ repl::getGlobalReplicationCoordinator()->canAcceptWritesForDatabase(_dbName));
// Make sure database still exists after we resume from the temp release
Database* db = dbHolder().openDb(txn, _dbName);
@@ -278,6 +285,13 @@ namespace mongo {
_conn->query(stdx::function<void(DBClientCursorBatchIterator &)>(f), from_collection,
query, 0, options);
}
+
+ uassert(ErrorCodes::NotMaster,
+ str::stream() << "Not primary while cloning collection " << from_collection.ns()
+ << " to " << to_collection.ns() << " with filter "
+ << query.toString(),
+ !logForRepl ||
+ repl::getGlobalReplicationCoordinator()->canAcceptWritesForDatabase(toDBName));
}
void Cloner::copyIndexes(OperationContext* txn,
@@ -305,6 +319,13 @@ namespace mongo {
}
}
+ uassert(ErrorCodes::NotMaster,
+ str::stream() << "Not primary while copying indexes from " << from_collection.ns()
+ << " to " << to_collection.ns() << " (Cloner)",
+ !logForRepl ||
+ repl::getGlobalReplicationCoordinator()->canAcceptWritesForDatabase(toDBName));
+
+
if (indexesToBuild.empty())
return;
@@ -368,6 +389,11 @@ namespace mongo {
ScopedTransaction transaction(txn, MODE_IX);
Lock::DBLock dbWrite(txn->lockState(), dbname, MODE_X);
+ uassert(ErrorCodes::NotMaster,
+ str::stream() << "Not primary while copying collection " << ns << " (Cloner)",
+ !logForRepl ||
+ repl::getGlobalReplicationCoordinator()->canAcceptWritesForDatabase(dbname));
+
Database* db = dbHolder().openDb(txn, dbname);
// config
@@ -536,6 +562,12 @@ namespace mongo {
}
}
+ uassert(ErrorCodes::NotMaster,
+ str::stream() << "Not primary while cloning database " << opts.fromDB
+ << " (after getting list of collections to clone)",
+ !opts.logForRepl ||
+ repl::getGlobalReplicationCoordinator()->canAcceptWritesForDatabase(toDBName));
+
if ( opts.syncData ) {
for ( list<BSONObj>::iterator i=toClone.begin(); i != toClone.end(); i++ ) {
BSONObj collection = *i;