Files
mongo/db/repl/replset.cpp

71 lines
2.3 KiB
C++
Raw Normal View History

2010-04-13 13:22:42 -04:00
/**
2010-04-14 17:25:03 -04:00
* Copyright (C) 2008 10gen Inc.
2010-04-13 13:22:42 -04:00
*
* 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/>.
*/
#include "stdafx.h"
#include "../cmdline.h"
2010-04-13 17:38:15 -04:00
#include "replset.h"
2010-04-13 13:22:42 -04:00
namespace mongo {
2010-04-13 17:38:15 -04:00
ReplSet *theReplSet = 0;
2010-04-14 17:25:03 -04:00
ReplSet::ReplSet(string cfgString) {
const char *p = cfgString.c_str();
const char *q = strchr(p, '/');
uassert(13093, "bad --replset config string format is: <setname>/<seedhost1>,<seedhost2>[,...]", q != 0 && p != q);
2010-04-15 19:12:28 -04:00
_name = string(p, q-p);
2010-04-14 17:25:03 -04:00
set<RemoteServer> temp;
2010-04-15 19:12:28 -04:00
vector<RemoteServer> *seeds = new vector<RemoteServer>;
2010-04-14 17:25:03 -04:00
while( 1 ) {
p = q + 1;
q = strchr(p, ',');
if( q == 0 ) q = strchr(p,0);
uassert(13094, "bad --replset config string", p != q);
const char *colon = strchr(p, ':');
RemoteServer m;
if( colon && colon < q ) {
int port = atoi(colon+1);
uassert(13095, "bad --replset port #", port > 0);
m = RemoteServer(string(p,colon-p),port);
}
else {
// no port specified.
m = RemoteServer(string(p,q-p));
}
2010-04-15 19:12:28 -04:00
uassert(13096, "bad --replset config string - dups?", temp.count(m) == 0 ); // these uasserts leak seeds but that's ok
2010-04-14 17:25:03 -04:00
temp.insert(m);
2010-04-15 19:12:28 -04:00
seeds->push_back(m);
2010-04-14 17:25:03 -04:00
if( *q == 0 )
break;
}
2010-04-14 20:50:15 -04:00
2010-04-15 19:12:28 -04:00
_seeds = seeds;
2010-04-18 12:30:40 -04:00
startHealthThreads();
2010-04-14 17:25:03 -04:00
}
2010-04-13 13:22:42 -04:00
/* called at initialization */
bool startReplSets() {
2010-04-14 17:25:03 -04:00
assert( theReplSet == 0 );
if( cmdLine.replSet.empty() )
return false;
theReplSet = new ReplSet(cmdLine.replSet);
2010-04-13 13:22:42 -04:00
return false;
}
}