2010-04-14 17:30:23 -04:00
|
|
|
/**
|
|
|
|
|
* Copyright (C) 2008 10gen Inc.
|
|
|
|
|
*
|
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU Affero General Public License, version 3,
|
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
2010-04-27 15:27:52 -04:00
|
|
|
#include "pch.h"
|
2010-04-14 17:30:23 -04:00
|
|
|
#include "../cmdline.h"
|
|
|
|
|
#include "health.h"
|
|
|
|
|
#include "../commands.h"
|
2010-04-23 17:35:05 -04:00
|
|
|
#include "replset.h"
|
|
|
|
|
#include "rs_config.h"
|
2010-04-14 17:30:23 -04:00
|
|
|
|
|
|
|
|
namespace mongo {
|
|
|
|
|
|
2010-04-22 16:17:18 -04:00
|
|
|
class CmdReplSetInitiate : public Command {
|
|
|
|
|
public:
|
2010-04-23 15:50:49 -04:00
|
|
|
virtual LockType locktype() const { return WRITE; }
|
|
|
|
|
virtual bool slaveOk() const { return true; }
|
2010-04-23 16:41:56 -04:00
|
|
|
virtual bool adminOnly() const { return true; }
|
2010-04-22 16:17:18 -04:00
|
|
|
virtual bool logTheOp() { return false; }
|
|
|
|
|
CmdReplSetInitiate() : Command("replSetInitiate") { }
|
2010-04-25 16:13:21 -04:00
|
|
|
virtual void help(stringstream& h) const {
|
|
|
|
|
h << "Initiate/christen a replica set.";
|
|
|
|
|
h << "\nhttp://www.mongodb.org/display/DOCS/Replica+Set+Commands";
|
|
|
|
|
}
|
2010-04-22 16:17:18 -04:00
|
|
|
virtual bool run(const char *ns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool fromRepl) {
|
|
|
|
|
if( !replSet ) {
|
2010-04-22 18:43:37 -04:00
|
|
|
errmsg = "server is not running with --replSet";
|
2010-04-22 16:17:18 -04:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if( theReplSet ) {
|
|
|
|
|
errmsg = "already initialized";
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if( ReplSet::startupStatus == ReplSet::BADCONFIG ) {
|
2010-04-22 18:43:37 -04:00
|
|
|
errmsg = "server already in BADCONFIG state (check logs); not initiating";
|
|
|
|
|
result.append("info", ReplSet::startupStatusMsg);
|
2010-04-22 16:17:18 -04:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if( ReplSet::startupStatus != ReplSet::EMPTYCONFIG ) {
|
|
|
|
|
result.append("startupStatus", ReplSet::startupStatus);
|
|
|
|
|
errmsg = "all seed hosts must be reachable to initiate set";
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-27 14:22:46 -04:00
|
|
|
if( cmdObj["replSetInitiate"].type() != Object ) {
|
|
|
|
|
errmsg = "no configuration specified";
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-23 17:35:05 -04:00
|
|
|
ReplSetConfig newConfig(cmdObj["replSetInitiate"].Obj());
|
|
|
|
|
|
2010-04-27 14:22:46 -04:00
|
|
|
log() << newConfig.toString() << endl;
|
|
|
|
|
|
2010-04-28 08:25:56 -04:00
|
|
|
newConfig.save();
|
2010-04-27 14:37:41 -04:00
|
|
|
|
2010-04-28 08:25:56 -04:00
|
|
|
errmsg = "replsets are not yet implemented. coming soon.";
|
|
|
|
|
return true;
|
2010-04-22 16:17:18 -04:00
|
|
|
}
|
|
|
|
|
} cmdReplSetInitiate;
|
|
|
|
|
|
2010-04-18 12:30:40 -04:00
|
|
|
/* commands in other files:
|
|
|
|
|
replSetHeartbeat - health.cpp
|
2010-04-22 18:43:37 -04:00
|
|
|
*/
|
2010-04-18 12:30:40 -04:00
|
|
|
|
2010-04-14 17:30:23 -04:00
|
|
|
class CmdReplSetGetStatus : public Command {
|
|
|
|
|
public:
|
2010-04-23 15:50:49 -04:00
|
|
|
virtual bool slaveOk() const { return true; }
|
2010-04-23 16:41:56 -04:00
|
|
|
virtual bool adminOnly() const { return true; }
|
2010-04-22 16:17:18 -04:00
|
|
|
virtual bool logTheOp() { return false; }
|
2010-04-23 15:50:49 -04:00
|
|
|
virtual LockType locktype() const { return NONE; }
|
|
|
|
|
virtual void help( stringstream &help ) const {
|
|
|
|
|
help << "Report status of a replica set from the POV of this server\n";
|
|
|
|
|
help << "{ replSetGetStatus : 1 }";
|
2010-04-25 16:13:21 -04:00
|
|
|
help << "\nhttp://www.mongodb.org/display/DOCS/Replica+Set+Commands";
|
2010-04-23 15:50:49 -04:00
|
|
|
}
|
|
|
|
|
|
2010-04-19 21:05:46 -04:00
|
|
|
CmdReplSetGetStatus() : Command("replSetGetStatus", true) { }
|
2010-04-14 17:30:23 -04:00
|
|
|
virtual bool run(const char *ns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool fromRepl) {
|
2010-04-21 21:19:37 -04:00
|
|
|
if( !replSet ) {
|
|
|
|
|
errmsg = "not running with --replSet";
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2010-04-20 12:29:00 -04:00
|
|
|
if( theReplSet == 0 ) {
|
2010-04-23 17:35:05 -04:00
|
|
|
result.append("startupStatus", ReplSet::startupStatus);
|
2010-04-21 17:40:24 -04:00
|
|
|
errmsg = ReplSet::startupStatusMsg.empty() ?
|
2010-04-21 21:19:37 -04:00
|
|
|
errmsg = "replset unknown error 1" : ReplSet::startupStatusMsg;
|
2010-04-20 12:29:00 -04:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
theReplSet->summarizeStatus(result);
|
|
|
|
|
|
2010-04-14 17:30:23 -04:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
} cmdReplSetGetStatus;
|
|
|
|
|
|
2010-04-25 16:13:21 -04:00
|
|
|
class CmdReplSetFreeze : public Command {
|
|
|
|
|
public:
|
|
|
|
|
virtual bool slaveOk() const { return true; }
|
|
|
|
|
virtual bool adminOnly() const { return true; }
|
|
|
|
|
virtual bool logTheOp() { return false; }
|
|
|
|
|
virtual LockType locktype() const { return NONE; }
|
|
|
|
|
virtual void help( stringstream &help ) const {
|
|
|
|
|
help << "Enable / disable failover for the set - locks current primary as primary even if issues occur.\nFor use during system maintenance.\n";
|
|
|
|
|
help << "{ replSetFreeze : <bool> }";
|
|
|
|
|
help << "\nhttp://www.mongodb.org/display/DOCS/Replica+Set+Commands";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CmdReplSetFreeze() : Command("replSetFreeze", true) { }
|
|
|
|
|
virtual bool run(const char *ns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool fromRepl) {
|
|
|
|
|
if( !replSet ) {
|
|
|
|
|
errmsg = "not running with --replSet";
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if( theReplSet == 0 ) {
|
|
|
|
|
result.append("startupStatus", ReplSet::startupStatus);
|
|
|
|
|
errmsg = ReplSet::startupStatusMsg.empty() ?
|
|
|
|
|
errmsg = "replset unknown error 1" : ReplSet::startupStatusMsg;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
errmsg = "not yet implemented"; /*TODO*/
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
} cmdReplSetFreeze;
|
|
|
|
|
|
2010-04-14 17:30:23 -04:00
|
|
|
}
|