diff options
author | Benety Goh <benety@mongodb.com> | 2015-02-11 13:30:37 -0500 |
---|---|---|
committer | Benety Goh <benety@mongodb.com> | 2015-02-11 14:43:27 -0500 |
commit | acf726499561a6ed34486bd4efcbf615405f93f8 (patch) | |
tree | b205974bd88542ce51b55c96b7dc04015150e2eb | |
parent | f2ddb7c3c2cf63faaa4eef796ee76e7342d1e82f (diff) | |
download | mongo-acf726499561a6ed34486bd4efcbf615405f93f8.tar.gz |
SERVER-17163 cancel chunk migration on the primary when the node is stepped down
-rw-r--r-- | src/mongo/s/d_migrate.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/mongo/s/d_migrate.cpp b/src/mongo/s/d_migrate.cpp index 2c79a6243c4..b492c0e8b18 100644 --- a/src/mongo/s/d_migrate.cpp +++ b/src/mongo/s/d_migrate.cpp @@ -61,6 +61,7 @@ #include "mongo/db/pagefault.h" #include "mongo/db/query/internal_plans.h" #include "mongo/db/range_deleter_service.h" +#include "mongo/db/repl/is_master.h" #include "mongo/db/repl/oplog.h" #include "mongo/db/repl/replication_server_status.h" #include "mongo/db/repl/rs.h" @@ -1632,6 +1633,15 @@ namespace mongo { { // 0. copy system.namespaces entry if collection doesn't already exist Client::WriteContext ctx( ns ); + + if (!isMasterNs(ns.c_str())) { + errmsg = str::stream() << "Not primary during migration: " << ns + << ": checking if collection exists"; + warning() << errmsg; + state = FAIL; + return; + } + // Only copy if ns doesn't already exist Database* db = ctx.ctx().db(); Collection* collection = db->getCollection( ns ); @@ -1670,6 +1680,13 @@ namespace mongo { for ( unsigned i=0; i<all.size(); i++ ) { BSONObj idx = all[i]; Client::WriteContext ctx( ns ); + if (!isMasterNs(ns.c_str())) { + errmsg = str::stream() << "Not primary during migration: " << ns; + warning() << errmsg; + state = FAIL; + return; + } + Database* db = ctx.ctx().db(); Collection* collection = db->getCollection( ns ); if ( !collection ) { |