diff options
author | Eric Milkie <milkie@10gen.com> | 2013-02-26 20:01:12 -0500 |
---|---|---|
committer | Eric Milkie <milkie@10gen.com> | 2013-03-11 11:15:02 -0400 |
commit | c77acec063b7319a2e2bb4d304cb3d5abb563c29 (patch) | |
tree | 100729d5b80a3d30e675f7eb8ac4235e7fae5263 | |
parent | 753dc84327d166c2973d268d5c6f05fef64195bb (diff) | |
download | mongo-c77acec063b7319a2e2bb4d304cb3d5abb563c29.tar.gz |
SERVER-7772 separate out Sync class
-rw-r--r-- | src/mongo/SConscript | 1 | ||||
-rw-r--r-- | src/mongo/db/oplog.cpp | 57 | ||||
-rw-r--r-- | src/mongo/db/oplog.h | 15 | ||||
-rw-r--r-- | src/mongo/db/repl/rs_sync.h | 1 | ||||
-rw-r--r-- | src/mongo/db/repl/sync.cpp | 86 | ||||
-rw-r--r-- | src/mongo/db/repl/sync.h | 40 |
6 files changed, 128 insertions, 72 deletions
diff --git a/src/mongo/SConscript b/src/mongo/SConscript index 4a691f57d6a..87e99e7b7b1 100644 --- a/src/mongo/SConscript +++ b/src/mongo/SConscript @@ -380,6 +380,7 @@ serverOnlyFiles = [ "db/curop.cpp", "db/repl/bgsync.cpp", "db/repl/master_slave.cpp", "db/repl/finding_start_cursor.cpp", + "db/repl/sync.cpp", "db/oplog.cpp", "db/prefetch.cpp", "db/repl_block.cpp", diff --git a/src/mongo/db/oplog.cpp b/src/mongo/db/oplog.cpp index 54dfae8c27e..e4d1ace9bef 100644 --- a/src/mongo/db/oplog.cpp +++ b/src/mongo/db/oplog.cpp @@ -424,63 +424,6 @@ namespace mongo { verify( !(q != t) ); } } testoptime; - - void Sync::setHostname(const string& hostname) { - hn = hostname; - } - - BSONObj Sync::getMissingDoc(const BSONObj& o) { - OplogReader missingObjReader; - const char *ns = o.getStringField("ns"); - - // capped collections - NamespaceDetails *nsd = nsdetails(ns); - if ( nsd && nsd->isCapped() ) { - log() << "replication missing doc, but this is okay for a capped collection (" << ns << ")" << endl; - return BSONObj(); - } - - uassert(15916, str::stream() << "Can no longer connect to initial sync source: " << hn, missingObjReader.connect(hn)); - - // might be more than just _id in the update criteria - BSONObj query = BSONObjBuilder().append(o.getObjectField("o2")["_id"]).obj(); - BSONObj missingObj; - try { - missingObj = missingObjReader.findOne(ns, query); - } catch(DBException& e) { - log() << "replication assertion fetching missing object: " << e.what() << endl; - throw; - } - - return missingObj; - } - - bool Sync::shouldRetry(const BSONObj& o) { - // should already have write lock - const char *ns = o.getStringField("ns"); - Client::Context ctx(ns); - - // we don't have the object yet, which is possible on initial sync. get it. - log() << "replication info adding missing object" << endl; // rare enough we can log - - BSONObj missingObj = getMissingDoc(o); - - if( missingObj.isEmpty() ) { - log() << "replication missing object not found on source. presumably deleted later in oplog" << endl; - log() << "replication o2: " << o.getObjectField("o2").toString() << endl; - log() << "replication o firstfield: " << o.getObjectField("o").firstElementFieldName() << endl; - - return false; - } - else { - DiskLoc d = theDataFileMgr.insert(ns, (void*) missingObj.objdata(), missingObj.objsize()); - uassert(15917, "Got bad disk location when attempting to insert", !d.isNull()); - - LOG(1) << "replication inserted missing doc: " << missingObj.toString() << endl; - return true; - } - } - /** @param fromRepl false if from ApplyOpsCmd @return true if was and update should have happened and the document DNE. see replset initial sync code. */ diff --git a/src/mongo/db/oplog.h b/src/mongo/db/oplog.h index e7539bcba30..8eeebdf4a2c 100644 --- a/src/mongo/db/oplog.h +++ b/src/mongo/db/oplog.h @@ -67,21 +67,6 @@ namespace mongo { void oplogCheckCloseDatabase( Database * db ); - class Sync { - protected: - string hn; - public: - Sync(const string& hostname) : hn(hostname) {} - virtual ~Sync() {} - virtual BSONObj getMissingDoc(const BSONObj& o); - - /** - * If applyOperation_inlock should be called again after an update fails. - */ - virtual bool shouldRetry(const BSONObj& o); - void setHostname(const string& hostname); - }; - /** * take an op and apply locally * used for applying from an oplog diff --git a/src/mongo/db/repl/rs_sync.h b/src/mongo/db/repl/rs_sync.h index 90e48f0c9e5..523f45d1900 100644 --- a/src/mongo/db/repl/rs_sync.h +++ b/src/mongo/db/repl/rs_sync.h @@ -23,6 +23,7 @@ #include "mongo/db/dur.h" #include "mongo/db/jsobj.h" #include "mongo/db/oplog.h" +#include "mongo/db/repl/sync.h" #include "mongo/util/concurrency/thread_pool.h" namespace mongo { diff --git a/src/mongo/db/repl/sync.cpp b/src/mongo/db/repl/sync.cpp new file mode 100644 index 00000000000..dbc48f6ff34 --- /dev/null +++ b/src/mongo/db/repl/sync.cpp @@ -0,0 +1,86 @@ +/** +* 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/>. +*/ + +#include "mongo/db/repl/sync.h" + +#include <string> + +#include "mongo/db/jsobj.h" +#include "mongo/db/client.h" +#include "mongo/db/diskloc.h" +#include "mongo/db/namespace_details.h" +#include "mongo/db/oplogreader.h" +#include "mongo/util/assert_util.h" +#include "mongo/util/log.h" + +namespace mongo { + + void Sync::setHostname(const string& hostname) { + hn = hostname; + } + + BSONObj Sync::getMissingDoc(const BSONObj& o) { + OplogReader missingObjReader; + const char *ns = o.getStringField("ns"); + + // capped collections + NamespaceDetails *nsd = nsdetails(ns); + if ( nsd && nsd->isCapped() ) { + log() << "replication missing doc, but this is okay for a capped collection (" << ns << ")" << endl; + return BSONObj(); + } + + uassert(15916, str::stream() << "Can no longer connect to initial sync source: " << hn, missingObjReader.connect(hn)); + + // might be more than just _id in the update criteria + BSONObj query = BSONObjBuilder().append(o.getObjectField("o2")["_id"]).obj(); + BSONObj missingObj; + try { + missingObj = missingObjReader.findOne(ns, query); + } catch(DBException& e) { + log() << "replication assertion fetching missing object: " << e.what() << endl; + throw; + } + + return missingObj; + } + + bool Sync::shouldRetry(const BSONObj& o) { + // should already have write lock + const char *ns = o.getStringField("ns"); + Client::Context ctx(ns); + + // we don't have the object yet, which is possible on initial sync. get it. + log() << "replication info adding missing object" << endl; // rare enough we can log + + BSONObj missingObj = getMissingDoc(o); + + if( missingObj.isEmpty() ) { + log() << "replication missing object not found on source. presumably deleted later in oplog" << endl; + log() << "replication o2: " << o.getObjectField("o2").toString() << endl; + log() << "replication o firstfield: " << o.getObjectField("o").firstElementFieldName() << endl; + + return false; + } + else { + DiskLoc d = theDataFileMgr.insert(ns, (void*) missingObj.objdata(), missingObj.objsize()); + uassert(15917, "Got bad disk location when attempting to insert", !d.isNull()); + + LOG(1) << "replication inserted missing doc: " << missingObj.toString() << endl; + return true; + } + } +} diff --git a/src/mongo/db/repl/sync.h b/src/mongo/db/repl/sync.h new file mode 100644 index 00000000000..9bf2b87ae99 --- /dev/null +++ b/src/mongo/db/repl/sync.h @@ -0,0 +1,40 @@ +/** +* 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/>. +*/ + +#pragma once + +#include <string> + +#include "mongo/db/jsobj.h" + +namespace mongo { + + class Sync { + protected: + string hn; + public: + Sync(const string& hostname) : hn(hostname) {} + virtual ~Sync() {} + virtual BSONObj getMissingDoc(const BSONObj& o); + + /** + * If applyOperation_inlock should be called again after an update fails. + */ + virtual bool shouldRetry(const BSONObj& o); + void setHostname(const string& hostname); + }; + +} |