diff options
author | dwight <dwight@10gen.com> | 2011-12-16 18:18:47 -0500 |
---|---|---|
committer | dwight <dwight@10gen.com> | 2011-12-16 18:18:47 -0500 |
commit | f4512aa38324ee0541d51bf003ac93fe6866e84e (patch) | |
tree | 79800f50453eded6f2ee1050656041b601a9cc89 | |
parent | 103a1e6019c0e0d034aed178a8fb062fc1383f52 (diff) | |
download | mongo-f4512aa38324ee0541d51bf003ac93fe6866e84e.tar.gz |
copying of OplogReaders was scaring me
-rwxr-xr-x | db/db.vcxproj | 2 | ||||
-rw-r--r-- | db/oplogreader.h | 17 | ||||
-rw-r--r-- | db/repl/rs.h | 6 | ||||
-rw-r--r-- | db/repl/rs_sync.cpp | 11 |
4 files changed, 15 insertions, 21 deletions
diff --git a/db/db.vcxproj b/db/db.vcxproj index 9237aa4c383..21b2369a0d5 100755 --- a/db/db.vcxproj +++ b/db/db.vcxproj @@ -127,7 +127,7 @@ <ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>..\..\js\src;..\third_party\pcre-7.4;c:\boost;\boost</AdditionalIncludeDirectories>
- <PreprocessorDefinitions>CLC;MONGO_EXPOSE_MACROS;OLDJS;STATIC_JS_API;XP_WIN;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;HAVE_CONFIG_H;;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <PreprocessorDefinitions>MONGO_EXPOSE_MACROS;OLDJS;STATIC_JS_API;XP_WIN;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;HAVE_CONFIG_H;;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<PrecompiledHeader>Use</PrecompiledHeader>
diff --git a/db/oplogreader.h b/db/oplogreader.h index a1b1c756765..6efd1469c01 100644 --- a/db/oplogreader.h +++ b/db/oplogreader.h @@ -15,15 +15,9 @@ namespace mongo { shared_ptr<DBClientConnection> _conn; shared_ptr<DBClientCursor> cursor; public: - - OplogReader() { - } - ~OplogReader() { - } - - void resetCursor() { - cursor.reset(); - } + OplogReader() { } + ~OplogReader() { } + void resetCursor() { cursor.reset(); } void resetConnection() { cursor.reset(); _conn.reset(); @@ -32,7 +26,6 @@ namespace mongo { BSONObj findOne(const char *ns, const Query& q) { return conn()->findOne(ns, q, 0, QueryOption_SlaveOk); } - BSONObj getLastOp(const char *ns) { return findOne(ns, Query().sort(reverseNaturalObj)); } @@ -42,7 +35,6 @@ namespace mongo { bool connect(const BSONObj& rid, const int from, const string& to); - void tailCheck() { if( cursor.get() && cursor->isDead() ) { log() << "repl: old cursor isDead, will initiate a new one" << endl; @@ -117,11 +109,8 @@ namespace mongo { if( cursor.get() ) cursor->peek(v,n); } - BSONObj nextSafe() { return cursor->nextSafe(); } - BSONObj next() { return cursor->next(); } - void putBack(BSONObj op) { cursor->putBack(op); } private: diff --git a/db/repl/rs.h b/db/repl/rs.h index be07c94731d..8296fd0170b 100644 --- a/db/repl/rs.h +++ b/db/repl/rs.h @@ -131,8 +131,8 @@ namespace mongo { }; class GhostSync : public task::Server { - struct GhostSlave { - GhostSlave() : last(0), slave(0), init(false) {} + struct GhostSlave : boost::noncopyable { + GhostSlave() : last(0), slave(0), init(false) { } OplogReader reader; OpTime last; Member* slave; @@ -141,7 +141,7 @@ namespace mongo { /** * This is a cache of ghost slaves */ - typedef map<mongo::OID,GhostSlave> MAP; + typedef map<mongo::OID,shared_ptr<GhostSlave>> MAP; MAP _ghostCache; RWLock _lock; // protects _ghostCache ReplSetImpl *rs; diff --git a/db/repl/rs_sync.cpp b/db/repl/rs_sync.cpp index fbacdd1ad83..0770f2f9043 100644 --- a/db/repl/rs_sync.cpp +++ b/db/repl/rs_sync.cpp @@ -594,7 +594,12 @@ namespace mongo { void GhostSync::associateSlave(const BSONObj& id, const int memberId) { const OID rid = id["_id"].OID(); rwlock lk( _lock , true ); - GhostSlave &slave = _ghostCache[rid]; + shared_ptr<GhostSlave> &g = _ghostCache[rid]; + if( g.get() == 0 ) { + g.reset( new GhostSlave() ); + wassert( _ghostCache.size() < 10000 ); + } + GhostSlave &slave = *g; if (slave.init) { LOG(1) << "tracking " << slave.slave->h().toString() << " as " << rid << rsLog; return; @@ -618,7 +623,7 @@ namespace mongo { return; } - GhostSlave& slave = i->second; + GhostSlave& slave = *(i->second); if (!slave.init) { OCCASIONALLY log() << "couldn't update slave " << rid << " not init" << rsLog; return; @@ -639,7 +644,7 @@ namespace mongo { return; } - slave = &(i->second); + slave = i->second.get(); if (!slave->init) { OCCASIONALLY log() << "couldn't percolate slave " << rid << " not init" << rsLog; return; |