summaryrefslogtreecommitdiff
path: root/src/mongo/dbtests
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/dbtests')
-rw-r--r--src/mongo/dbtests/clienttests.cpp13
-rw-r--r--src/mongo/dbtests/counttests.cpp7
-rw-r--r--src/mongo/dbtests/dbhelper_tests.cpp24
-rw-r--r--src/mongo/dbtests/documentsourcetests.cpp2
-rw-r--r--src/mongo/dbtests/indexcatalogtests.cpp9
-rw-r--r--src/mongo/dbtests/indexupdatetests.cpp5
-rw-r--r--src/mongo/dbtests/matchertests.cpp5
-rw-r--r--src/mongo/dbtests/pdfiletests.cpp3
-rw-r--r--src/mongo/dbtests/plan_ranking.cpp17
-rw-r--r--src/mongo/dbtests/query_multi_plan_runner.cpp4
-rw-r--r--src/mongo/dbtests/query_single_solution_runner.cpp32
-rw-r--r--src/mongo/dbtests/query_stage_and.cpp71
-rw-r--r--src/mongo/dbtests/query_stage_collscan.cpp20
-rw-r--r--src/mongo/dbtests/query_stage_count.cpp37
-rw-r--r--src/mongo/dbtests/query_stage_distinct.cpp19
-rw-r--r--src/mongo/dbtests/query_stage_fetch.cpp6
-rw-r--r--src/mongo/dbtests/query_stage_keep.cpp3
-rw-r--r--src/mongo/dbtests/query_stage_merge_sort.cpp38
-rw-r--r--src/mongo/dbtests/query_stage_sort.cpp18
-rw-r--r--src/mongo/dbtests/query_stage_tests.cpp20
-rw-r--r--src/mongo/dbtests/querytests.cpp70
-rw-r--r--src/mongo/dbtests/replsettests.cpp15
-rw-r--r--src/mongo/dbtests/runner_registry.cpp6
-rw-r--r--src/mongo/dbtests/threadedtests.cpp55
-rw-r--r--src/mongo/dbtests/updatetests.cpp26
25 files changed, 294 insertions, 231 deletions
diff --git a/src/mongo/dbtests/clienttests.cpp b/src/mongo/dbtests/clienttests.cpp
index e47e67ea4ea..194cc048046 100644
--- a/src/mongo/dbtests/clienttests.cpp
+++ b/src/mongo/dbtests/clienttests.cpp
@@ -1,3 +1,5 @@
+// client.cpp
+
/*
* Copyright (C) 2010 10gen Inc.
*
@@ -26,16 +28,13 @@
* then also delete it in the license file.
*/
-// client.cpp
-
-#include "mongo/pch.h"
-
#include "mongo/client/dbclientcursor.h"
#include "mongo/db/catalog/collection.h"
#include "mongo/db/catalog/database.h"
-#include "mongo/db/d_concurrency.h"
+#include "mongo/db/operation_context_noop.h"
#include "mongo/dbtests/dbtests.h"
+
namespace ClientTests {
class Base {
@@ -123,8 +122,8 @@ namespace ClientTests {
public:
BuildIndex() : Base("buildIndex") {}
void run() {
- Lock::DBWrite lock(ns());
- Client::WriteContext ctx(ns());
+ OperationContextNoop txn;
+ Client::WriteContext ctx(&txn, ns());
db.insert(ns(), BSON("x" << 1 << "y" << 2));
db.insert(ns(), BSON("x" << 2 << "y" << 2));
diff --git a/src/mongo/dbtests/counttests.cpp b/src/mongo/dbtests/counttests.cpp
index 1ff84d735f8..729443e2835 100644
--- a/src/mongo/dbtests/counttests.cpp
+++ b/src/mongo/dbtests/counttests.cpp
@@ -41,13 +41,16 @@
namespace CountTests {
class Base {
+ OperationContextImpl _txn;
Lock::DBWrite lk;
+
Client::Context _context;
+
Database* _database;
Collection* _collection;
- OperationContextImpl _txn;
+
public:
- Base() : lk(ns()), _context( ns() ) {
+ Base() : lk(_txn.lockState(), ns()), _context( ns() ) {
_database = _context.db();
_collection = _database->getCollection( ns() );
if ( _collection ) {
diff --git a/src/mongo/dbtests/dbhelper_tests.cpp b/src/mongo/dbtests/dbhelper_tests.cpp
index 535dab6124d..0cee60de170 100644
--- a/src/mongo/dbtests/dbhelper_tests.cpp
+++ b/src/mongo/dbtests/dbhelper_tests.cpp
@@ -58,8 +58,9 @@ namespace mongo {
{
// Remove _id range [_min, _max).
OperationContextImpl txn;
- Lock::DBWrite lk( ns );
+ Lock::DBWrite lk(txn.lockState(), ns);
Client::Context ctx( ns );
+
KeyRange range( ns,
BSON( "_id" << _min ),
BSON( "_id" << _max ),
@@ -112,6 +113,8 @@ namespace mongo {
TEST(DBHelperTests, FindDiskLocs) {
DBDirectClient client;
+ OperationContextImpl txn;
+
// Some unique tag we can use to make sure we're pulling back the right data
OID tag = OID::gen();
client.remove( ns, BSONObj() );
@@ -128,14 +131,15 @@ namespace mongo {
long long estSizeBytes;
{
// search _id range (0, 10)
- Lock::DBRead lk( ns );
+ Lock::DBRead lk(txn.lockState(), ns);
KeyRange range( ns,
BSON( "_id" << 0 ),
BSON( "_id" << numDocsInserted ),
BSON( "_id" << 1 ) );
- Status result = Helpers::getLocsInRange( range,
+ Status result = Helpers::getLocsInRange( &txn,
+ range,
maxSizeBytes,
&locs,
&numDocsFound,
@@ -164,6 +168,8 @@ namespace mongo {
TEST(DBHelperTests, FindDiskLocsNoIndex) {
DBDirectClient client;
+ OperationContextImpl txn;
+
client.remove( ns, BSONObj() );
client.insert( ns, BSON( "_id" << OID::gen() ) );
@@ -173,7 +179,7 @@ namespace mongo {
long long numDocsFound;
long long estSizeBytes;
{
- Lock::DBRead lk( ns );
+ Lock::DBRead lk(txn.lockState(), ns);
Client::Context ctx( ns );
// search invalid index range
@@ -182,7 +188,8 @@ namespace mongo {
BSON( "badIndex" << 10 ),
BSON( "badIndex" << 1 ) );
- Status result = Helpers::getLocsInRange( range,
+ Status result = Helpers::getLocsInRange( &txn,
+ range,
maxSizeBytes,
&locs,
&numDocsFound,
@@ -203,6 +210,8 @@ namespace mongo {
TEST(DBHelperTests, FindDiskLocsTooBig) {
DBDirectClient client;
+ OperationContextImpl txn;
+
client.remove( ns, BSONObj() );
int numDocsInserted = 10;
@@ -217,14 +226,15 @@ namespace mongo {
long long numDocsFound;
long long estSizeBytes;
{
- Lock::DBRead lk( ns );
+ Lock::DBRead lk(txn.lockState(), ns);
Client::Context ctx( ns );
KeyRange range( ns,
BSON( "_id" << 0 ),
BSON( "_id" << numDocsInserted ),
BSON( "_id" << 1 ) );
- Status result = Helpers::getLocsInRange( range,
+ Status result = Helpers::getLocsInRange( &txn,
+ range,
maxSizeBytes,
&locs,
&numDocsFound,
diff --git a/src/mongo/dbtests/documentsourcetests.cpp b/src/mongo/dbtests/documentsourcetests.cpp
index 593c310eb93..652958c2efe 100644
--- a/src/mongo/dbtests/documentsourcetests.cpp
+++ b/src/mongo/dbtests/documentsourcetests.cpp
@@ -166,7 +166,7 @@ namespace DocumentSourceTests {
_registration.reset();
_runner.reset();
- Client::WriteContext ctx (ns);
+ Client::WriteContext ctx(&_opCtx, ns);
CanonicalQuery* cq;
uassertStatusOK(CanonicalQuery::canonicalize(ns, /*query=*/BSONObj(), &cq));
Runner* runnerBare;
diff --git a/src/mongo/dbtests/indexcatalogtests.cpp b/src/mongo/dbtests/indexcatalogtests.cpp
index 8afba25af39..bf9b61cf5d3 100644
--- a/src/mongo/dbtests/indexcatalogtests.cpp
+++ b/src/mongo/dbtests/indexcatalogtests.cpp
@@ -31,22 +31,25 @@ namespace IndexCatalogTests {
class IndexIteratorTests {
public:
IndexIteratorTests() {
- Client::WriteContext ctx(_ns);
OperationContextImpl txn;
+ Client::WriteContext ctx(&txn, _ns);
+
_db = ctx.ctx().db();
_coll = _db->createCollection(&txn, _ns);
_catalog = _coll->getIndexCatalog();
}
~IndexIteratorTests() {
- Client::WriteContext ctx(_ns);
OperationContextImpl txn;
+ Client::WriteContext ctx(&txn, _ns);
+
_db->dropCollection(&txn, _ns);
}
void run() {
- Client::WriteContext ctx(_ns);
OperationContextImpl txn;
+ Client::WriteContext ctx(&txn, _ns);
+
int numFinishedIndexesStart = _catalog->numIndexesReady();
BSONObjBuilder b1;
diff --git a/src/mongo/dbtests/indexupdatetests.cpp b/src/mongo/dbtests/indexupdatetests.cpp
index 7c2f03662f6..792c1071d3e 100644
--- a/src/mongo/dbtests/indexupdatetests.cpp
+++ b/src/mongo/dbtests/indexupdatetests.cpp
@@ -55,7 +55,7 @@ namespace IndexUpdateTests {
class IndexBuildBase {
public:
IndexBuildBase() :
- _ctx( _ns ) {
+ _ctx(&_txn, _ns) {
_client.createCollection( _ns );
}
~IndexBuildBase() {
@@ -91,8 +91,9 @@ namespace IndexUpdateTests {
return collection()->getIndexCatalog()->findIndexByName( "a_1" );
}
#endif
- Client::WriteContext _ctx;
+
OperationContextImpl _txn;
+ Client::WriteContext _ctx;
};
/** addKeysToPhaseOne() adds keys from a collection's documents to an external sorter. */
diff --git a/src/mongo/dbtests/matchertests.cpp b/src/mongo/dbtests/matchertests.cpp
index 5bee238cda6..67bff7ef74b 100644
--- a/src/mongo/dbtests/matchertests.cpp
+++ b/src/mongo/dbtests/matchertests.cpp
@@ -33,6 +33,7 @@
#include "mongo/db/json.h"
#include "mongo/db/matcher/matcher.h"
+#include "mongo/db/operation_context_impl.h"
#include "mongo/dbtests/dbtests.h"
#include "mongo/util/timer.h"
@@ -216,7 +217,9 @@ namespace MatcherTests {
class WhereSimple1 {
public:
void run() {
- Client::ReadContext ctx( "unittests.matchertests" );
+ OperationContextImpl txn;
+ Client::ReadContext ctx(&txn, "unittests.matchertests");
+
M m(BSON("$where" << "function(){ return this.a == 1; }"),
WhereCallbackReal(StringData("unittests")));
ASSERT( m.matches( BSON( "a" << 1 ) ) );
diff --git a/src/mongo/dbtests/pdfiletests.cpp b/src/mongo/dbtests/pdfiletests.cpp
index 59d5f1bc483..5ef98e0b08b 100644
--- a/src/mongo/dbtests/pdfiletests.cpp
+++ b/src/mongo/dbtests/pdfiletests.cpp
@@ -164,7 +164,8 @@ namespace PdfileTests {
void run() {
SmallFilesControl c;
- Client::ReadContext ctx( "local" );
+ OperationContextImpl txn;
+ Client::ReadContext ctx(&txn, "local");
Database* db = ctx.ctx().db();
ExtentManager* em = db->getExtentManager();
diff --git a/src/mongo/dbtests/plan_ranking.cpp b/src/mongo/dbtests/plan_ranking.cpp
index 970e59a97ca..02939707de3 100644
--- a/src/mongo/dbtests/plan_ranking.cpp
+++ b/src/mongo/dbtests/plan_ranking.cpp
@@ -37,6 +37,7 @@
#include "mongo/db/index/index_descriptor.h"
#include "mongo/db/instance.h"
#include "mongo/db/json.h"
+#include "mongo/db/operation_context_impl.h"
#include "mongo/db/query/get_runner.h"
#include "mongo/db/query/qlog.h"
#include "mongo/db/query/query_knobs.h"
@@ -45,6 +46,7 @@
#include "mongo/db/query/stage_builder.h"
#include "mongo/dbtests/dbtests.h"
+
namespace mongo {
// How we access the external setParameter testing bool.
@@ -59,7 +61,7 @@ namespace PlanRankingTests {
class PlanRankingTestBase {
public:
PlanRankingTestBase() : _internalQueryForceIntersectionPlans(internalQueryForceIntersectionPlans) {
- Client::WriteContext ctx(ns);
+ Client::WriteContext ctx(&_txn, ns);
_client.dropCollection(ns);
}
@@ -69,12 +71,12 @@ namespace PlanRankingTests {
}
void insert(const BSONObj& obj) {
- Client::WriteContext ctx(ns);
+ Client::WriteContext ctx(&_txn, ns);
_client.insert(ns, obj);
}
void addIndex(const BSONObj& obj) {
- Client::WriteContext ctx(ns);
+ Client::WriteContext ctx(&_txn, ns);
_client.ensureIndex(ns, obj);
}
@@ -85,7 +87,7 @@ namespace PlanRankingTests {
* Takes ownership of 'cq'. Caller DOES NOT own the returned QuerySolution*.
*/
QuerySolution* pickBestPlan(CanonicalQuery* cq) {
- Client::ReadContext ctx(ns);
+ Client::ReadContext ctx(&_txn, ns);
Collection* collection = ctx.ctx().db()->getCollection(ns);
QueryPlannerParams plannerParams;
@@ -135,16 +137,17 @@ namespace PlanRankingTests {
// determining the number of documents in the tests below.
static const int N;
+ OperationContextImpl _txn;
+
private:
- static DBDirectClient _client;
+
+ DBDirectClient _client;
scoped_ptr<MultiPlanStage> _mps;
// Holds the value of global "internalQueryForceIntersectionPlans" setParameter flag.
// Restored at end of test invocation regardless of test result.
bool _internalQueryForceIntersectionPlans;
};
- DBDirectClient PlanRankingTestBase::_client;
-
// static
const int PlanRankingTestBase::N = internalQueryPlanEvaluationWorks + 1000;
diff --git a/src/mongo/dbtests/query_multi_plan_runner.cpp b/src/mongo/dbtests/query_multi_plan_runner.cpp
index bc853298488..99d1f61d172 100644
--- a/src/mongo/dbtests/query_multi_plan_runner.cpp
+++ b/src/mongo/dbtests/query_multi_plan_runner.cpp
@@ -38,6 +38,7 @@
#include "mongo/db/instance.h"
#include "mongo/db/json.h"
#include "mongo/db/matcher/expression_parser.h"
+#include "mongo/db/operation_context_impl.h"
#include "mongo/db/catalog/collection.h"
#include "mongo/dbtests/dbtests.h"
@@ -92,7 +93,8 @@ namespace QueryMultiPlanRunner {
class MPRCollectionScanVsHighlySelectiveIXScan : public MultiPlanRunnerBase {
public:
void run() {
- Client::WriteContext ctx(ns());
+ OperationContextImpl txn;
+ Client::WriteContext ctx(&txn, ns());
const int N = 5000;
for (int i = 0; i < N; ++i) {
diff --git a/src/mongo/dbtests/query_single_solution_runner.cpp b/src/mongo/dbtests/query_single_solution_runner.cpp
index 30d7ca0535f..3e2e1330323 100644
--- a/src/mongo/dbtests/query_single_solution_runner.cpp
+++ b/src/mongo/dbtests/query_single_solution_runner.cpp
@@ -39,6 +39,7 @@
#include "mongo/db/query/query_solution.h"
#include "mongo/db/query/single_solution_runner.h"
#include "mongo/db/catalog/collection.h"
+#include "mongo/db/operation_context_impl.h"
#include "mongo/dbtests/dbtests.h"
namespace QuerySingleSolutionRunner {
@@ -147,7 +148,7 @@ namespace QuerySingleSolutionRunner {
static const char* ns() { return "unittests.QueryStageSingleSolutionRunner"; }
size_t numCursors() {
- Client::ReadContext ctx( ns() );
+ Client::ReadContext ctx(&_txn, ns() );
Collection* collection = ctx.ctx().db()->getCollection( ns() );
if ( !collection )
return 0;
@@ -155,28 +156,29 @@ namespace QuerySingleSolutionRunner {
}
void registerRunner( Runner* runner ) {
- Client::ReadContext ctx( ns() );
+ Client::ReadContext ctx(&_txn, ns());
Collection* collection = ctx.ctx().db()->getOrCreateCollection( ns() );
return collection->cursorCache()->registerRunner( runner );
}
void deregisterRunner( Runner* runner ) {
- Client::ReadContext ctx( ns() );
+ Client::ReadContext ctx(&_txn, ns());
Collection* collection = ctx.ctx().db()->getOrCreateCollection( ns() );
return collection->cursorCache()->deregisterRunner( runner );
}
+ protected:
+ OperationContextImpl _txn;
+
private:
IndexDescriptor* getIndex(Database* db, const BSONObj& obj) {
Collection* collection = db->getCollection( ns() );
return collection->getIndexCatalog()->findIndexByKeyPattern(obj);
}
- static DBDirectClient _client;
+ DBDirectClient _client;
};
- DBDirectClient SingleSolutionRunnerBase::_client;
-
/**
* Test dropping the collection while the
* SingleSolutionRunner is doing a collection scan.
@@ -184,7 +186,7 @@ namespace QuerySingleSolutionRunner {
class DropCollScan : public SingleSolutionRunnerBase {
public:
void run() {
- Client::WriteContext ctx(ns());
+ Client::WriteContext ctx(&_txn, ns());
insert(BSON("_id" << 1));
insert(BSON("_id" << 2));
@@ -212,7 +214,7 @@ namespace QuerySingleSolutionRunner {
class DropIndexScan : public SingleSolutionRunnerBase {
public:
void run() {
- Client::WriteContext ctx(ns());
+ Client::WriteContext ctx(&_txn, ns());
insert(BSON("_id" << 1 << "a" << 6));
insert(BSON("_id" << 2 << "a" << 7));
insert(BSON("_id" << 3 << "a" << 8));
@@ -283,7 +285,7 @@ namespace QuerySingleSolutionRunner {
class SnapshotControl : public SnapshotBase {
public:
void run() {
- Client::WriteContext ctx(ns());
+ Client::WriteContext ctx(&_txn, ns());
setupCollection();
BSONObj filterObj = fromjson("{a: {$gte: 2}}");
@@ -308,7 +310,7 @@ namespace QuerySingleSolutionRunner {
class SnapshotTest : public SnapshotBase {
public:
void run() {
- Client::WriteContext ctx(ns());
+ Client::WriteContext ctx(&_txn, ns());
setupCollection();
BSONObj indexSpec = BSON("_id" << 1);
addIndex(indexSpec);
@@ -339,7 +341,7 @@ namespace QuerySingleSolutionRunner {
class Invalidate : public SingleSolutionRunnerBase {
public:
void run() {
- Client::WriteContext ctx(ns());
+ Client::WriteContext ctx(&_txn, ns());
insert(BSON("a" << 1 << "b" << 1));
BSONObj filterObj = fromjson("{_id: {$gt: 0}, b: {$gt: 0}}");
@@ -364,7 +366,7 @@ namespace QuerySingleSolutionRunner {
class InvalidatePinned : public SingleSolutionRunnerBase {
public:
void run() {
- Client::WriteContext ctx(ns());
+ Client::WriteContext ctx(&_txn, ns());
insert(BSON("a" << 1 << "b" << 1));
Collection* collection = ctx.ctx().db()->getCollection(ns());
@@ -402,12 +404,12 @@ namespace QuerySingleSolutionRunner {
public:
void run() {
{
- Client::WriteContext ctx(ns());
+ Client::WriteContext ctx(&_txn, ns());
insert(BSON("a" << 1 << "b" << 1));
}
{
- Client::ReadContext ctx(ns());
+ Client::ReadContext ctx(&_txn, ns());
Collection* collection = ctx.ctx().db()->getCollection(ns());
BSONObj filterObj = fromjson("{_id: {$gt: 0}, b: {$gt: 0}}");
@@ -420,7 +422,7 @@ namespace QuerySingleSolutionRunner {
// There should be one cursor before timeout,
// and zero cursors after timeout.
ASSERT_EQUALS(1U, numCursors());
- CollectionCursorCache::timeoutCursorsGlobal(600001);
+ CollectionCursorCache::timeoutCursorsGlobal(&_txn, 600001);
ASSERT_EQUALS(0U, numCursors());
}
};
diff --git a/src/mongo/dbtests/query_stage_and.cpp b/src/mongo/dbtests/query_stage_and.cpp
index 3f9d3526f2e..f1d33ff7fb8 100644
--- a/src/mongo/dbtests/query_stage_and.cpp
+++ b/src/mongo/dbtests/query_stage_and.cpp
@@ -109,12 +109,13 @@ namespace QueryStageAnd {
static const char* ns() { return "unittests.QueryStageAnd"; }
+ protected:
+ OperationContextImpl _txn;
+
private:
- static DBDirectClient _client;
+ DBDirectClient _client;
};
- DBDirectClient QueryStageAndBase::_client;
-
//
// Hash AND tests
//
@@ -126,12 +127,12 @@ namespace QueryStageAnd {
class QueryStageAndHashInvalidation : public QueryStageAndBase {
public:
void run() {
- Client::WriteContext ctx(ns());
+ Client::WriteContext ctx(&_txn, ns());
OperationContextImpl txn;
Database* db = ctx.ctx().db();
Collection* coll = db->getCollection(ns());
if (!coll) {
- coll = db->createCollection(&txn, ns());
+ coll = db->createCollection(&_txn, ns());
}
for (int i = 0; i < 50; ++i) {
@@ -228,12 +229,12 @@ namespace QueryStageAnd {
class QueryStageAndHashInvalidateLookahead : public QueryStageAndBase {
public:
void run() {
- Client::WriteContext ctx(ns());
+ Client::WriteContext ctx(&_txn, ns());
OperationContextImpl txn;
Database* db = ctx.ctx().db();
Collection* coll = db->getCollection(ns());
if (!coll) {
- coll = db->createCollection(&txn, ns());
+ coll = db->createCollection(&_txn, ns());
}
for (int i = 0; i < 50; ++i) {
@@ -314,12 +315,12 @@ namespace QueryStageAnd {
class QueryStageAndHashTwoLeaf : public QueryStageAndBase {
public:
void run() {
- Client::WriteContext ctx(ns());
+ Client::WriteContext ctx(&_txn, ns());
OperationContextImpl txn;
Database* db = ctx.ctx().db();
Collection* coll = db->getCollection(ns());
if (!coll) {
- coll = db->createCollection(&txn, ns());
+ coll = db->createCollection(&_txn, ns());
}
for (int i = 0; i < 50; ++i) {
@@ -363,12 +364,12 @@ namespace QueryStageAnd {
class QueryStageAndHashTwoLeafFirstChildLargeKeys : public QueryStageAndBase {
public:
void run() {
- Client::WriteContext ctx(ns());
+ Client::WriteContext ctx(&_txn, ns());
OperationContextImpl txn;
Database* db = ctx.ctx().db();
Collection* coll = db->getCollection(ns());
if (!coll) {
- coll = db->createCollection(&txn, ns());
+ coll = db->createCollection(&_txn, ns());
}
// Generate large keys for {foo: 1, big: 1} index.
@@ -415,12 +416,12 @@ namespace QueryStageAnd {
class QueryStageAndHashTwoLeafLastChildLargeKeys : public QueryStageAndBase {
public:
void run() {
- Client::WriteContext ctx(ns());
+ Client::WriteContext ctx(&_txn, ns());
OperationContextImpl txn;
Database* db = ctx.ctx().db();
Collection* coll = db->getCollection(ns());
if (!coll) {
- coll = db->createCollection(&txn, ns());
+ coll = db->createCollection(&_txn, ns());
}
// Generate large keys for {baz: 1, big: 1} index.
@@ -466,12 +467,12 @@ namespace QueryStageAnd {
class QueryStageAndHashThreeLeaf : public QueryStageAndBase {
public:
void run() {
- Client::WriteContext ctx(ns());
+ Client::WriteContext ctx(&_txn, ns());
OperationContextImpl txn;
Database* db = ctx.ctx().db();
Collection* coll = db->getCollection(ns());
if (!coll) {
- coll = db->createCollection(&txn, ns());
+ coll = db->createCollection(&_txn, ns());
}
for (int i = 0; i < 50; ++i) {
@@ -527,12 +528,12 @@ namespace QueryStageAnd {
class QueryStageAndHashThreeLeafMiddleChildLargeKeys : public QueryStageAndBase {
public:
void run() {
- Client::WriteContext ctx(ns());
+ Client::WriteContext ctx(&_txn, ns());
OperationContextImpl txn;
Database* db = ctx.ctx().db();
Collection* coll = db->getCollection(ns());
if (!coll) {
- coll = db->createCollection(&txn, ns());
+ coll = db->createCollection(&_txn, ns());
}
// Generate large keys for {bar: 1, big: 1} index.
@@ -586,12 +587,12 @@ namespace QueryStageAnd {
class QueryStageAndHashWithNothing : public QueryStageAndBase {
public:
void run() {
- Client::WriteContext ctx(ns());
+ Client::WriteContext ctx(&_txn, ns());
OperationContextImpl txn;
Database* db = ctx.ctx().db();
Collection* coll = db->getCollection(ns());
if (!coll) {
- coll = db->createCollection(&txn, ns());
+ coll = db->createCollection(&_txn, ns());
}
for (int i = 0; i < 50; ++i) {
@@ -645,12 +646,12 @@ namespace QueryStageAnd {
class QueryStageAndHashProducesNothing : public QueryStageAndBase {
public:
void run() {
- Client::WriteContext ctx(ns());
+ Client::WriteContext ctx(&_txn, ns());
OperationContextImpl txn;
Database* db = ctx.ctx().db();
Collection* coll = db->getCollection(ns());
if (!coll) {
- coll = db->createCollection(&txn, ns());
+ coll = db->createCollection(&_txn, ns());
}
for (int i = 0; i < 10; ++i) {
@@ -693,12 +694,12 @@ namespace QueryStageAnd {
class QueryStageAndHashWithMatcher : public QueryStageAndBase {
public:
void run() {
- Client::WriteContext ctx(ns());
+ Client::WriteContext ctx(&_txn, ns());
OperationContextImpl txn;
Database* db = ctx.ctx().db();
Collection* coll = db->getCollection(ns());
if (!coll) {
- coll = db->createCollection(&txn, ns());
+ coll = db->createCollection(&_txn, ns());
}
for (int i = 0; i < 50; ++i) {
@@ -749,12 +750,12 @@ namespace QueryStageAnd {
class QueryStageAndSortedInvalidation : public QueryStageAndBase {
public:
void run() {
- Client::WriteContext ctx(ns());
+ Client::WriteContext ctx(&_txn, ns());
OperationContextImpl txn;
Database* db = ctx.ctx().db();
Collection* coll = db->getCollection(ns());
if (!coll) {
- coll = db->createCollection(&txn, ns());
+ coll = db->createCollection(&_txn, ns());
}
// Insert a bunch of data
@@ -866,12 +867,12 @@ namespace QueryStageAnd {
class QueryStageAndSortedThreeLeaf : public QueryStageAndBase {
public:
void run() {
- Client::WriteContext ctx(ns());
+ Client::WriteContext ctx(&_txn, ns());
OperationContextImpl txn;
Database* db = ctx.ctx().db();
Collection* coll = db->getCollection(ns());
if (!coll) {
- coll = db->createCollection(&txn, ns());
+ coll = db->createCollection(&_txn, ns());
}
// Insert a bunch of data
@@ -919,12 +920,12 @@ namespace QueryStageAnd {
class QueryStageAndSortedWithNothing : public QueryStageAndBase {
public:
void run() {
- Client::WriteContext ctx(ns());
+ Client::WriteContext ctx(&_txn, ns());
OperationContextImpl txn;
Database* db = ctx.ctx().db();
Collection* coll = db->getCollection(ns());
if (!coll) {
- coll = db->createCollection(&txn, ns());
+ coll = db->createCollection(&_txn, ns());
}
@@ -964,12 +965,12 @@ namespace QueryStageAnd {
class QueryStageAndSortedProducesNothing : public QueryStageAndBase {
public:
void run() {
- Client::WriteContext ctx(ns());
+ Client::WriteContext ctx(&_txn, ns());
OperationContextImpl txn;
Database* db = ctx.ctx().db();
Collection* coll = db->getCollection(ns());
if (!coll) {
- coll = db->createCollection(&txn, ns());
+ coll = db->createCollection(&_txn, ns());
}
for (int i = 0; i < 50; ++i) {
@@ -1012,12 +1013,12 @@ namespace QueryStageAnd {
class QueryStageAndSortedWithMatcher : public QueryStageAndBase {
public:
void run() {
- Client::WriteContext ctx(ns());
+ Client::WriteContext ctx(&_txn, ns());
OperationContextImpl txn;
Database* db = ctx.ctx().db();
Collection* coll = db->getCollection(ns());
if (!coll) {
- coll = db->createCollection(&txn, ns());
+ coll = db->createCollection(&_txn, ns());
}
for (int i = 0; i < 50; ++i) {
@@ -1057,12 +1058,12 @@ namespace QueryStageAnd {
class QueryStageAndSortedByLastChild : public QueryStageAndBase {
public:
void run() {
- Client::WriteContext ctx(ns());
+ Client::WriteContext ctx(&_txn, ns());
OperationContextImpl txn;
Database* db = ctx.ctx().db();
Collection* coll = db->getCollection(ns());
if (!coll) {
- coll = db->createCollection(&txn, ns());
+ coll = db->createCollection(&_txn, ns());
}
for (int i = 0; i < 50; ++i) {
diff --git a/src/mongo/dbtests/query_stage_collscan.cpp b/src/mongo/dbtests/query_stage_collscan.cpp
index aa0fb3a2e65..fc30e82ad99 100644
--- a/src/mongo/dbtests/query_stage_collscan.cpp
+++ b/src/mongo/dbtests/query_stage_collscan.cpp
@@ -315,7 +315,7 @@ namespace QueryStageCollectionScan {
class QueryStageCollectionScanBase {
public:
QueryStageCollectionScanBase() {
- Client::WriteContext ctx(ns());
+ Client::WriteContext ctx(&_txn, ns());
for (int i = 0; i < numObj(); ++i) {
BSONObjBuilder bob;
@@ -325,7 +325,7 @@ namespace QueryStageCollectionScan {
}
virtual ~QueryStageCollectionScanBase() {
- Client::WriteContext ctx(ns());
+ Client::WriteContext ctx(&_txn, ns());
_client.dropCollection(ns());
}
@@ -334,7 +334,7 @@ namespace QueryStageCollectionScan {
}
int countResults(CollectionScanParams::Direction direction, const BSONObj& filterObj) {
- Client::ReadContext ctx(ns());
+ Client::ReadContext ctx(&_txn, ns());
// Configure the scan.
CollectionScanParams params;
@@ -384,11 +384,13 @@ namespace QueryStageCollectionScan {
static const char* ns() { return "unittests.QueryStageCollectionScan"; }
+ protected:
+ OperationContextImpl _txn;
+
private:
- static DBDirectClient _client;
+ DBDirectClient _client;
};
- DBDirectClient QueryStageCollectionScanBase::_client;
//
// Go forwards, get everything.
@@ -442,7 +444,7 @@ namespace QueryStageCollectionScan {
class QueryStageCollscanObjectsInOrderForward : public QueryStageCollectionScanBase {
public:
void run() {
- Client::ReadContext ctx(ns());
+ Client::ReadContext ctx(&_txn, ns());
// Configure the scan.
CollectionScanParams params;
@@ -473,7 +475,7 @@ namespace QueryStageCollectionScan {
class QueryStageCollscanObjectsInOrderBackward : public QueryStageCollectionScanBase {
public:
void run() {
- Client::ReadContext ctx(ns());
+ Client::ReadContext ctx(&_txn, ns());
CollectionScanParams params;
params.collection = ctx.ctx().db()->getCollection( ns() );
@@ -502,7 +504,7 @@ namespace QueryStageCollectionScan {
class QueryStageCollscanInvalidateUpcomingObject : public QueryStageCollectionScanBase {
public:
void run() {
- Client::WriteContext ctx(ns());
+ Client::WriteContext ctx(&_txn, ns());
Collection* coll = ctx.ctx().db()->getCollection( ns() );
@@ -564,7 +566,7 @@ namespace QueryStageCollectionScan {
class QueryStageCollscanInvalidateUpcomingObjectBackward : public QueryStageCollectionScanBase {
public:
void run() {
- Client::WriteContext ctx(ns());
+ Client::WriteContext ctx(&_txn, ns());
Collection* coll = ctx.ctx().db()->getCollection(ns());
// Get the DiskLocs that would be returned by an in-order scan.
diff --git a/src/mongo/dbtests/query_stage_count.cpp b/src/mongo/dbtests/query_stage_count.cpp
index 090bf068f63..0d0dcbc0673 100644
--- a/src/mongo/dbtests/query_stage_count.cpp
+++ b/src/mongo/dbtests/query_stage_count.cpp
@@ -37,6 +37,7 @@
#include "mongo/db/instance.h"
#include "mongo/db/json.h"
#include "mongo/db/matcher/expression_parser.h"
+#include "mongo/db/operation_context_impl.h"
#include "mongo/db/pdfile.h"
#include "mongo/db/catalog/collection.h"
#include "mongo/dbtests/dbtests.h"
@@ -51,7 +52,7 @@ namespace QueryStageCount {
CountBase() { }
virtual ~CountBase() {
- Client::WriteContext ctx(ns());
+ Client::WriteContext ctx(&_txn, ns());
_client.dropCollection(ns());
}
@@ -92,11 +93,13 @@ namespace QueryStageCount {
static const char* ns() { return "unittests.QueryStageCount"; }
+ protected:
+ OperationContextImpl _txn;
+
private:
- static DBDirectClient _client;
+ DBDirectClient _client;
};
-
- DBDirectClient CountBase::_client;
+
//
// Check that dups are properly identified
@@ -104,7 +107,7 @@ namespace QueryStageCount {
class QueryStageCountDups : public CountBase {
public:
void run() {
- Client::WriteContext ctx(ns());
+ Client::WriteContext ctx(&_txn, ns());
// Insert some docs
insert(BSON("a" << BSON_ARRAY(5 << 7)));
@@ -136,7 +139,7 @@ namespace QueryStageCount {
class QueryStageCountInclusiveBounds : public CountBase {
public:
void run() {
- Client::WriteContext ctx(ns());
+ Client::WriteContext ctx(&_txn, ns());
// Insert some docs
for (int i = 0; i < 10; ++i) {
@@ -168,7 +171,7 @@ namespace QueryStageCount {
class QueryStageCountExclusiveBounds : public CountBase {
public:
void run() {
- Client::WriteContext ctx(ns());
+ Client::WriteContext ctx(&_txn, ns());
// Insert some docs
for (int i = 0; i < 10; ++i) {
@@ -200,7 +203,7 @@ namespace QueryStageCount {
class QueryStageCountLowerBound : public CountBase {
public:
void run() {
- Client::WriteContext ctx(ns());
+ Client::WriteContext ctx(&_txn, ns());
// Insert doc, add index
insert(BSON("a" << 2));
@@ -228,7 +231,7 @@ namespace QueryStageCount {
class QueryStageCountNothingInInterval : public CountBase {
public:
void run() {
- Client::WriteContext ctx(ns());
+ Client::WriteContext ctx(&_txn, ns());
// Insert documents, add index
insert(BSON("a" << 2));
@@ -258,7 +261,7 @@ namespace QueryStageCount {
class QueryStageCountNothingInIntervalFirstMatchTooHigh : public CountBase {
public:
void run() {
- Client::WriteContext ctx(ns());
+ Client::WriteContext ctx(&_txn, ns());
// Insert some documents, add index
insert(BSON("a" << 2));
@@ -288,7 +291,7 @@ namespace QueryStageCount {
class QueryStageCountNoChangeDuringYield : public CountBase {
public:
void run() {
- Client::WriteContext ctx(ns());
+ Client::WriteContext ctx(&_txn, ns());
// Insert documents, add index
for (int i = 0; i < 10; ++i) {
@@ -339,7 +342,7 @@ namespace QueryStageCount {
class QueryStageCountDeleteDuringYield : public CountBase {
public:
void run() {
- Client::WriteContext ctx(ns());
+ Client::WriteContext ctx(&_txn, ns());
// Insert documents, add index
for (int i = 0; i < 10; ++i) {
@@ -393,7 +396,7 @@ namespace QueryStageCount {
class QueryStageCountInsertNewDocsDuringYield : public CountBase {
public:
void run() {
- Client::WriteContext ctx(ns());
+ Client::WriteContext ctx(&_txn, ns());
// Insert documents, add index
for (int i = 0; i < 10; ++i) {
@@ -450,7 +453,7 @@ namespace QueryStageCount {
class QueryStageCountBecomesMultiKeyDuringYield : public CountBase {
public:
void run() {
- Client::WriteContext ctx(ns());
+ Client::WriteContext ctx(&_txn, ns());
// Insert documents, add index
for (int i = 0; i < 10; ++i) {
@@ -503,7 +506,7 @@ namespace QueryStageCount {
class QueryStageCountUnusedKeys : public CountBase {
public:
void run() {
- Client::WriteContext ctx(ns());
+ Client::WriteContext ctx(&_txn, ns());
// Insert docs, add index
for (int i = 0; i < 10; ++i) {
@@ -538,7 +541,7 @@ namespace QueryStageCount {
class QueryStageCountUnusedEndKey : public CountBase {
public:
void run() {
- Client::WriteContext ctx(ns());
+ Client::WriteContext ctx(&_txn, ns());
// Insert docs, add index
for (int i = 0; i < 10; ++i) {
@@ -571,7 +574,7 @@ namespace QueryStageCount {
class QueryStageCountKeyBecomesUnusedDuringYield : public CountBase {
public:
void run() {
- Client::WriteContext ctx(ns());
+ Client::WriteContext ctx(&_txn, ns());
// Insert documents, add index
for (int i = 0; i < 10; ++i) {
diff --git a/src/mongo/dbtests/query_stage_distinct.cpp b/src/mongo/dbtests/query_stage_distinct.cpp
index 37a0a6473b1..ecbbbaf5561 100644
--- a/src/mongo/dbtests/query_stage_distinct.cpp
+++ b/src/mongo/dbtests/query_stage_distinct.cpp
@@ -32,6 +32,7 @@
#include "mongo/db/exec/plan_stage.h"
#include "mongo/db/instance.h"
#include "mongo/db/json.h"
+#include "mongo/db/operation_context_impl.h"
#include "mongo/db/query/index_bounds_builder.h"
#include "mongo/db/query/plan_executor.h"
#include "mongo/db/catalog/collection.h"
@@ -48,22 +49,22 @@ namespace QueryStageDistinct {
DistinctBase() { }
virtual ~DistinctBase() {
- Client::WriteContext ctx(ns());
+ Client::WriteContext ctx(&_txn, ns());
_client.dropCollection(ns());
}
void addIndex(const BSONObj& obj) {
- Client::WriteContext ctx(ns());
+ Client::WriteContext ctx(&_txn, ns());
_client.ensureIndex(ns(), obj);
}
void insert(const BSONObj& obj) {
- Client::WriteContext ctx(ns());
+ Client::WriteContext ctx(&_txn, ns());
_client.insert(ns(), obj);
}
IndexDescriptor* getIndex(const BSONObj& obj) {
- Client::ReadContext ctx(ns());
+ Client::ReadContext ctx(&_txn, ns());
Collection* collection = ctx.ctx().db()->getCollection( ns() );
return collection->getIndexCatalog()->findIndexByKeyPattern( obj );
}
@@ -96,11 +97,13 @@ namespace QueryStageDistinct {
static const char* ns() { return "unittests.QueryStageDistinct"; }
+ protected:
+ OperationContextImpl _txn;
+
private:
- static DBDirectClient _client;
+ DBDirectClient _client;
};
- DBDirectClient DistinctBase::_client;
// Tests distinct with single key indices.
class QueryStageDistinctBasic : public DistinctBase {
@@ -121,7 +124,7 @@ namespace QueryStageDistinct {
// Make an index on a:1
addIndex(BSON("a" << 1));
- Client::ReadContext ctx(ns());
+ Client::ReadContext ctx(&_txn, ns());
// Set up the distinct stage.
DistinctParams params;
@@ -184,7 +187,7 @@ namespace QueryStageDistinct {
// Make an index on a:1
addIndex(BSON("a" << 1));
- Client::ReadContext ctx(ns());
+ Client::ReadContext ctx(&_txn, ns());
// Set up the distinct stage.
DistinctParams params;
diff --git a/src/mongo/dbtests/query_stage_fetch.cpp b/src/mongo/dbtests/query_stage_fetch.cpp
index 4aaaa2657b7..b99a95b1d87 100644
--- a/src/mongo/dbtests/query_stage_fetch.cpp
+++ b/src/mongo/dbtests/query_stage_fetch.cpp
@@ -87,8 +87,9 @@ namespace QueryStageFetch {
class FetchStageAlreadyFetched : public QueryStageFetchBase {
public:
void run() {
- Client::WriteContext ctx(ns());
OperationContextImpl txn;
+ Client::WriteContext ctx(&txn, ns());
+
Database* db = ctx.ctx().db();
Collection* coll = db->getCollection(ns());
if (!coll) {
@@ -145,8 +146,9 @@ namespace QueryStageFetch {
class FetchStageFilter : public QueryStageFetchBase {
public:
void run() {
- Client::WriteContext ctx(ns());
OperationContextImpl txn;
+ Client::WriteContext ctx(&txn, ns());
+
Database* db = ctx.ctx().db();
Collection* coll = db->getCollection(ns());
if (!coll) {
diff --git a/src/mongo/dbtests/query_stage_keep.cpp b/src/mongo/dbtests/query_stage_keep.cpp
index c030387ff09..5ea488a37f2 100644
--- a/src/mongo/dbtests/query_stage_keep.cpp
+++ b/src/mongo/dbtests/query_stage_keep.cpp
@@ -104,8 +104,9 @@ namespace QueryStageKeep {
class KeepStageBasic : public QueryStageKeepBase {
public:
void run() {
- Client::WriteContext ctx(ns());
OperationContextImpl txn;
+ Client::WriteContext ctx(&txn, ns());
+
Database* db = ctx.ctx().db();
Collection* coll = db->getCollection(ns());
if (!coll) {
diff --git a/src/mongo/dbtests/query_stage_merge_sort.cpp b/src/mongo/dbtests/query_stage_merge_sort.cpp
index 6ddf69290e5..43319528bb2 100644
--- a/src/mongo/dbtests/query_stage_merge_sort.cpp
+++ b/src/mongo/dbtests/query_stage_merge_sort.cpp
@@ -50,7 +50,7 @@ namespace QueryStageMergeSortTests {
QueryStageMergeSortTestBase() { }
virtual ~QueryStageMergeSortTestBase() {
- Client::WriteContext ctx(ns());
+ Client::WriteContext ctx(&_txn, ns());
_client.dropCollection(ns());
}
@@ -95,23 +95,25 @@ namespace QueryStageMergeSortTests {
}
static const char* ns() { return "unittests.QueryStageMergeSort"; }
+
+ protected:
+ OperationContextImpl _txn;
+
private:
- static DBDirectClient _client;
+ DBDirectClient _client;
};
- DBDirectClient QueryStageMergeSortTestBase::_client;
-
// SERVER-1205:
// find($or[{a:1}, {b:1}]).sort({c:1}) with indices {a:1, c:1} and {b:1, c:1}.
class QueryStageMergeSortPrefixIndex : public QueryStageMergeSortTestBase {
public:
void run() {
- Client::WriteContext ctx(ns());
+ Client::WriteContext ctx(&_txn, ns());
OperationContextImpl txn;
Database* db = ctx.ctx().db();
Collection* coll = db->getCollection(ns());
if (!coll) {
- coll = db->createCollection(&txn, ns());
+ coll = db->createCollection(&_txn, ns());
}
const int N = 50;
@@ -170,12 +172,12 @@ namespace QueryStageMergeSortTests {
class QueryStageMergeSortDups : public QueryStageMergeSortTestBase {
public:
void run() {
- Client::WriteContext ctx(ns());
+ Client::WriteContext ctx(&_txn, ns());
OperationContextImpl txn;
Database* db = ctx.ctx().db();
Collection* coll = db->getCollection(ns());
if (!coll) {
- coll = db->createCollection(&txn, ns());
+ coll = db->createCollection(&_txn, ns());
}
const int N = 50;
@@ -233,12 +235,12 @@ namespace QueryStageMergeSortTests {
class QueryStageMergeSortDupsNoDedup : public QueryStageMergeSortTestBase {
public:
void run() {
- Client::WriteContext ctx(ns());
+ Client::WriteContext ctx(&_txn, ns());
OperationContextImpl txn;
Database* db = ctx.ctx().db();
Collection* coll = db->getCollection(ns());
if (!coll) {
- coll = db->createCollection(&txn, ns());
+ coll = db->createCollection(&_txn, ns());
}
const int N = 50;
@@ -297,12 +299,12 @@ namespace QueryStageMergeSortTests {
class QueryStageMergeSortPrefixIndexReverse : public QueryStageMergeSortTestBase {
public:
void run() {
- Client::WriteContext ctx(ns());
+ Client::WriteContext ctx(&_txn, ns());
OperationContextImpl txn;
Database* db = ctx.ctx().db();
Collection* coll = db->getCollection(ns());
if (!coll) {
- coll = db->createCollection(&txn, ns());
+ coll = db->createCollection(&_txn, ns());
}
const int N = 50;
@@ -362,12 +364,12 @@ namespace QueryStageMergeSortTests {
class QueryStageMergeSortOneStageEOF : public QueryStageMergeSortTestBase {
public:
void run() {
- Client::WriteContext ctx(ns());
+ Client::WriteContext ctx(&_txn, ns());
OperationContextImpl txn;
Database* db = ctx.ctx().db();
Collection* coll = db->getCollection(ns());
if (!coll) {
- coll = db->createCollection(&txn, ns());
+ coll = db->createCollection(&_txn, ns());
}
const int N = 50;
@@ -425,12 +427,12 @@ namespace QueryStageMergeSortTests {
class QueryStageMergeSortManyShort : public QueryStageMergeSortTestBase {
public:
void run() {
- Client::WriteContext ctx(ns());
+ Client::WriteContext ctx(&_txn, ns());
OperationContextImpl txn;
Database* db = ctx.ctx().db();
Collection* coll = db->getCollection(ns());
if (!coll) {
- coll = db->createCollection(&txn, ns());
+ coll = db->createCollection(&_txn, ns());
}
WorkingSet* ws = new WorkingSet();
@@ -478,12 +480,12 @@ namespace QueryStageMergeSortTests {
class QueryStageMergeSortInvalidation : public QueryStageMergeSortTestBase {
public:
void run() {
- Client::WriteContext ctx(ns());
+ Client::WriteContext ctx(&_txn, ns());
OperationContextImpl txn;
Database* db = ctx.ctx().db();
Collection* coll = db->getCollection(ns());
if (!coll) {
- coll = db->createCollection(&txn, ns());
+ coll = db->createCollection(&_txn, ns());
}
WorkingSet ws;
diff --git a/src/mongo/dbtests/query_stage_sort.cpp b/src/mongo/dbtests/query_stage_sort.cpp
index f0605a7abbc..2440f67948f 100644
--- a/src/mongo/dbtests/query_stage_sort.cpp
+++ b/src/mongo/dbtests/query_stage_sort.cpp
@@ -169,10 +169,9 @@ namespace QueryStageSortTests {
static const char* ns() { return "unittests.QueryStageSort"; }
private:
- static DBDirectClient _client;
+ DBDirectClient _client;
};
- DBDirectClient QueryStageSortTestBase::_client;
// Sort some small # of results in increasing order.
class QueryStageSortInc: public QueryStageSortTestBase {
@@ -180,8 +179,9 @@ namespace QueryStageSortTests {
virtual int numObj() { return 100; }
void run() {
- Client::WriteContext ctx(ns());
OperationContextImpl txn;
+ Client::WriteContext ctx(&txn, ns());
+
Database* db = ctx.ctx().db();
Collection* coll = db->getCollection(ns());
if (!coll) {
@@ -199,8 +199,9 @@ namespace QueryStageSortTests {
virtual int numObj() { return 100; }
void run() {
- Client::WriteContext ctx(ns());
OperationContextImpl txn;
+ Client::WriteContext ctx(&txn, ns());
+
Database* db = ctx.ctx().db();
Collection* coll = db->getCollection(ns());
if (!coll) {
@@ -227,8 +228,9 @@ namespace QueryStageSortTests {
virtual int numObj() { return 10000; }
void run() {
- Client::WriteContext ctx(ns());
OperationContextImpl txn;
+ Client::WriteContext ctx(&txn, ns());
+
Database* db = ctx.ctx().db();
Collection* coll = db->getCollection(ns());
if (!coll) {
@@ -246,8 +248,9 @@ namespace QueryStageSortTests {
virtual int numObj() { return 2000; }
void run() {
- Client::WriteContext ctx(ns());
OperationContextImpl txn;
+ Client::WriteContext ctx(&txn, ns());
+
Database* db = ctx.ctx().db();
Collection* coll = db->getCollection(ns());
if (!coll) {
@@ -336,8 +339,9 @@ namespace QueryStageSortTests {
virtual int numObj() { return 100; }
void run() {
- Client::WriteContext ctx(ns());
OperationContextImpl txn;
+ Client::WriteContext ctx(&txn, ns());
+
Database* db = ctx.ctx().db();
Collection* coll = db->getCollection(ns());
if (!coll) {
diff --git a/src/mongo/dbtests/query_stage_tests.cpp b/src/mongo/dbtests/query_stage_tests.cpp
index 3bf9b0ca31f..7e0b0f20c6e 100644
--- a/src/mongo/dbtests/query_stage_tests.cpp
+++ b/src/mongo/dbtests/query_stage_tests.cpp
@@ -33,6 +33,7 @@
#include "mongo/db/instance.h"
#include "mongo/db/json.h"
#include "mongo/db/matcher/expression_parser.h"
+#include "mongo/db/operation_context_impl.h"
#include "mongo/db/query/plan_executor.h"
#include "mongo/db/catalog/collection.h"
#include "mongo/dbtests/dbtests.h"
@@ -46,7 +47,7 @@ namespace QueryStageTests {
class IndexScanBase {
public:
IndexScanBase() {
- Client::WriteContext ctx(ns());
+ Client::WriteContext ctx(&_txn, ns());
for (int i = 0; i < numObj(); ++i) {
BSONObjBuilder bob;
@@ -61,17 +62,17 @@ namespace QueryStageTests {
}
virtual ~IndexScanBase() {
- Client::WriteContext ctx(ns());
+ Client::WriteContext ctx(&_txn, ns());
_client.dropCollection(ns());
}
void addIndex(const BSONObj& obj) {
- Client::WriteContext ctx(ns());
+ Client::WriteContext ctx(&_txn, ns());
_client.ensureIndex(ns(), obj);
}
int countResults(const IndexScanParams& params, BSONObj filterObj = BSONObj()) {
- Client::ReadContext ctx(ns());
+ Client::ReadContext ctx(&_txn, ns());
StatusWithMatchExpression swme = MatchExpressionParser::parse(filterObj);
verify(swme.isOK());
@@ -91,7 +92,7 @@ namespace QueryStageTests {
}
void makeGeoData() {
- Client::WriteContext ctx(ns());
+ Client::WriteContext ctx(&_txn, ns());
for (int i = 0; i < numObj(); ++i) {
double lat = double(rand()) / RAND_MAX;
@@ -101,7 +102,7 @@ namespace QueryStageTests {
}
IndexDescriptor* getIndex(const BSONObj& obj) {
- Client::ReadContext ctx(ns());
+ Client::ReadContext ctx(&_txn, ns());
Collection* collection = ctx.ctx().db()->getCollection( ns() );
return collection->getIndexCatalog()->findIndexByKeyPattern( obj );
}
@@ -109,12 +110,13 @@ namespace QueryStageTests {
static int numObj() { return 50; }
static const char* ns() { return "unittests.IndexScan"; }
+ protected:
+ OperationContextImpl _txn;
+
private:
- static DBDirectClient _client;
+ DBDirectClient _client;
};
- DBDirectClient IndexScanBase::_client;
-
class QueryStageIXScanBasic : public IndexScanBase {
public:
virtual ~QueryStageIXScanBasic() { }
diff --git a/src/mongo/dbtests/querytests.cpp b/src/mongo/dbtests/querytests.cpp
index 0f834d1d50c..0e73c01e3b5 100644
--- a/src/mongo/dbtests/querytests.cpp
+++ b/src/mongo/dbtests/querytests.cpp
@@ -157,14 +157,13 @@ namespace QueryTests {
// an empty object (one might be allowed inside a reserved namespace at some point).
Lock::GlobalWrite lk;
Client::Context ctx( "unittests.querytests" );
- OperationContextImpl txn;
Database* db = ctx.db();
if ( db->getCollection( ns() ) ) {
_collection = NULL;
- db->dropCollection( &txn, ns() );
+ db->dropCollection( &_txn, ns() );
}
- _collection = db->createCollection( &txn, ns(), CollectionOptions(), true, false );
+ _collection = db->createCollection( &_txn, ns(), CollectionOptions(), true, false );
ASSERT( _collection );
DBDirectClient cl;
@@ -189,21 +188,25 @@ namespace QueryTests {
~ClientBase() {
//mongo::lastError.release();
}
+
protected:
- static void insert( const char *ns, BSONObj o ) {
+ void insert( const char *ns, BSONObj o ) {
client_.insert( ns, o );
}
- static void update( const char *ns, BSONObj q, BSONObj o, bool upsert = 0 ) {
+ void update( const char *ns, BSONObj q, BSONObj o, bool upsert = 0 ) {
client_.update( ns, Query( q ), o, upsert );
}
- static bool error() {
+ bool error() {
return !client_.getPrevError().getField( "err" ).isNull();
}
- DBDirectClient &client() const { return client_; }
- static DBDirectClient client_;
+ const DBDirectClient& client() const { return client_; }
+ DBDirectClient& client() { return client_; }
+
+ DBDirectClient client_;
+
+ OperationContextImpl _txn;
};
- DBDirectClient ClientBase::client_;
class BoundedKey : public ClientBase {
public:
@@ -239,7 +242,7 @@ namespace QueryTests {
{
// Check internal server handoff to getmore.
- Lock::DBWrite lk(ns);
+ Lock::DBWrite lk(_txn.lockState(), ns);
Client::Context ctx( ns );
ClientCursorPin clientCursor( ctx.db()->getCollection(ns), cursorId );
// pq doesn't exist if it's a runner inside of the clientcursor.
@@ -252,6 +255,9 @@ namespace QueryTests {
ASSERT( cursor->more() );
ASSERT_EQUALS( 3, cursor->next().getIntField( "a" ) );
}
+
+ protected:
+ OperationContextImpl _txn;
};
/**
@@ -294,10 +300,11 @@ namespace QueryTests {
// Check that the cursor has been removed.
{
- Client::ReadContext ctx( ns );
+ Client::ReadContext ctx(&_txn, ns);
ASSERT( 0 == ctx.ctx().db()->getCollection( ns )->cursorCache()->numCursors() );
}
- ASSERT_FALSE( CollectionCursorCache::eraseCursorGlobal( cursorId ) );
+
+ ASSERT_FALSE(CollectionCursorCache::eraseCursorGlobal(&_txn, cursorId));
// Check that a subsequent get more fails with the cursor removed.
ASSERT_THROWS( client().getMore( ns, cursorId ), UserException );
@@ -343,7 +350,7 @@ namespace QueryTests {
// Check that the cursor still exists
{
- Client::ReadContext ctx( ns );
+ Client::ReadContext ctx(&_txn, ns);
ASSERT( 1 == ctx.ctx().db()->getCollection( ns )->cursorCache()->numCursors() );
ASSERT( ctx.ctx().db()->getCollection( ns )->cursorCache()->find( cursorId, false ) );
}
@@ -583,7 +590,7 @@ namespace QueryTests {
}
void run() {
const char *ns = "unittests.querytests.OplogReplaySlaveReadTill";
- Lock::DBWrite lk(ns);
+ Lock::DBWrite lk(_txn.lockState(), ns);
Client::Context ctx( ns );
BSONObj info;
@@ -654,7 +661,7 @@ namespace QueryTests {
count( 2 );
}
private:
- void count( unsigned long long c ) const {
+ void count( unsigned long long c ) {
ASSERT_EQUALS( c, client().count( "unittests.querytests.BasicCount", BSON( "a" << 4 ) ) );
}
};
@@ -749,8 +756,8 @@ namespace QueryTests {
}
static const char *ns() { return "unittests.querytests.AutoResetIndexCache"; }
static const char *idxNs() { return "unittests.system.indexes"; }
- void index() const { ASSERT( !client().findOne( idxNs(), BSON( "name" << NE << "_id_" ) ).isEmpty() ); }
- void noIndex() const {
+ void index() { ASSERT( !client().findOne( idxNs(), BSON( "name" << NE << "_id_" ) ).isEmpty() ); }
+ void noIndex() {
BSONObj o = client().findOne( idxNs(), BSON( "name" << NE << "_id_" ) );
if( !o.isEmpty() ) {
cout << o.toString() << endl;
@@ -1130,7 +1137,7 @@ namespace QueryTests {
}
size_t numCursorsOpen() {
- Client::ReadContext ctx( _ns );
+ Client::ReadContext ctx(&_txn, _ns);
Collection* collection = ctx.ctx().db()->getCollection( _ns );
if ( !collection )
return 0;
@@ -1172,16 +1179,13 @@ namespace QueryTests {
}
void run() {
string err;
-
- Client::WriteContext ctx( "unittests" );
- OperationContextImpl txn;
+ Client::WriteContext ctx(&_txn, "unittests" );
// note that extents are always at least 4KB now - so this will get rounded up a bit.
- ASSERT( userCreateNS( &txn, ctx.ctx().db(), ns(),
+ ASSERT( userCreateNS( &_txn, ctx.ctx().db(), ns(),
fromjson( "{ capped : true, size : 2000 }" ), false ).isOK() );
for ( int i=0; i<200; i++ ) {
insertNext();
-// cout << count() << endl;
ASSERT( count() < 90 );
}
@@ -1224,7 +1228,7 @@ namespace QueryTests {
}
void run() {
- Client::WriteContext ctx( "unittests" );
+ Client::WriteContext ctx(&_txn, "unittests" );
for ( int i=0; i<50; i++ ) {
insert( ns() , BSON( "_id" << i << "x" << i * 2 ) );
@@ -1275,7 +1279,7 @@ namespace QueryTests {
}
void run() {
- Client::WriteContext ctx( "unittests" );
+ Client::WriteContext ctx(&_txn, "unittests" );
for ( int i=0; i<1000; i++ ) {
insert( ns() , BSON( "_id" << i << "x" << i * 2 ) );
@@ -1298,7 +1302,7 @@ namespace QueryTests {
}
void run() {
- Client::WriteContext ctx( "unittests" );
+ Client::WriteContext ctx(&_txn, "unittests" );
for ( int i=0; i<1000; i++ ) {
insert( ns() , BSON( "_id" << i << "x" << i * 2 ) );
@@ -1414,7 +1418,7 @@ namespace QueryTests {
public:
CollectionInternalBase( const char *nsLeaf ) :
CollectionBase( nsLeaf ),
- _lk( ns() ),
+ _lk(_txn.lockState(), ns() ),
_ctx( ns() ) {
}
private:
@@ -1439,8 +1443,7 @@ namespace QueryTests {
DbMessage dbMessage( message );
QueryMessage queryMessage( dbMessage );
Message result;
- OperationContextImpl txn;
- string exhaust = newRunQuery( &txn, message, queryMessage, *cc().curop(), result );
+ string exhaust = newRunQuery( &_txn, message, queryMessage, *cc().curop(), result );
ASSERT( exhaust.size() );
ASSERT_EQUALS( string( ns() ), exhaust );
}
@@ -1459,7 +1462,7 @@ namespace QueryTests {
ClientCursor *clientCursor = 0;
{
- Client::ReadContext ctx( ns() );
+ Client::ReadContext ctx(&_txn, ns());
ClientCursorPin clientCursorPointer( ctx.ctx().db()->getCollection( ns() ),
cursorId );
clientCursor = clientCursorPointer.c();
@@ -1497,10 +1500,11 @@ namespace QueryTests {
long long cursorId = cursor->getCursorId();
{
- Client::WriteContext ctx( ns() );
+ Client::WriteContext ctx(&_txn, ns() );
ClientCursorPin pinCursor( ctx.ctx().db()->getCollection( ns() ), cursorId );
-
- ASSERT_THROWS( client().killCursor( cursorId ), MsgAssertionException );
+
+ ASSERT_THROWS(CollectionCursorCache::eraseCursorGlobal(&_txn, cursorId),
+ MsgAssertionException);
string expectedAssertion =
str::stream() << "Cannot kill active cursor " << cursorId;
ASSERT_EQUALS( expectedAssertion, client().getLastError() );
diff --git a/src/mongo/dbtests/replsettests.cpp b/src/mongo/dbtests/replsettests.cpp
index fb2a2afdd0a..deb82f41e17 100644
--- a/src/mongo/dbtests/replsettests.cpp
+++ b/src/mongo/dbtests/replsettests.cpp
@@ -147,9 +147,10 @@ namespace ReplSetTests {
DBDirectClient *client() const { return &client_; }
static void insert( const BSONObj &o, bool god = false ) {
- Lock::DBWrite lk(ns());
- Client::Context ctx(ns());
OperationContextImpl txn;
+ Lock::DBWrite lk(txn.lockState(), ns());
+ Client::Context ctx(ns());
+
Database* db = ctx.db();
Collection* coll = db->getCollection(ns());
if (!coll) {
@@ -174,8 +175,8 @@ namespace ReplSetTests {
}
void drop() {
- Client::WriteContext c(ns());
OperationContextImpl txn;
+ Client::WriteContext c(&txn, ns());
Database* db = c.ctx().db();
@@ -306,6 +307,8 @@ namespace ReplSetTests {
class CappedInitialSync : public Base {
string _cappedNs;
+
+ OperationContextImpl _txn;
Lock::DBWrite _lk;
string spec() const {
@@ -342,7 +345,8 @@ namespace ReplSetTests {
return o;
}
public:
- CappedInitialSync() : _cappedNs("unittests.foo.bar"), _lk(_cappedNs) {
+ CappedInitialSync() :
+ _cappedNs("unittests.foo.bar"), _lk(_txn.lockState(), _cappedNs) {
dropCapped();
create();
}
@@ -363,7 +367,8 @@ namespace ReplSetTests {
}
void run() {
- Lock::DBWrite lk(_cappedNs);
+ OperationContextImpl txn;
+ Lock::DBWrite lk(txn.lockState(), _cappedNs);
BSONObj op = updateFail();
diff --git a/src/mongo/dbtests/runner_registry.cpp b/src/mongo/dbtests/runner_registry.cpp
index 8881ff2d4f3..b29088e36d8 100644
--- a/src/mongo/dbtests/runner_registry.cpp
+++ b/src/mongo/dbtests/runner_registry.cpp
@@ -51,7 +51,7 @@ namespace RunnerRegistry {
class RunnerRegistryBase {
public:
RunnerRegistryBase() {
- _ctx.reset(new Client::WriteContext(ns()));
+ _ctx.reset(new Client::WriteContext(&_opCtx, ns()));
_client.dropCollection(ns());
for (int i = 0; i < N(); ++i) {
@@ -269,7 +269,7 @@ namespace RunnerRegistry {
// requires a "global write lock."
_ctx.reset();
_client.dropDatabase("somesillydb");
- _ctx.reset(new Client::WriteContext(ns()));
+ _ctx.reset(new Client::WriteContext(&_opCtx, ns()));
// Unregister and restore state.
deregisterRunner(run.get());
@@ -285,7 +285,7 @@ namespace RunnerRegistry {
// Drop our DB. Once again, must give up the lock.
_ctx.reset();
_client.dropDatabase("unittests");
- _ctx.reset(new Client::WriteContext(ns()));
+ _ctx.reset(new Client::WriteContext(&_opCtx, ns()));
// Unregister and restore state.
deregisterRunner(run.get());
diff --git a/src/mongo/dbtests/threadedtests.cpp b/src/mongo/dbtests/threadedtests.cpp
index b5537364525..96e6e0df7b4 100644
--- a/src/mongo/dbtests/threadedtests.cpp
+++ b/src/mongo/dbtests/threadedtests.cpp
@@ -35,6 +35,7 @@
#include "mongo/bson/util/atomic_int.h"
#include "mongo/db/d_concurrency.h"
+#include "mongo/db/operation_context_impl.h"
#include "mongo/dbtests/dbtests.h"
#include "mongo/platform/atomic_word.h"
#include "mongo/stdx/functional.h"
@@ -115,6 +116,8 @@ namespace ThreadedTests {
}
virtual void subthread(int tnumber) {
Client::initThread("mongomutextest");
+ LockState lockState;
+
sleepmillis(0);
for( int i = 0; i < N; i++ ) {
int x = std::rand();
@@ -169,13 +172,13 @@ namespace ThreadedTests {
}
else if( i % 7 == 5 ) {
{
- Lock::DBRead r("foo");
+ Lock::DBRead r(&lockState, "foo");
if( sometimes ) {
Lock::TempRelease t;
}
}
{
- Lock::DBRead r("bar");
+ Lock::DBRead r(&lockState, "bar");
}
}
else if( i % 7 == 6 ) {
@@ -183,13 +186,13 @@ namespace ThreadedTests {
int q = i % 11;
if( q == 0 ) {
char what = 'r';
- Lock::DBRead r("foo");
+ Lock::DBRead r(&lockState, "foo");
ASSERT( Lock::isLocked() == what && Lock::atLeastReadLocked("foo") );
ASSERT( !Lock::nested() );
- Lock::DBRead r2("foo");
+ Lock::DBRead r2(&lockState, "foo");
ASSERT( Lock::nested() );
ASSERT( Lock::isLocked() == what && Lock::atLeastReadLocked("foo") );
- Lock::DBRead r3("local");
+ Lock::DBRead r3(&lockState, "local");
if( sometimes ) {
Lock::TempRelease t;
}
@@ -199,41 +202,48 @@ namespace ThreadedTests {
else if( q == 1 ) {
// test locking local only -- with no preceeding lock
{
- Lock::DBRead x("local");
+ Lock::DBRead x(&lockState, "local");
//Lock::DBRead y("q");
if( sometimes ) {
Lock::TempRelease t; // we don't temprelease (cant=true) here thus this is just a check that nothing weird happens...
}
}
- {
- Lock::DBWrite x("local");
+ {
+ OperationContextImpl txn;
+ Lock::DBWrite x(txn.lockState(), "local");
if( sometimes ) {
Lock::TempRelease t;
}
}
} else if( q == 1 ) {
- { Lock::DBRead x("admin"); }
- { Lock::DBWrite x("admin"); }
+ { Lock::DBRead x(&lockState, "admin"); }
+ {
+ OperationContextImpl txn;
+ Lock::DBWrite x(txn.lockState(), "admin");
+ }
} else if( q == 2 ) {
/*Lock::DBWrite x("foo");
Lock::DBWrite y("admin");
{ Lock::TempRelease t; }*/
}
else if( q == 3 ) {
- Lock::DBWrite x("foo");
- Lock::DBRead y("admin");
+ OperationContextImpl txn;
+ Lock::DBWrite x(txn.lockState(), "foo");
+ Lock::DBRead y(&lockState, "admin");
{ Lock::TempRelease t; }
}
else if( q == 4 ) {
- Lock::DBRead x("foo2");
- Lock::DBRead y("admin");
+ Lock::DBRead x(&lockState, "foo2");
+ Lock::DBRead y(&lockState, "admin");
{ Lock::TempRelease t; }
}
else if ( q > 4 && q < 8 ) {
static const char * const dbnames[] = {
"bar0", "bar1", "bar2", "bar3", "bar4", "bar5",
"bar6", "bar7", "bar8", "bar9", "bar10" };
- Lock::DBWrite w(dbnames[q]);
+
+ OperationContextImpl txn;
+ Lock::DBWrite w(txn.lockState(), dbnames[q]);
{
Lock::UpgradeGlobalLockToExclusive wToX;
if (wToX.gotUpgrade()) {
@@ -245,21 +255,24 @@ namespace ThreadedTests {
}
}
else {
- Lock::DBWrite w("foo");
+ OperationContextImpl txn;
+ Lock::DBWrite w(txn.lockState(), "foo");
+
{
Lock::TempRelease t;
}
- Lock::DBRead r2("foo");
- Lock::DBRead r3("local");
+
+ Lock::DBRead r2(&lockState, "foo");
+ Lock::DBRead r3(&lockState, "local");
if( sometimes ) {
Lock::TempRelease t;
}
}
}
else {
- Lock::DBRead r("foo");
- Lock::DBRead r2("foo");
- Lock::DBRead r3("local");
+ Lock::DBRead r(&lockState, "foo");
+ Lock::DBRead r2(&lockState, "foo");
+ Lock::DBRead r3(&lockState, "local");
}
}
pm.hit();
diff --git a/src/mongo/dbtests/updatetests.cpp b/src/mongo/dbtests/updatetests.cpp
index 32e20bd9d01..e89997330cf 100644
--- a/src/mongo/dbtests/updatetests.cpp
+++ b/src/mongo/dbtests/updatetests.cpp
@@ -1060,14 +1060,11 @@ namespace UpdateTests {
BSONObj result;
BSONObj expected;
- switch ( i ) {
- default:
- client().update( ns(), Query(), getUpdate(i) );
- result = client().findOne( ns(), Query() );
- expected = fromjson( "{'_id':0,x:[]}" );
- ASSERT_EQUALS( result, expected );
- break;
- }
+
+ client().update( ns(), Query(), getUpdate(i) );
+ result = client().findOne( ns(), Query() );
+ expected = fromjson( "{'_id':0,x:[]}" );
+ ASSERT_EQUALS( result, expected );
}
}
};
@@ -1092,14 +1089,11 @@ namespace UpdateTests {
BSONObj result;
BSONObj expected;
- switch ( i ) {
- default:
- client().update( ns(), Query(), getUpdate(i) );
- result = client().findOne( ns(), Query() );
- expected = fromjson( "{'_id':0,x:[]}" );
- ASSERT_EQUALS( result, expected );
- break;
- }
+
+ client().update( ns(), Query(), getUpdate(i) );
+ result = client().findOne( ns(), Query() );
+ expected = fromjson( "{'_id':0,x:[]}" );
+ ASSERT_EQUALS( result, expected );
}
}
};