summaryrefslogtreecommitdiff
path: root/src/mongo
diff options
context:
space:
mode:
authorHari Khalsa <hkhalsa@10gen.com>2014-05-13 16:17:36 -0400
committerHari Khalsa <hkhalsa@10gen.com>2014-05-14 12:37:46 -0400
commit29a700ada85ff1a11ca428bbf71d337ece2f2c5a (patch)
treebe986e3aa163e5b655fcfd70ca632ee0a0ea9208 /src/mongo
parentb1e42ae09dbcf45e5b35b787743bb183930b20a9 (diff)
downloadmongo-29a700ada85ff1a11ca428bbf71d337ece2f2c5a.tar.gz
SERVER-13922 remove dbtemprelease from non-repl remaining spots
Diffstat (limited to 'src/mongo')
-rw-r--r--src/mongo/db/cloner.cpp72
-rw-r--r--src/mongo/db/commands/mr.cpp55
-rw-r--r--src/mongo/db/db.h27
-rw-r--r--src/mongo/db/pdfile.cpp1
-rw-r--r--src/mongo/db/repair_database.cpp1
5 files changed, 41 insertions, 115 deletions
diff --git a/src/mongo/db/cloner.cpp b/src/mongo/db/cloner.cpp
index e0187ab59c4..37d28f334ad 100644
--- a/src/mongo/db/cloner.cpp
+++ b/src/mongo/db/cloner.cpp
@@ -59,26 +59,6 @@ namespace mongo {
BSONElement getErrField(const BSONObj& o);
- /** Selectively release the mutex based on a parameter. */
- class dbtempreleaseif {
- MONGO_DISALLOW_COPYING(dbtempreleaseif);
- public:
- dbtempreleaseif( bool release ) : _impl( release ? new dbtemprelease() : 0 ) {}
- ~dbtempreleaseif() throw(DBException) {
- if (_impl)
- delete _impl;
- }
- private:
- // can't use a smart pointer because we need throw annotation on destructor
- dbtemprelease* _impl;
- };
-
- void mayInterrupt( bool mayBeInterrupted ) {
- if ( mayBeInterrupted ) {
- killCurrentOp.checkForInterrupt( false );
- }
- }
-
/* for index info object:
{ "name" : "name_1" , "ns" : "foo.index3" , "key" : { "name" : 1.0 } }
we need to fix up the value in the "ns" parameter so that the name prefix is correct on a
@@ -107,14 +87,8 @@ namespace mongo {
else
b.append(e);
}
- BSONObj res= b.obj();
- /* if( mod ) {
- out() << "before: " << o.toString() << endl;
- o.dump();
- out() << "after: " << res.toString() << endl;
- res.dump();
- }*/
+ BSONObj res= b.obj();
return res;
}
@@ -129,15 +103,29 @@ namespace mongo {
{}
void operator()( DBClientCursorBatchIterator &i ) {
+ // XXX: can probably take dblock instead
Lock::GlobalWrite lk;
context.relocked();
bool createdCollection = false;
Collection* collection = NULL;
+ if ( isindex == false ) {
+ collection = context.db()->getCollection( to_collection );
+ if ( !collection ) {
+ massert( 17321,
+ str::stream()
+ << "collection dropped during clone ["
+ << to_collection << "]",
+ !createdCollection );
+ createdCollection = true;
+ collection = context.db()->createCollection( txn, to_collection );
+ verify( collection );
+ }
+ }
+
while( i.moreInCurrentBatch() ) {
- if ( numSeen % 128 == 127 /*yield some*/ ) {
- collection = NULL;
+ if ( numSeen % 128 == 127 ) {
time_t now = time(0);
if( now - lastLog >= 60 ) {
// report progress
@@ -145,22 +133,6 @@ namespace mongo {
log() << "clone " << to_collection << ' ' << numSeen << endl;
lastLog = now;
}
- mayInterrupt( _mayBeInterrupted );
- dbtempreleaseif t( _mayYield );
- }
-
- if ( isindex == false && collection == NULL ) {
- collection = context.db()->getCollection( to_collection );
- if ( !collection ) {
- massert( 17321,
- str::stream()
- << "collection dropped during clone ["
- << to_collection << "]",
- !createdCollection );
- createdCollection = true;
- collection = context.db()->createCollection( txn, to_collection );
- verify( collection );
- }
}
BSONObj tmp = i.nextSafe();
@@ -249,8 +221,7 @@ namespace mongo {
int options = QueryOption_NoCursorTimeout | ( slaveOk ? QueryOption_SlaveOk : 0 );
{
- mayInterrupt( mayBeInterrupted );
- dbtempreleaseif r( mayYield );
+ dbtemprelease r;
_conn->query(boost::function<void(DBClientCursorBatchIterator &)>(f), from_collection,
query, 0, options);
}
@@ -417,8 +388,7 @@ namespace mongo {
/* todo: we can put these releases inside dbclient or a dbclient specialization.
or just wait until we get rid of global lock anyway.
*/
- mayInterrupt( opts.mayBeInterrupted );
- dbtempreleaseif r( opts.mayYield );
+ dbtemprelease r;
// just using exhaust for collection copying right now
@@ -477,10 +447,6 @@ namespace mongo {
}
for ( list<BSONObj>::iterator i=toClone.begin(); i != toClone.end(); i++ ) {
- {
- mayInterrupt( opts.mayBeInterrupted );
- dbtempreleaseif r( opts.mayYield );
- }
BSONObj collection = *i;
LOG(2) << " really will clone: " << collection << endl;
const char * from_name = collection["name"].valuestr();
diff --git a/src/mongo/db/commands/mr.cpp b/src/mongo/db/commands/mr.cpp
index b1e80ecbf06..7c39fee77e4 100644
--- a/src/mongo/db/commands/mr.cpp
+++ b/src/mongo/db/commands/mr.cpp
@@ -948,7 +948,7 @@ namespace mongo {
verify( foundIndex );
}
- Client::ReadContext ctx( _config.incLong );
+ scoped_ptr<Client::ReadContext> ctx(new Client::ReadContext(_config.incLong));
BSONObj prev;
BSONList all;
@@ -969,7 +969,7 @@ namespace mongo {
whereCallback).isOK());
Runner* rawRunner;
- verify(getRunner(ctx.ctx().db()->getCollection(_config.incLong),
+ verify(getRunner(ctx->ctx().db()->getCollection(_config.incLong),
cq, &rawRunner, QueryPlannerParams::NO_TABLE_SCAN).isOK());
auto_ptr<Runner> runner(rawRunner);
@@ -992,18 +992,12 @@ namespace mongo {
runner->saveState();
- // can't be a smart pointer since it needs throw annotation on destructor
- dbtempreleasecond* yield = new dbtempreleasecond();
+ ctx.reset();
- try {
- // reduce a finalize array
- finalReduce( all );
- }
- catch (...) {
- delete yield; // if throws, replaces current exception rather than terminating.
- throw;
- }
- delete yield;
+ // reduce a finalize array
+ finalReduce( all );
+
+ ctx.reset(new Client::ReadContext(_config.incLong));
all.clear();
prev = o;
@@ -1016,13 +1010,10 @@ namespace mongo {
_txn->checkForInterrupt();
}
- {
- dbtempreleasecond tl;
- if ( ! tl.unlocked() )
- warning() << "map/reduce can't temp release" << endl;
- // reduce and finalize last array
- finalReduce( all );
- }
+ ctx.reset();
+ // reduce and finalize last array
+ finalReduce( all );
+ ctx.reset(new Client::ReadContext(_config.incLong));
pm.finished();
}
@@ -1296,11 +1287,11 @@ namespace mongo {
// We've got a cursor preventing migrations off, now re-establish our useful cursor
// Need lock and context to use it
- Lock::DBRead lock( config.ns );
+ scoped_ptr<Lock::DBRead> lock(new Lock::DBRead(config.ns));
// This context does no version check, safe b/c we checked earlier and have an
// open cursor
- Client::Context ctx(config.ns, storageGlobalParams.dbpath, false);
+ scoped_ptr<Client::Context> ctx(new Client::Context(config.ns, storageGlobalParams.dbpath, false));
const NamespaceString nss(config.ns);
const WhereCallbackReal whereCallback(nss.db());
@@ -1317,7 +1308,7 @@ namespace mongo {
}
Runner* rawRunner;
- if (!getRunner(ctx.db()->getCollection( config.ns), cq, &rawRunner).isOK()) {
+ if (!getRunner(ctx->db()->getCollection( config.ns), cq, &rawRunner).isOK()) {
uasserted(17239, "Can't get runner for query " + config.filter.toString());
return 0;
}
@@ -1352,16 +1343,14 @@ namespace mongo {
if (numInputs % 100 == 0) {
Timer t;
- // TODO: As an optimization, we might want to do the save/restore
- // state and yield inside the reduceAndSpillInMemoryState method,
- // so it only happens if necessary.
- //
- runner->saveState();
- {
- dbtemprelease unlock;
- state.reduceAndSpillInMemoryStateIfNeeded();
- }
- runner->restoreState();
+ // TODO: As an optimization, we might want to do the save/restore
+ // state and yield inside the reduceAndSpillInMemoryState method, so
+ // it only happens if necessary.
+ ctx.reset();
+ lock.reset();
+ state.reduceAndSpillInMemoryStateIfNeeded();
+ lock.reset(new Lock::DBRead(config.ns));
+ ctx.reset(new Client::Context(config.ns, storageGlobalParams.dbpath, false));
reduceTime += t.micros();
diff --git a/src/mongo/db/db.h b/src/mongo/db/db.h
index 9ff1a1541a7..63b1e38bbfb 100644
--- a/src/mongo/db/db.h
+++ b/src/mongo/db/db.h
@@ -71,33 +71,6 @@ namespace mongo {
}
};
- /**
- * only does a temp release if we're not nested and have a lock
- *
- * WARNING: do not put in a smart pointer or any other class. If you absolutely must, you need
- * to add the throw(DBException) annotation to it's destructor.
- */
- class dbtempreleasecond : boost::noncopyable {
- dbtemprelease * real;
- public:
- dbtempreleasecond() {
- real = 0;
- if( Lock::isLocked() ) {
- // if nested don't temprelease, and we don't complain either for this class
- if( !Lock::nested() ) {
- real = new dbtemprelease();
- }
- }
- }
- ~dbtempreleasecond() throw(DBException) {
- if ( real ) {
- delete real;
- real = 0;
- }
- }
- bool unlocked() const { return real != 0; }
- };
-
extern void (*snmpInit)();
} // namespace mongo
diff --git a/src/mongo/db/pdfile.cpp b/src/mongo/db/pdfile.cpp
index 45f3d6c2bb6..903a78cd12d 100644
--- a/src/mongo/db/pdfile.cpp
+++ b/src/mongo/db/pdfile.cpp
@@ -52,7 +52,6 @@ _ disallow system* manipulations from the database.
#include "mongo/db/pdfile_private.h"
#include "mongo/db/background.h"
#include "mongo/db/clientcursor.h"
-#include "mongo/db/cloner.h"
#include "mongo/db/commands/server_status.h"
#include "mongo/db/curop-inl.h"
#include "mongo/db/db.h"
diff --git a/src/mongo/db/repair_database.cpp b/src/mongo/db/repair_database.cpp
index cceba1f26fc..9151e81300a 100644
--- a/src/mongo/db/repair_database.cpp
+++ b/src/mongo/db/repair_database.cpp
@@ -38,7 +38,6 @@
#include "mongo/db/catalog/database_holder.h"
#include "mongo/db/catalog/index_create.h"
#include "mongo/db/client.h"
-#include "mongo/db/cloner.h"
#include "mongo/db/index/index_descriptor.h"
#include "mongo/util/file.h"
#include "mongo/util/file_allocator.h"