0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-11-30 09:06:21 +01:00

Check --pairwith peer spec against local.sources on startup

This commit is contained in:
Aaron 2009-03-23 11:38:22 -04:00
parent ff54da9dde
commit a1a76f96bf

View File

@ -550,6 +550,34 @@ namespace mongo {
else { else {
massert("--only requires use of --source", dashDashOnly.empty()); massert("--only requires use of --source", dashDashOnly.empty());
} }
if ( replPair ) {
const string &remote = replPair->remote;
setClient( "local.sources" );
// --pairwith host specified.
// check that no items are in sources other than that
// add if missing
auto_ptr<Cursor> c = findTableScan("local.sources", BSONObj());
int n = 0;
while ( c->ok() ) {
n++;
ReplSource tmp(c->current());
if ( tmp.hostName != remote ) {
log() << "E10003 pairwith " << remote << " != " << tmp.hostName << " from local.sources collection" << endl;
log() << "terminating after 30 seconds" << endl;
sleepsecs(30);
dbexit(18);
}
c->advance();
}
uassert( "E10002 local.sources collection corrupt?", n<2 );
if ( n == 0 ) {
// source missing. add.
ReplSource s;
s.hostName = remote;
s.save();
}
}
setClient("local.sources"); setClient("local.sources");
auto_ptr<Cursor> c = findTableScan("local.sources", BSONObj()); auto_ptr<Cursor> c = findTableScan("local.sources", BSONObj());