summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenety Goh <benety@mongodb.com>2015-02-11 09:56:01 -0500
committerBenety Goh <benety@mongodb.com>2015-02-11 15:40:28 -0500
commit4d9728816460fcd7579071c0f64d0c97032a246d (patch)
treef14c5564999b78d299719ab5dbe014ae514c5ce1
parentacf726499561a6ed34486bd4efcbf615405f93f8 (diff)
downloadmongo-4d9728816460fcd7579071c0f64d0c97032a246d.tar.gz
SERVER-16599 do not proceed with copydb/clone if primary steps down
-rw-r--r--src/mongo/db/cloner.cpp26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/mongo/db/cloner.cpp b/src/mongo/db/cloner.cpp
index fa2e9dedafb..744edd8cfb6 100644
--- a/src/mongo/db/cloner.cpp
+++ b/src/mongo/db/cloner.cpp
@@ -48,6 +48,7 @@
#include "mongo/db/jsobj.h"
#include "mongo/db/kill_current_op.h"
#include "mongo/db/namespace_string.h"
+#include "mongo/db/repl/is_master.h"
#include "mongo/db/repl/oplog.h"
#include "mongo/db/repl/oplogreader.h"
#include "mongo/db/pdfile.h"
@@ -147,6 +148,12 @@ namespace mongo {
dbtempreleaseif t( _mayYield );
}
+ uassert(ErrorCodes::NotMaster,
+ str::stream() << "Not primary while cloning collection " << from_collection
+ << " to " << to_collection,
+ !logForRepl ||
+ isMasterNs(to_collection));
+
if ( isindex == false && collection == NULL ) {
collection = context.db()->getCollection( to_collection );
if ( !collection ) {
@@ -250,6 +257,13 @@ namespace mongo {
query, 0, options);
}
+ uassert(ErrorCodes::NotMaster,
+ str::stream() << "Not primary while cloning collection " << from_collection
+ << " to " << to_collection << " with filter "
+ << query.toString(),
+ !logForRepl ||
+ isMasterNs(from_collection));
+
if ( indexesToBuild.size() ) {
for (list<BSONObj>::const_iterator i = indexesToBuild.begin();
i != indexesToBuild.end();
@@ -321,6 +335,11 @@ namespace mongo {
Client::WriteContext ctx(ns);
+ uassert(ErrorCodes::NotMaster,
+ str::stream() << "Not primary while copying collection " << ns << " (Cloner)",
+ !logForRepl ||
+ isMasterNs(ns.c_str()));
+
// config
BSONObj filter = BSON("name" << nss.coll().toString());
list<BSONObj> collList = _conn->getCollectionInfos( dbname, filter);
@@ -466,6 +485,13 @@ namespace mongo {
mayInterrupt( opts.mayBeInterrupted );
dbtempreleaseif r( opts.mayYield );
}
+
+ uassert(ErrorCodes::NotMaster,
+ str::stream() << "Not primary while cloning database " << opts.fromDB
+ << " (after getting list of collections to clone)",
+ !opts.logForRepl ||
+ isMaster(todb.c_str()));
+
BSONObj collection = *i;
LOG(2) << " really will clone: " << collection << endl;
BSONObj options = collection.getObjectField("options");