summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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");