summaryrefslogtreecommitdiff
path: root/src/mongo/db/repl
diff options
context:
space:
mode:
authorMathias Stearn <mathias@10gen.com>2014-05-29 15:36:28 -0400
committerMathias Stearn <mathias@10gen.com>2014-05-30 12:10:16 -0400
commita78d754b67040c19714bc4696dd7feb5ce10d412 (patch)
treeaaf640483eff976ff22fdaceb9ebfa78f7659af2 /src/mongo/db/repl
parent4edbe14669b7804180d8b58549e257ceb679bb1d (diff)
downloadmongo-a78d754b67040c19714bc4696dd7feb5ce10d412.tar.gz
SERVER-13641 Plumb OperationContext through to getCollection and all Helpers
Diffstat (limited to 'src/mongo/db/repl')
-rw-r--r--src/mongo/db/repl/health.cpp4
-rw-r--r--src/mongo/db/repl/master_slave.cpp24
-rw-r--r--src/mongo/db/repl/master_slave.h2
-rw-r--r--src/mongo/db/repl/oplog.cpp6
-rw-r--r--src/mongo/db/repl/repl_set.h2
-rw-r--r--src/mongo/db/repl/repl_set_impl.cpp9
-rw-r--r--src/mongo/db/repl/repl_set_impl.h2
-rw-r--r--src/mongo/db/repl/repl_settings.cpp6
-rw-r--r--src/mongo/db/repl/replset_web_handler.cpp6
-rw-r--r--src/mongo/db/repl/rs_initialsync.cpp2
-rw-r--r--src/mongo/db/repl/rs_initiate.cpp2
-rw-r--r--src/mongo/db/repl/rs_rollback.cpp13
-rw-r--r--src/mongo/db/repl/sync.cpp8
-rw-r--r--src/mongo/db/repl/sync.h3
-rw-r--r--src/mongo/db/repl/sync_source_feedback.cpp2
15 files changed, 50 insertions, 41 deletions
diff --git a/src/mongo/db/repl/health.cpp b/src/mongo/db/repl/health.cpp
index aed8a4baa9b..cfb1bd780de 100644
--- a/src/mongo/db/repl/health.cpp
+++ b/src/mongo/db/repl/health.cpp
@@ -217,7 +217,7 @@ namespace repl {
}
}
- void ReplSetImpl::_summarizeAsHtml(stringstream& s) const {
+ void ReplSetImpl::_summarizeAsHtml(OperationContext* txn, stringstream& s) const {
s << table(0, false);
s << tr("Set name:", _name);
s << tr("Majority up:", elect.aMajoritySeemsToBeUp()?"yes":"no" );
@@ -252,7 +252,7 @@ namespace repl {
readlocktry lk(/*"local.replset.minvalid", */300);
if( lk.got() ) {
BSONObj mv;
- if( Helpers::getSingleton("local.replset.minvalid", mv) ) {
+ if( Helpers::getSingleton(txn, "local.replset.minvalid", mv) ) {
myMinValid = "minvalid:" + mv["ts"]._opTime().toString();
}
}
diff --git a/src/mongo/db/repl/master_slave.cpp b/src/mongo/db/repl/master_slave.cpp
index ff2ff4921f5..93681b32d28 100644
--- a/src/mongo/db/repl/master_slave.cpp
+++ b/src/mongo/db/repl/master_slave.cpp
@@ -165,7 +165,7 @@ namespace repl {
OperationContextImpl txn;
Client::WriteContext ctx(&txn, "local");
// local.me is an identifier for a server for getLastError w:2+
- if (!Helpers::getSingleton("local.me", _me) ||
+ if (!Helpers::getSingleton(&txn, "local.me", _me) ||
!_me.hasField("host") ||
_me["host"].String() != myname) {
@@ -231,7 +231,7 @@ namespace repl {
/* we reuse our existing objects so that we can keep our existing connection
and cursor in effect.
*/
- void ReplSource::loadAll(SourceVector &v) {
+ void ReplSource::loadAll(OperationContext* txn, SourceVector &v) {
const char* localSources = "local.sources";
Client::Context ctx(localSources);
SourceVector old = v;
@@ -242,8 +242,9 @@ namespace repl {
// check that no items are in sources other than that
// add if missing
int n = 0;
- auto_ptr<Runner> runner(InternalPlanner::collectionScan(localSources,
- ctx.db()->getCollection(localSources)));
+ auto_ptr<Runner> runner(
+ InternalPlanner::collectionScan(localSources,
+ ctx.db()->getCollection(txn, localSources)));
BSONObj obj;
Runner::RunnerState state;
while (Runner::RUNNER_ADVANCED == (state = runner->getNext(&obj, NULL))) {
@@ -285,8 +286,9 @@ namespace repl {
}
}
- auto_ptr<Runner> runner(InternalPlanner::collectionScan(localSources,
- ctx.db()->getCollection(localSources)));
+ auto_ptr<Runner> runner(
+ InternalPlanner::collectionScan(localSources,
+ ctx.db()->getCollection(txn, localSources)));
BSONObj obj;
Runner::RunnerState state;
while (Runner::RUNNER_ADVANCED == (state = runner->getNext(&obj, NULL))) {
@@ -318,7 +320,7 @@ namespace repl {
if ( !replAllDead )
return;
SourceVector sources;
- ReplSource::loadAll(sources);
+ ReplSource::loadAll(txn, sources);
for( SourceVector::iterator i = sources.begin(); i != sources.end(); ++i ) {
log() << requester << " forcing resync from " << (*i)->hostName << endl;
(*i)->forceResync( txn, requester );
@@ -1020,10 +1022,11 @@ namespace repl {
1 = special sentinel indicating adaptive sleep recommended
*/
int _replMain(ReplSource::SourceVector& sources, int& nApplied) {
+ OperationContextImpl txn;
{
ReplInfo r("replMain load sources");
Lock::GlobalWrite lk;
- ReplSource::loadAll(sources);
+ ReplSource::loadAll(&txn, sources);
replSettings.fastsync = false; // only need this param for initial reset
}
@@ -1245,6 +1248,7 @@ namespace repl {
c = &cc();
}
+ OperationContextImpl txn; // XXX
Lock::GlobalRead lk;
for( unsigned i = a; i <= b; i++ ) {
const BSONObj& op = v[i];
@@ -1267,7 +1271,7 @@ namespace repl {
b.append(_id);
BSONObj result;
Client::Context ctx( ns );
- if( Helpers::findById(ctx.db(), ns, b.done(), result) )
+ if( Helpers::findById(&txn, ctx.db(), ns, b.done(), result) )
_dummy_z += result.objsize(); // touch
}
}
@@ -1301,7 +1305,7 @@ namespace repl {
b.append(_id);
BSONObj result;
Client::ReadContext ctx(txn, ns );
- if( Helpers::findById(ctx.ctx().db(), ns, b.done(), result) )
+ if( Helpers::findById(txn, ctx.ctx().db(), ns, b.done(), result) )
_dummy_z += result.objsize(); // touch
}
}
diff --git a/src/mongo/db/repl/master_slave.h b/src/mongo/db/repl/master_slave.h
index ca21d180111..15445f68ede 100644
--- a/src/mongo/db/repl/master_slave.h
+++ b/src/mongo/db/repl/master_slave.h
@@ -138,7 +138,7 @@ namespace repl {
int nClonedThisPass;
typedef std::vector< shared_ptr< ReplSource > > SourceVector;
- static void loadAll(SourceVector&);
+ static void loadAll(OperationContext* txn, SourceVector&);
explicit ReplSource(BSONObj);
/* -1 = error */
diff --git a/src/mongo/db/repl/oplog.cpp b/src/mongo/db/repl/oplog.cpp
index 474416dd250..1c40bbdfa6f 100644
--- a/src/mongo/db/repl/oplog.cpp
+++ b/src/mongo/db/repl/oplog.cpp
@@ -422,7 +422,7 @@ namespace repl {
_logOp(txn, opstr, ns, 0, obj, patt, b, fromMigrate);
}
- logOpForSharding(opstr, ns, obj, patt, fromMigrate);
+ logOpForSharding(txn, opstr, ns, obj, patt, fromMigrate);
logOpForDbHash(ns);
getGlobalAuthorizationManager()->logOp(opstr, ns, obj, patt, b);
@@ -672,9 +672,9 @@ namespace repl {
// thus this is not ideal.
else {
if (collection == NULL ||
- (indexCatalog->haveIdIndex() && Helpers::findById(collection, updateCriteria).isNull()) ||
+ (indexCatalog->haveIdIndex() && Helpers::findById(txn, collection, updateCriteria).isNull()) ||
// capped collections won't have an _id index
- (!indexCatalog->haveIdIndex() && Helpers::findOne(collection, updateCriteria, false).isNull())) {
+ (!indexCatalog->haveIdIndex() && Helpers::findOne(txn, collection, updateCriteria, false).isNull())) {
failedUpdate = true;
log() << "replication couldn't find doc: " << op.toString() << endl;
}
diff --git a/src/mongo/db/repl/repl_set.h b/src/mongo/db/repl/repl_set.h
index 914f13751cf..981e2ee708a 100644
--- a/src/mongo/db/repl/repl_set.h
+++ b/src/mongo/db/repl/repl_set.h
@@ -63,7 +63,7 @@ namespace repl {
string name() const { return ReplSetImpl::name(); }
virtual const ReplSetConfig& config() { return ReplSetImpl::config(); }
void getOplogDiagsAsHtml(unsigned server_id, stringstream& ss) const { _getOplogDiagsAsHtml(server_id,ss); }
- void summarizeAsHtml(stringstream& ss) const { _summarizeAsHtml(ss); }
+ void summarizeAsHtml(OperationContext* txn, stringstream& ss) const { _summarizeAsHtml(txn, ss); }
void summarizeStatus(BSONObjBuilder& b) const { _summarizeStatus(b); }
void fillIsMaster(BSONObjBuilder& b) { _fillIsMaster(b); }
threadpool::ThreadPool& getPrefetchPool() { return ReplSetImpl::getPrefetchPool(); }
diff --git a/src/mongo/db/repl/repl_set_impl.cpp b/src/mongo/db/repl/repl_set_impl.cpp
index 5274e461f07..5d7a37d8806 100644
--- a/src/mongo/db/repl/repl_set_impl.cpp
+++ b/src/mongo/db/repl/repl_set_impl.cpp
@@ -438,7 +438,7 @@ namespace {
OperationContextImpl txn; // XXX?
Lock::DBRead lk(txn.lockState(), rsoplog);
BSONObj o;
- if (Helpers::getLast(rsoplog, o)) {
+ if (Helpers::getLast(&txn, rsoplog, o)) {
lastH = o["h"].numberLong();
lastOpTimeWritten = o["ts"]._opTime();
uassert(13290, "bad replSet oplog entry?", quiet || !lastOpTimeWritten.isNull());
@@ -449,7 +449,8 @@ namespace {
OperationContextImpl txn; // XXX?
Lock::DBRead lk(txn.lockState(), rsoplog);
BSONObj o;
- uassert(17347, "Problem reading earliest entry from oplog", Helpers::getFirst(rsoplog, o));
+ uassert(17347, "Problem reading earliest entry from oplog",
+ Helpers::getFirst(&txn, rsoplog, o));
return o["ts"]._opTime();
}
@@ -876,7 +877,7 @@ namespace {
OperationContextImpl txn; // XXX?
Lock::DBRead lk (txn.lockState(), "local");
BSONObj mv;
- if (Helpers::getSingleton("local.replset.minvalid", mv)) {
+ if (Helpers::getSingleton(&txn, "local.replset.minvalid", mv)) {
return mv[_initialSyncFlagString].trueValue();
}
return false;
@@ -897,7 +898,7 @@ namespace {
OperationContextImpl txn; // XXX?
Lock::DBRead lk(txn.lockState(), "local.replset.minvalid");
BSONObj mv;
- if (Helpers::getSingleton("local.replset.minvalid", mv)) {
+ if (Helpers::getSingleton(&txn, "local.replset.minvalid", mv)) {
return mv["ts"]._opTime();
}
return OpTime();
diff --git a/src/mongo/db/repl/repl_set_impl.h b/src/mongo/db/repl/repl_set_impl.h
index 1fc7529dd2d..b5b6254826d 100644
--- a/src/mongo/db/repl/repl_set_impl.h
+++ b/src/mongo/db/repl/repl_set_impl.h
@@ -198,7 +198,7 @@ namespace repl {
MemberState state() const { return box.getState(); }
void _fatal();
void _getOplogDiagsAsHtml(unsigned server_id, stringstream& ss) const;
- void _summarizeAsHtml(stringstream&) const;
+ void _summarizeAsHtml(OperationContext* txn, stringstream&) const;
void _summarizeStatus(BSONObjBuilder&) const; // for replSetGetStatus command
/* call afer constructing to start - returns fairly quickly after launching its threads */
diff --git a/src/mongo/db/repl/repl_settings.cpp b/src/mongo/db/repl/repl_settings.cpp
index 48dad4218cc..65db46755ab 100644
--- a/src/mongo/db/repl/repl_settings.cpp
+++ b/src/mongo/db/repl/repl_settings.cpp
@@ -90,8 +90,10 @@ namespace repl {
{
const char* localSources = "local.sources";
Client::ReadContext ctx(txn, localSources);
- auto_ptr<Runner> runner(InternalPlanner::collectionScan(localSources,
- ctx.ctx().db()->getCollection(localSources)));
+ auto_ptr<Runner> runner(
+ InternalPlanner::collectionScan(localSources,
+ ctx.ctx().db()->getCollection(txn,
+ localSources)));
BSONObj obj;
Runner::RunnerState state;
while (Runner::RUNNER_ADVANCED == (state = runner->getNext(&obj, NULL))) {
diff --git a/src/mongo/db/repl/replset_web_handler.cpp b/src/mongo/db/repl/replset_web_handler.cpp
index f9d271a1e09..8c71fa2748b 100644
--- a/src/mongo/db/repl/replset_web_handler.cpp
+++ b/src/mongo/db/repl/replset_web_handler.cpp
@@ -59,7 +59,7 @@ namespace repl {
responseMsg = _replSetOplog(params);
}
else
- responseMsg = _replSet();
+ responseMsg = _replSet(txn);
responseCode = 200;
}
@@ -93,7 +93,7 @@ namespace repl {
}
/* /_replSet show replica set status in html format */
- string _replSet() {
+ string _replSet(OperationContext* txn) {
stringstream s;
s << start("Replica Set Status " + prettyHostName());
s << p( a("/", "back", "Home") + " | " +
@@ -112,7 +112,7 @@ namespace repl {
}
else {
try {
- theReplSet->summarizeAsHtml(s);
+ theReplSet->summarizeAsHtml(txn, s);
}
catch(...) { s << "error summarizing replset status\n"; }
}
diff --git a/src/mongo/db/repl/rs_initialsync.cpp b/src/mongo/db/repl/rs_initialsync.cpp
index 32d9d7e6e3c..be6c8aaf75a 100644
--- a/src/mongo/db/repl/rs_initialsync.cpp
+++ b/src/mongo/db/repl/rs_initialsync.cpp
@@ -133,7 +133,7 @@ namespace repl {
OperationContextImpl txn;
Client::WriteContext ctx(&txn, rsoplog);
- Collection* collection = ctx.ctx().db()->getCollection(rsoplog);
+ Collection* collection = ctx.ctx().db()->getCollection(&txn, rsoplog);
// temp
if( collection->numRecords() == 0 )
diff --git a/src/mongo/db/repl/rs_initiate.cpp b/src/mongo/db/repl/rs_initiate.cpp
index 23ec6697a57..e50d2a80568 100644
--- a/src/mongo/db/repl/rs_initiate.cpp
+++ b/src/mongo/db/repl/rs_initiate.cpp
@@ -207,7 +207,7 @@ namespace repl {
it is ok if the initiating member has *other* data than that.
*/
BSONObj o;
- if( Helpers::getFirst(rsoplog, o) ) {
+ if( Helpers::getFirst(txn, rsoplog, o) ) {
errmsg = rsoplog + string(" is not empty on the initiating member. cannot initiate.");
return false;
}
diff --git a/src/mongo/db/repl/rs_rollback.cpp b/src/mongo/db/repl/rs_rollback.cpp
index b8bc672753f..efdcee062a2 100644
--- a/src/mongo/db/repl/rs_rollback.cpp
+++ b/src/mongo/db/repl/rs_rollback.cpp
@@ -231,12 +231,13 @@ namespace repl {
int getRBID(DBClientConnection*);
static void syncRollbackFindCommonPoint(DBClientConnection* them, FixUpInfo& fixUpInfo) {
+ OperationContextImpl txn; // XXX
verify(Lock::isLocked());
Client::Context ctx(rsoplog);
boost::scoped_ptr<Runner> runner(
InternalPlanner::collectionScan(rsoplog,
- ctx.db()->getCollection(rsoplog),
+ ctx.db()->getCollection(&txn, rsoplog),
InternalPlanner::BACKWARD));
BSONObj ourObj;
@@ -484,7 +485,7 @@ namespace repl {
sethbmsg("rollback 4.7");
Client::Context ctx(rsoplog);
- Collection* oplogCollection = ctx.db()->getCollection(rsoplog);
+ Collection* oplogCollection = ctx.db()->getCollection(&txn, rsoplog);
uassert(13423,
str::stream() << "replSet error in rollback can't find " << rsoplog,
oplogCollection);
@@ -516,7 +517,7 @@ namespace repl {
// Add the doc to our rollback file
BSONObj obj;
- bool found = Helpers::findOne(ctx.db()->getCollection(doc.ns), pattern, obj, false);
+ bool found = Helpers::findOne(&txn, ctx.db()->getCollection(&txn, doc.ns), pattern, obj, false);
if (found) {
removeSaver->goingToDelete(obj);
}
@@ -529,7 +530,7 @@ namespace repl {
// TODO 1.6 : can't delete from a capped collection. need to handle that here.
deletes++;
- Collection* collection = ctx.db()->getCollection(doc.ns);
+ Collection* collection = ctx.db()->getCollection(&txn, doc.ns);
if (collection) {
if (collection->isCapped()) {
// can't delete from a capped collection - so we truncate instead. if
@@ -538,7 +539,7 @@ namespace repl {
// TODO: IIRC cappedTruncateAfter does not handle completely empty.
// this will crazy slow if no _id index.
long long start = Listener::getElapsedTimeMillis();
- DiskLoc loc = Helpers::findOne(collection, pattern, false);
+ DiskLoc loc = Helpers::findOne(&txn, collection, pattern, false);
if (Listener::getElapsedTimeMillis() - start > 200)
log() << "replSet warning roll back slow no _id index for "
<< doc.ns << " perhaps?" << rsLog;
@@ -657,7 +658,7 @@ namespace repl {
OperationContextImpl txn;
Lock::DBRead lk(txn.lockState(), "local.replset.minvalid");
BSONObj mv;
- if (Helpers::getSingleton("local.replset.minvalid", mv)) {
+ if (Helpers::getSingleton(&txn, "local.replset.minvalid", mv)) {
OpTime minvalid = mv["ts"]._opTime();
if (minvalid > lastOpTimeWritten) {
log() << "replSet need to rollback, but in inconsistent state";
diff --git a/src/mongo/db/repl/sync.cpp b/src/mongo/db/repl/sync.cpp
index 888edbeb99a..8ca15ed9386 100644
--- a/src/mongo/db/repl/sync.cpp
+++ b/src/mongo/db/repl/sync.cpp
@@ -48,12 +48,12 @@ namespace repl {
hn = hostname;
}
- BSONObj Sync::getMissingDoc(Database* db, const BSONObj& o) {
+ BSONObj Sync::getMissingDoc(OperationContext* txn, Database* db, const BSONObj& o) {
OplogReader missingObjReader; // why are we using OplogReader to run a non-oplog query?
const char *ns = o.getStringField("ns");
// capped collections
- Collection* collection = db->getCollection(ns);
+ Collection* collection = db->getCollection(txn, ns);
if ( collection && collection->isCapped() ) {
log() << "replication missing doc, but this is okay for a capped collection (" << ns << ")" << endl;
return BSONObj();
@@ -115,7 +115,7 @@ namespace repl {
// 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(ctx.db(), o);
+ BSONObj missingObj = getMissingDoc(&txn, ctx.db(), o);
if( missingObj.isEmpty() ) {
log() << "replication missing object not found on source. presumably deleted later in oplog" << endl;
@@ -125,7 +125,7 @@ namespace repl {
return false;
}
else {
- Collection* collection = ctx.db()->getOrCreateCollection( ns );
+ Collection* collection = ctx.db()->getOrCreateCollection( &txn, ns );
verify( collection ); // should never happen
StatusWith<DiskLoc> result = collection->insertDocument( &txn, missingObj, true );
uassert(15917,
diff --git a/src/mongo/db/repl/sync.h b/src/mongo/db/repl/sync.h
index e86997cad6c..67cb5e63a60 100644
--- a/src/mongo/db/repl/sync.h
+++ b/src/mongo/db/repl/sync.h
@@ -34,6 +34,7 @@
namespace mongo {
class Database;
+ class OperationContext;
namespace repl {
@@ -43,7 +44,7 @@ namespace repl {
public:
Sync(const std::string& hostname) : hn(hostname) {}
virtual ~Sync() {}
- virtual BSONObj getMissingDoc(Database* db, const BSONObj& o);
+ virtual BSONObj getMissingDoc(OperationContext* txn, Database* db, const BSONObj& o);
/**
* If applyOperation_inlock should be called again after an update fails.
diff --git a/src/mongo/db/repl/sync_source_feedback.cpp b/src/mongo/db/repl/sync_source_feedback.cpp
index d30eb517898..774748288b5 100644
--- a/src/mongo/db/repl/sync_source_feedback.cpp
+++ b/src/mongo/db/repl/sync_source_feedback.cpp
@@ -70,7 +70,7 @@ namespace repl {
Client::WriteContext ctx(&txn, "local");
// local.me is an identifier for a server for getLastError w:2+
- if (!Helpers::getSingleton("local.me", _me) ||
+ if (!Helpers::getSingleton(&txn, "local.me", _me) ||
!_me.hasField("host") ||
_me["host"].String() != myname) {