summaryrefslogtreecommitdiff
path: root/db/repl
diff options
context:
space:
mode:
authorKristina <kristina@10gen.com>2011-01-13 13:30:13 -0500
committerKristina <kristina@10gen.com>2011-01-13 13:31:01 -0500
commit6bf551e90f84fd16a5bd7dccfd2546fb00634b30 (patch)
treeffc35db505941d0842b633ce7f0733e59e6f36fc /db/repl
parente3ae36e0764c1d66b77fb201165c06851ccc237a (diff)
downloadmongo-6bf551e90f84fd16a5bd7dccfd2546fb00634b30.tar.gz
allow duplicate key exceptions in initial sync SERVER-2219
Diffstat (limited to 'db/repl')
-rw-r--r--db/repl/rs_sync.cpp41
1 files changed, 27 insertions, 14 deletions
diff --git a/db/repl/rs_sync.cpp b/db/repl/rs_sync.cpp
index 6cb86ecd9a4..3c7bd2b0910 100644
--- a/db/repl/rs_sync.cpp
+++ b/db/repl/rs_sync.cpp
@@ -56,9 +56,8 @@ namespace mongo {
if( source == 0 ) return false;
const string hn = source->h().toString();
- OpTime ts;
+ OplogReader r;
try {
- OplogReader r;
if( !r.connect(hn) ) {
log() << "replSet initial sync error can't connect to " << hn << " to read " << rsoplog << rsLog;
return false;
@@ -74,9 +73,6 @@ namespace mongo {
}
assert( r.haveCursor() );
- /* we lock outside the loop to avoid the overhead of locking on every operation. server isn't usable yet anyway! */
- writelock lk("");
-
{
if( !r.more() ) {
sethbmsg("replSet initial sync error reading remote oplog");
@@ -100,11 +96,20 @@ namespace mongo {
return false;
}
}
+ }
+ catch(DBException& e) {
+ log() << "replSet initial sync failing: " << e.toString() << rsLog;
+ return false;
+ }
- // todo : use exhaust
- unsigned long long n = 0;
- while( 1 ) {
+ /* we lock outside the loop to avoid the overhead of locking on every operation. */
+ writelock lk("");
+ // todo : use exhaust
+ OpTime ts;
+ unsigned long long n = 0;
+ while( 1 ) {
+ try {
if( !r.more() )
break;
BSONObj o = r.nextSafe(); /* note we might get "not master" at some point */
@@ -139,12 +144,20 @@ namespace mongo {
log() << "replSet initialSyncOplogApplication " << n << rsLog;
}
}
- }
- catch(DBException& e) {
- if( ts <= minValid ) {
- // didn't make it far enough
- log() << "replSet initial sync failing, error applying oplog " << e.toString() << rsLog;
- return false;
+ catch (DBException& e) {
+ if( e.getCode() == 11000 || e.getCode() == 11001 ) {
+ // skip duplicate key exceptions
+ continue;
+ }
+
+ if( ts <= minValid ) {
+ // didn't make it far enough
+ log() << "replSet initial sync failing, error applying oplog " << e.toString() << rsLog;
+ return false;
+ }
+
+ // otherwise, whatever
+ break;
}
}
return true;