mirror of
https://github.com/mongodb/mongo.git
synced 2024-12-01 09:32:32 +01:00
allow reconfig on secondary on startup
This commit is contained in:
parent
34c0970db0
commit
6c4b677fcd
@ -59,6 +59,7 @@ namespace mongo {
|
||||
int slavedelay;
|
||||
|
||||
set<string> discoveredSeeds;
|
||||
BSONObj reconfig;
|
||||
|
||||
ReplSettings()
|
||||
: slave(NotSlave) , master(false) , fastsync() , autoresync(false), slavedelay(), discoveredSeeds() {
|
||||
|
@ -17,6 +17,7 @@
|
||||
#include "pch.h"
|
||||
#include "../cmdline.h"
|
||||
#include "../commands.h"
|
||||
#include "../repl.h"
|
||||
#include "health.h"
|
||||
#include "rs.h"
|
||||
#include "rs_config.h"
|
||||
@ -138,10 +139,22 @@ namespace mongo {
|
||||
}
|
||||
private:
|
||||
bool _run(const string& , BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool fromRepl) {
|
||||
if( !check(errmsg, result) )
|
||||
if( cmdObj["replSetReconfig"].type() != Object ) {
|
||||
errmsg = "no configuration specified";
|
||||
return false;
|
||||
}
|
||||
|
||||
bool force = cmdObj.hasField("force") && cmdObj["force"].trueValue();
|
||||
if( force && !theReplSet ) {
|
||||
replSettings.reconfig = cmdObj["replSetReconfig"].Obj().getOwned();
|
||||
result.append("msg", "will try this config momentarily, try running rs.conf() again in a few seconds");
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( !check(errmsg, result) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if( !force && !theReplSet->box.getState().primary() ) {
|
||||
errmsg = "replSetReconfig command must be sent to the current replica set primary.";
|
||||
return false;
|
||||
@ -159,11 +172,6 @@ namespace mongo {
|
||||
}
|
||||
}
|
||||
|
||||
if( cmdObj["replSetReconfig"].type() != Object ) {
|
||||
errmsg = "no configuration specified";
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
ReplSetConfig newConfig(cmdObj["replSetReconfig"].Obj(), force);
|
||||
|
||||
|
@ -566,6 +566,16 @@ namespace mongo {
|
||||
}
|
||||
}
|
||||
|
||||
if (!replSettings.reconfig.isEmpty()) {
|
||||
try {
|
||||
configs.push_back(ReplSetConfig(replSettings.reconfig, true));
|
||||
}
|
||||
catch( DBException& re) {
|
||||
log() << "couldn't load reconfig: " << re.what() << endl;
|
||||
replSettings.reconfig = BSONObj();
|
||||
}
|
||||
}
|
||||
|
||||
int nok = 0;
|
||||
int nempty = 0;
|
||||
for( vector<ReplSetConfig>::iterator i = configs.begin(); i != configs.end(); i++ ) {
|
||||
|
@ -22,7 +22,7 @@ var wait = function(f) {
|
||||
}
|
||||
|
||||
var reconnect = function(a) {
|
||||
wait(function() {
|
||||
wait(function() {
|
||||
try {
|
||||
a.getDB("foo").bar.stats();
|
||||
return true;
|
||||
@ -59,7 +59,7 @@ while (count < 10 && result.ok != 1) {
|
||||
count++;
|
||||
sleep(2000);
|
||||
result = admin.runCommand({replSetInitiate : config});
|
||||
}
|
||||
}
|
||||
|
||||
assert(result.ok, tojson(result));
|
||||
assert.soon(function() { result = false;
|
||||
@ -110,11 +110,11 @@ while (status.members[1].state != 2 && count < 200) {
|
||||
printjson(status);
|
||||
}
|
||||
assert(!status.members[1].errmsg || !status.members[1].errmsg.match("^initial sync cloning db"));
|
||||
|
||||
|
||||
sleep(1000);
|
||||
|
||||
// disconnection could happen here
|
||||
try {
|
||||
try {
|
||||
status = admin.runCommand({replSetGetStatus : 1});
|
||||
}
|
||||
catch (e) {
|
||||
@ -124,3 +124,36 @@ while (status.members[1].state != 2 && count < 200) {
|
||||
}
|
||||
|
||||
assert.eq(status.members[1].state, 2);
|
||||
|
||||
print("restart member with a different port and make it a new set");
|
||||
try {
|
||||
p.getDB("admin").runCommand({shutdown:1});
|
||||
}
|
||||
catch(e) {
|
||||
print("good, shutting down: " +e);
|
||||
}
|
||||
sleep(10000);
|
||||
|
||||
pargs = new MongodRunner( ports[ 2 ], basePath + "-p", false, false,
|
||||
["--replSet", basename, "--oplogSize", 2],
|
||||
{no_bind : true} );
|
||||
p = pargs.start(true);
|
||||
|
||||
printjson(p.getDB("admin").runCommand({replSetGetStatus:1}));
|
||||
|
||||
p.getDB("admin").runCommand({replSetReconfig : {
|
||||
_id : basename,
|
||||
members : [{_id:0, host : hostname+":"+ports[2]}]
|
||||
}, force : true});
|
||||
|
||||
print("start waiting for primary...");
|
||||
assert.soon(function() {
|
||||
try {
|
||||
return p.getDB("admin").runCommand({isMaster : 1}).ismaster;
|
||||
}
|
||||
catch(e) {
|
||||
print(e);
|
||||
}
|
||||
return false;
|
||||
}, "waiting for master", 60000);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user