From a1a76f96bf44955e8f5bb5cc0a698ba624aa7ba3 Mon Sep 17 00:00:00 2001 From: Aaron Date: Mon, 23 Mar 2009 11:38:22 -0400 Subject: [PATCH] Check --pairwith peer spec against local.sources on startup --- db/repl.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/db/repl.cpp b/db/repl.cpp index 536045052ed..de035fa5d10 100644 --- a/db/repl.cpp +++ b/db/repl.cpp @@ -550,6 +550,34 @@ namespace mongo { else { 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 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"); auto_ptr c = findTableScan("local.sources", BSONObj());