summaryrefslogtreecommitdiff
path: root/src/mongo
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo')
-rw-r--r--src/mongo/db/commands/geo_near_cmd.cpp2
-rw-r--r--src/mongo/db/commands/index_filter_commands.cpp2
-rw-r--r--src/mongo/db/commands/index_filter_commands_test.cpp86
-rw-r--r--src/mongo/db/commands/mr.cpp4
-rw-r--r--src/mongo/db/commands/plan_cache_commands.cpp3
-rw-r--r--src/mongo/db/commands/plan_cache_commands_test.cpp75
-rw-r--r--src/mongo/db/dbcommands.cpp3
-rw-r--r--src/mongo/db/dbhelpers.cpp2
-rw-r--r--src/mongo/db/exec/sort.cpp2
-rw-r--r--src/mongo/db/ops/parsed_delete.cpp2
-rw-r--r--src/mongo/db/ops/parsed_update.cpp2
-rw-r--r--src/mongo/db/ops/update_driver.cpp3
-rw-r--r--src/mongo/db/pipeline/pipeline_d.cpp4
-rw-r--r--src/mongo/db/query/canonical_query.cpp42
-rw-r--r--src/mongo/db/query/canonical_query.h14
-rw-r--r--src/mongo/db/query/canonical_query_test.cpp4
-rw-r--r--src/mongo/db/query/get_executor.cpp15
-rw-r--r--src/mongo/db/query/get_executor_test.cpp4
-rw-r--r--src/mongo/db/query/plan_cache_test.cpp14
-rw-r--r--src/mongo/db/query/query_planner_test.cpp9
-rw-r--r--src/mongo/db/query/query_planner_test_fixture.cpp7
-rw-r--r--src/mongo/db/query/query_planner_test_fixture.h2
-rw-r--r--src/mongo/dbtests/documentsourcetests.cpp26
-rw-r--r--src/mongo/dbtests/executor_registry.cpp42
-rw-r--r--src/mongo/dbtests/oplogstarttests.cpp40
-rw-r--r--src/mongo/dbtests/plan_ranking.cpp40
-rw-r--r--src/mongo/dbtests/query_multi_plan_runner.cpp32
-rw-r--r--src/mongo/dbtests/query_plan_executor.cpp64
-rw-r--r--src/mongo/dbtests/query_stage_cached_plan.cpp25
-rw-r--r--src/mongo/dbtests/query_stage_delete.cpp25
-rw-r--r--src/mongo/dbtests/query_stage_subplan.cpp31
-rw-r--r--src/mongo/dbtests/query_stage_update.cpp70
-rw-r--r--src/mongo/s/chunk_manager.cpp3
-rw-r--r--src/mongo/s/chunk_manager_targeter_test.cpp3
-rw-r--r--src/mongo/s/shard_key_pattern.cpp3
35 files changed, 344 insertions, 361 deletions
diff --git a/src/mongo/db/commands/geo_near_cmd.cpp b/src/mongo/db/commands/geo_near_cmd.cpp
index 8f03f059d80..eafef874646 100644
--- a/src/mongo/db/commands/geo_near_cmd.cpp
+++ b/src/mongo/db/commands/geo_near_cmd.cpp
@@ -186,7 +186,7 @@ public:
const WhereCallbackReal whereCallback(txn, nss.db());
auto statusWithCQ = CanonicalQuery::canonicalize(
- nss.ns(), rewritten, BSONObj(), projObj, 0, numWanted, BSONObj(), whereCallback);
+ nss, rewritten, BSONObj(), projObj, 0, numWanted, BSONObj(), whereCallback);
if (!statusWithCQ.isOK()) {
errmsg = "Can't parse filter / create query";
return false;
diff --git a/src/mongo/db/commands/index_filter_commands.cpp b/src/mongo/db/commands/index_filter_commands.cpp
index 0b6345ef06a..b4dd3e36d68 100644
--- a/src/mongo/db/commands/index_filter_commands.cpp
+++ b/src/mongo/db/commands/index_filter_commands.cpp
@@ -315,7 +315,7 @@ Status ClearFilters::clear(OperationContext* txn,
// Create canonical query.
auto statusWithCQ = CanonicalQuery::canonicalize(
- ns, entry->query, entry->sort, entry->projection, whereCallback);
+ nss, entry->query, entry->sort, entry->projection, whereCallback);
invariant(statusWithCQ.isOK());
std::unique_ptr<CanonicalQuery> cq = std::move(statusWithCQ.getValue());
diff --git a/src/mongo/db/commands/index_filter_commands_test.cpp b/src/mongo/db/commands/index_filter_commands_test.cpp
index 7da3619d1f7..5a0d7b6ce07 100644
--- a/src/mongo/db/commands/index_filter_commands_test.cpp
+++ b/src/mongo/db/commands/index_filter_commands_test.cpp
@@ -47,7 +47,7 @@ using std::string;
using std::unique_ptr;
using std::vector;
-static const char* ns = "test.t";
+static const NamespaceString nss("test.collection");
/**
* Utility function to get list of index filters from the query settings.
@@ -120,7 +120,7 @@ void addQueryShapeToPlanCache(PlanCache* planCache,
BSONObj projectionObj = fromjson(projectionStr);
// Create canonical query.
- auto statusWithCQ = CanonicalQuery::canonicalize(ns, queryObj, sortObj, projectionObj);
+ auto statusWithCQ = CanonicalQuery::canonicalize(nss, queryObj, sortObj, projectionObj);
ASSERT_OK(statusWithCQ.getStatus());
std::unique_ptr<CanonicalQuery> cq = std::move(statusWithCQ.getValue());
@@ -144,7 +144,7 @@ bool planCacheContains(const PlanCache& planCache,
BSONObj projectionObj = fromjson(projectionStr);
// Create canonical query.
- auto statusWithInputQuery = CanonicalQuery::canonicalize(ns, queryObj, sortObj, projectionObj);
+ auto statusWithInputQuery = CanonicalQuery::canonicalize(nss, queryObj, sortObj, projectionObj);
ASSERT_OK(statusWithInputQuery.getStatus());
unique_ptr<CanonicalQuery> inputQuery = std::move(statusWithInputQuery.getValue());
@@ -160,7 +160,7 @@ bool planCacheContains(const PlanCache& planCache,
// Alternatively, we could add key to PlanCacheEntry but that would be used in one place
// only.
auto statusWithCurrentQuery =
- CanonicalQuery::canonicalize(ns, entry->query, entry->sort, entry->projection);
+ CanonicalQuery::canonicalize(nss, entry->query, entry->sort, entry->projection);
ASSERT_OK(statusWithCurrentQuery.getStatus());
unique_ptr<CanonicalQuery> currentQuery = std::move(statusWithCurrentQuery.getValue());
@@ -193,21 +193,23 @@ TEST(IndexFilterCommandsTest, ClearFiltersInvalidParameter) {
OperationContextNoop txn;
// If present, query has to be an object.
- ASSERT_NOT_OK(ClearFilters::clear(&txn, &empty, &planCache, ns, fromjson("{query: 1234}")));
- // If present, sort must be an object.
ASSERT_NOT_OK(
- ClearFilters::clear(&txn, &empty, &planCache, ns, fromjson("{query: {a: 1}, sort: 1234}")));
+ ClearFilters::clear(&txn, &empty, &planCache, nss.ns(), fromjson("{query: 1234}")));
+ // If present, sort must be an object.
+ ASSERT_NOT_OK(ClearFilters::clear(
+ &txn, &empty, &planCache, nss.ns(), fromjson("{query: {a: 1}, sort: 1234}")));
// If present, projection must be an object.
ASSERT_NOT_OK(ClearFilters::clear(
- &txn, &empty, &planCache, ns, fromjson("{query: {a: 1}, projection: 1234}")));
+ &txn, &empty, &planCache, nss.ns(), fromjson("{query: {a: 1}, projection: 1234}")));
// Query must pass canonicalization.
ASSERT_NOT_OK(ClearFilters::clear(
- &txn, &empty, &planCache, ns, fromjson("{query: {a: {$no_such_op: 1}}}")));
+ &txn, &empty, &planCache, nss.ns(), fromjson("{query: {a: {$no_such_op: 1}}}")));
// Sort present without query is an error.
- ASSERT_NOT_OK(ClearFilters::clear(&txn, &empty, &planCache, ns, fromjson("{sort: {a: 1}}")));
+ ASSERT_NOT_OK(
+ ClearFilters::clear(&txn, &empty, &planCache, nss.ns(), fromjson("{sort: {a: 1}}")));
// Projection present without query is an error.
ASSERT_NOT_OK(ClearFilters::clear(
- &txn, &empty, &planCache, ns, fromjson("{projection: {_id: 0, a: 1}}")));
+ &txn, &empty, &planCache, nss.ns(), fromjson("{projection: {_id: 0, a: 1}}")));
}
TEST(IndexFilterCommandsTest, ClearNonexistentHint) {
@@ -215,15 +217,18 @@ TEST(IndexFilterCommandsTest, ClearNonexistentHint) {
PlanCache planCache;
OperationContextNoop txn;
- ASSERT_OK(SetFilter::set(
- &txn, &querySettings, &planCache, ns, fromjson("{query: {a: 1}, indexes: [{a: 1}]}")));
+ ASSERT_OK(SetFilter::set(&txn,
+ &querySettings,
+ &planCache,
+ nss.ns(),
+ fromjson("{query: {a: 1}, indexes: [{a: 1}]}")));
vector<BSONObj> filters = getFilters(querySettings);
ASSERT_EQUALS(filters.size(), 1U);
// Clear nonexistent hint.
// Command should succeed and cache should remain unchanged.
- ASSERT_OK(
- ClearFilters::clear(&txn, &querySettings, &planCache, ns, fromjson("{query: {b: 1}}")));
+ ASSERT_OK(ClearFilters::clear(
+ &txn, &querySettings, &planCache, nss.ns(), fromjson("{query: {b: 1}}")));
filters = getFilters(querySettings);
ASSERT_EQUALS(filters.size(), 1U);
}
@@ -237,46 +242,47 @@ TEST(IndexFilterCommandsTest, SetFilterInvalidParameter) {
PlanCache planCache;
OperationContextNoop txn;
- ASSERT_NOT_OK(SetFilter::set(&txn, &empty, &planCache, ns, fromjson("{}")));
+ ASSERT_NOT_OK(SetFilter::set(&txn, &empty, &planCache, nss.ns(), fromjson("{}")));
// Missing required query field.
- ASSERT_NOT_OK(SetFilter::set(&txn, &empty, &planCache, ns, fromjson("{indexes: [{a: 1}]}")));
+ ASSERT_NOT_OK(
+ SetFilter::set(&txn, &empty, &planCache, nss.ns(), fromjson("{indexes: [{a: 1}]}")));
// Missing required indexes field.
- ASSERT_NOT_OK(SetFilter::set(&txn, &empty, &planCache, ns, fromjson("{query: {a: 1}}")));
+ ASSERT_NOT_OK(SetFilter::set(&txn, &empty, &planCache, nss.ns(), fromjson("{query: {a: 1}}")));
// Query has to be an object.
ASSERT_NOT_OK(SetFilter::set(
- &txn, &empty, &planCache, ns, fromjson("{query: 1234, indexes: [{a: 1}, {b: 1}]}")));
+ &txn, &empty, &planCache, nss.ns(), fromjson("{query: 1234, indexes: [{a: 1}, {b: 1}]}")));
// Indexes field has to be an array.
- ASSERT_NOT_OK(
- SetFilter::set(&txn, &empty, &planCache, ns, fromjson("{query: {a: 1}, indexes: 1234}")));
+ ASSERT_NOT_OK(SetFilter::set(
+ &txn, &empty, &planCache, nss.ns(), fromjson("{query: {a: 1}, indexes: 1234}")));
// Array indexes field cannot empty.
- ASSERT_NOT_OK(
- SetFilter::set(&txn, &empty, &planCache, ns, fromjson("{query: {a: 1}, indexes: []}")));
+ ASSERT_NOT_OK(SetFilter::set(
+ &txn, &empty, &planCache, nss.ns(), fromjson("{query: {a: 1}, indexes: []}")));
// Elements in indexes have to be objects.
ASSERT_NOT_OK(SetFilter::set(
- &txn, &empty, &planCache, ns, fromjson("{query: {a: 1}, indexes: [{a: 1}, 99]}")));
+ &txn, &empty, &planCache, nss.ns(), fromjson("{query: {a: 1}, indexes: [{a: 1}, 99]}")));
// Objects in indexes cannot be empty.
ASSERT_NOT_OK(SetFilter::set(
- &txn, &empty, &planCache, ns, fromjson("{query: {a: 1}, indexes: [{a: 1}, {}]}")));
+ &txn, &empty, &planCache, nss.ns(), fromjson("{query: {a: 1}, indexes: [{a: 1}, {}]}")));
// If present, sort must be an object.
ASSERT_NOT_OK(
SetFilter::set(&txn,
&empty,
&planCache,
- ns,
+ nss.ns(),
fromjson("{query: {a: 1}, sort: 1234, indexes: [{a: 1}, {b: 1}]}")));
// If present, projection must be an object.
ASSERT_NOT_OK(
SetFilter::set(&txn,
&empty,
&planCache,
- ns,
+ nss.ns(),
fromjson("{query: {a: 1}, projection: 1234, indexes: [{a: 1}, {b: 1}]}")));
// Query must pass canonicalization.
ASSERT_NOT_OK(
SetFilter::set(&txn,
&empty,
&planCache,
- ns,
+ nss.ns(),
fromjson("{query: {a: {$no_such_op: 1}}, indexes: [{a: 1}, {b: 1}]}")));
}
@@ -292,7 +298,7 @@ TEST(IndexFilterCommandsTest, SetAndClearFilters) {
ASSERT_OK(SetFilter::set(&txn,
&querySettings,
&planCache,
- ns,
+ nss.ns(),
fromjson(
"{query: {a: 1, b: 1}, sort: {a: -1}, projection: {_id: 0, a: 1}, "
"indexes: [{a: 1}]}")));
@@ -312,7 +318,7 @@ TEST(IndexFilterCommandsTest, SetAndClearFilters) {
ASSERT_OK(SetFilter::set(&txn,
&querySettings,
&planCache,
- ns,
+ nss.ns(),
fromjson(
"{query: {b: 2, a: 3}, sort: {a: -1}, projection: {_id: 0, a: 1}, "
"indexes: [{a: 1, b: 1}]}")));
@@ -320,14 +326,20 @@ TEST(IndexFilterCommandsTest, SetAndClearFilters) {
ASSERT_EQUALS(filters.size(), 1U);
// Add hint for different query shape.
- ASSERT_OK(SetFilter::set(
- &txn, &querySettings, &planCache, ns, fromjson("{query: {b: 1}, indexes: [{b: 1}]}")));
+ ASSERT_OK(SetFilter::set(&txn,
+ &querySettings,
+ &planCache,
+ nss.ns(),
+ fromjson("{query: {b: 1}, indexes: [{b: 1}]}")));
filters = getFilters(querySettings);
ASSERT_EQUALS(filters.size(), 2U);
// Add hint for 3rd query shape. This is to prepare for ClearHint tests.
- ASSERT_OK(SetFilter::set(
- &txn, &querySettings, &planCache, ns, fromjson("{query: {a: 1}, indexes: [{a: 1}]}")));
+ ASSERT_OK(SetFilter::set(&txn,
+ &querySettings,
+ &planCache,
+ nss.ns(),
+ fromjson("{query: {a: 1}, indexes: [{a: 1}]}")));
filters = getFilters(querySettings);
ASSERT_EQUALS(filters.size(), 3U);
@@ -336,8 +348,8 @@ TEST(IndexFilterCommandsTest, SetAndClearFilters) {
addQueryShapeToPlanCache(&planCache, "{b: 1}", "{}", "{}");
// Clear single hint.
- ASSERT_OK(
- ClearFilters::clear(&txn, &querySettings, &planCache, ns, fromjson("{query: {a: 1}}")));
+ ASSERT_OK(ClearFilters::clear(
+ &txn, &querySettings, &planCache, nss.ns(), fromjson("{query: {a: 1}}")));
filters = getFilters(querySettings);
ASSERT_EQUALS(filters.size(), 2U);
@@ -346,7 +358,7 @@ TEST(IndexFilterCommandsTest, SetAndClearFilters) {
ASSERT_TRUE(planCacheContains(planCache, "{b: 1}", "{}", "{}"));
// Clear all filters
- ASSERT_OK(ClearFilters::clear(&txn, &querySettings, &planCache, ns, fromjson("{}")));
+ ASSERT_OK(ClearFilters::clear(&txn, &querySettings, &planCache, nss.ns(), fromjson("{}")));
filters = getFilters(querySettings);
ASSERT_TRUE(filters.empty());
diff --git a/src/mongo/db/commands/mr.cpp b/src/mongo/db/commands/mr.cpp
index bfcb529e6d7..46f9af9f6ee 100644
--- a/src/mongo/db/commands/mr.cpp
+++ b/src/mongo/db/commands/mr.cpp
@@ -1006,7 +1006,7 @@ void State::finalReduce(CurOp* op, ProgressMeterHolder& pm) {
const WhereCallbackReal whereCallback(_txn, nss.db());
auto statusWithCQ =
- CanonicalQuery::canonicalize(_config.incLong, BSONObj(), sortKey, BSONObj(), whereCallback);
+ CanonicalQuery::canonicalize(nss, BSONObj(), sortKey, BSONObj(), whereCallback);
verify(statusWithCQ.isOK());
std::unique_ptr<CanonicalQuery> cq = std::move(statusWithCQ.getValue());
@@ -1367,7 +1367,7 @@ public:
const WhereCallbackReal whereCallback(txn, nss.db());
auto statusWithCQ = CanonicalQuery::canonicalize(
- config.ns, config.filter, config.sort, BSONObj(), whereCallback);
+ nss, config.filter, config.sort, BSONObj(), whereCallback);
if (!statusWithCQ.isOK()) {
uasserted(17238, "Can't canonicalize query " + config.filter.toString());
return 0;
diff --git a/src/mongo/db/commands/plan_cache_commands.cpp b/src/mongo/db/commands/plan_cache_commands.cpp
index 2232632c9a5..632c672b509 100644
--- a/src/mongo/db/commands/plan_cache_commands.cpp
+++ b/src/mongo/db/commands/plan_cache_commands.cpp
@@ -209,7 +209,8 @@ StatusWith<unique_ptr<CanonicalQuery>> PlanCacheCommand::canonicalize(OperationC
const NamespaceString nss(ns);
const WhereCallbackReal whereCallback(txn, nss.db());
- auto statusWithCQ = CanonicalQuery::canonicalize(ns, queryObj, sortObj, projObj, whereCallback);
+ auto statusWithCQ =
+ CanonicalQuery::canonicalize(std::move(nss), queryObj, sortObj, projObj, whereCallback);
if (!statusWithCQ.isOK()) {
return statusWithCQ.getStatus();
}
diff --git a/src/mongo/db/commands/plan_cache_commands_test.cpp b/src/mongo/db/commands/plan_cache_commands_test.cpp
index c1216ea197d..7ffe832473b 100644
--- a/src/mongo/db/commands/plan_cache_commands_test.cpp
+++ b/src/mongo/db/commands/plan_cache_commands_test.cpp
@@ -49,7 +49,7 @@ using std::string;
using std::unique_ptr;
using std::vector;
-static const char* ns = "test.t";
+static const NamespaceString nss("test.collection");
/**
* Tests for planCacheListQueryShapes
@@ -125,7 +125,7 @@ TEST(PlanCacheCommandsTest, planCacheListQueryShapesEmpty) {
TEST(PlanCacheCommandsTest, planCacheListQueryShapesOneKey) {
// Create a canonical query
- auto statusWithCQ = CanonicalQuery::canonicalize(ns, fromjson("{a: 1}"));
+ auto statusWithCQ = CanonicalQuery::canonicalize(nss, fromjson("{a: 1}"));
ASSERT_OK(statusWithCQ.getStatus());
unique_ptr<CanonicalQuery> cq = std::move(statusWithCQ.getValue());
@@ -150,7 +150,7 @@ TEST(PlanCacheCommandsTest, planCacheListQueryShapesOneKey) {
TEST(PlanCacheCommandsTest, planCacheClearAllShapes) {
// Create a canonical query
- auto statusWithCQ = CanonicalQuery::canonicalize(ns, fromjson("{a: 1}"));
+ auto statusWithCQ = CanonicalQuery::canonicalize(nss, fromjson("{a: 1}"));
ASSERT_OK(statusWithCQ.getStatus());
unique_ptr<CanonicalQuery> cq = std::move(statusWithCQ.getValue());
@@ -166,7 +166,7 @@ TEST(PlanCacheCommandsTest, planCacheClearAllShapes) {
ASSERT_EQUALS(getShapes(planCache).size(), 1U);
// Clear cache and confirm number of keys afterwards.
- ASSERT_OK(PlanCacheClear::clear(&txn, &planCache, ns, BSONObj()));
+ ASSERT_OK(PlanCacheClear::clear(&txn, &planCache, nss.ns(), BSONObj()));
ASSERT_EQUALS(getShapes(planCache).size(), 0U);
}
@@ -181,52 +181,55 @@ TEST(PlanCacheCommandsTest, Canonicalize) {
OperationContextNoop txn;
// Missing query field
- ASSERT_NOT_OK(PlanCacheCommand::canonicalize(&txn, ns, fromjson("{}")).getStatus());
+ ASSERT_NOT_OK(PlanCacheCommand::canonicalize(&txn, nss.ns(), fromjson("{}")).getStatus());
// Query needs to be an object
- ASSERT_NOT_OK(PlanCacheCommand::canonicalize(&txn, ns, fromjson("{query: 1}")).getStatus());
- // Sort needs to be an object
ASSERT_NOT_OK(
- PlanCacheCommand::canonicalize(&txn, ns, fromjson("{query: {}, sort: 1}")).getStatus());
- // Bad query (invalid sort order)
- ASSERT_NOT_OK(PlanCacheCommand::canonicalize(&txn, ns, fromjson("{query: {}, sort: {a: 0}}"))
+ PlanCacheCommand::canonicalize(&txn, nss.ns(), fromjson("{query: 1}")).getStatus());
+ // Sort needs to be an object
+ ASSERT_NOT_OK(PlanCacheCommand::canonicalize(&txn, nss.ns(), fromjson("{query: {}, sort: 1}"))
.getStatus());
+ // Bad query (invalid sort order)
+ ASSERT_NOT_OK(PlanCacheCommand::canonicalize(
+ &txn, nss.ns(), fromjson("{query: {}, sort: {a: 0}}")).getStatus());
// Valid parameters
- auto statusWithCQ = PlanCacheCommand::canonicalize(&txn, ns, fromjson("{query: {a: 1, b: 1}}"));
+ auto statusWithCQ =
+ PlanCacheCommand::canonicalize(&txn, nss.ns(), fromjson("{query: {a: 1, b: 1}}"));
ASSERT_OK(statusWithCQ.getStatus());
unique_ptr<CanonicalQuery> query = std::move(statusWithCQ.getValue());
// Equivalent query should generate same key.
- statusWithCQ = PlanCacheCommand::canonicalize(&txn, ns, fromjson("{query: {b: 1, a: 1}}"));
+ statusWithCQ =
+ PlanCacheCommand::canonicalize(&txn, nss.ns(), fromjson("{query: {b: 1, a: 1}}"));
ASSERT_OK(statusWithCQ.getStatus());
unique_ptr<CanonicalQuery> equivQuery = std::move(statusWithCQ.getValue());
ASSERT_EQUALS(planCache.computeKey(*query), planCache.computeKey(*equivQuery));
// Sort query should generate different key from unsorted query.
statusWithCQ = PlanCacheCommand::canonicalize(
- &txn, ns, fromjson("{query: {a: 1, b: 1}, sort: {a: 1, b: 1}}"));
+ &txn, nss.ns(), fromjson("{query: {a: 1, b: 1}, sort: {a: 1, b: 1}}"));
ASSERT_OK(statusWithCQ.getStatus());
unique_ptr<CanonicalQuery> sortQuery1 = std::move(statusWithCQ.getValue());
ASSERT_NOT_EQUALS(planCache.computeKey(*query), planCache.computeKey(*sortQuery1));
// Confirm sort arguments are properly delimited (SERVER-17158)
- statusWithCQ =
- PlanCacheCommand::canonicalize(&txn, ns, fromjson("{query: {a: 1, b: 1}, sort: {aab: 1}}"));
+ statusWithCQ = PlanCacheCommand::canonicalize(
+ &txn, nss.ns(), fromjson("{query: {a: 1, b: 1}, sort: {aab: 1}}"));
ASSERT_OK(statusWithCQ.getStatus());
unique_ptr<CanonicalQuery> sortQuery2 = std::move(statusWithCQ.getValue());
ASSERT_NOT_EQUALS(planCache.computeKey(*sortQuery1), planCache.computeKey(*sortQuery2));
// Changing order and/or value of predicates should not change key
statusWithCQ = PlanCacheCommand::canonicalize(
- &txn, ns, fromjson("{query: {b: 3, a: 3}, sort: {a: 1, b: 1}}"));
+ &txn, nss.ns(), fromjson("{query: {b: 3, a: 3}, sort: {a: 1, b: 1}}"));
ASSERT_OK(statusWithCQ.getStatus());
unique_ptr<CanonicalQuery> sortQuery3 = std::move(statusWithCQ.getValue());
ASSERT_EQUALS(planCache.computeKey(*sortQuery1), planCache.computeKey(*sortQuery3));
// Projected query should generate different key from unprojected query.
statusWithCQ = PlanCacheCommand::canonicalize(
- &txn, ns, fromjson("{query: {a: 1, b: 1}, projection: {_id: 0, a: 1}}"));
+ &txn, nss.ns(), fromjson("{query: {a: 1, b: 1}, projection: {_id: 0, a: 1}}"));
ASSERT_OK(statusWithCQ.getStatus());
unique_ptr<CanonicalQuery> projectionQuery = std::move(statusWithCQ.getValue());
ASSERT_NOT_EQUALS(planCache.computeKey(*query), planCache.computeKey(*projectionQuery));
@@ -241,32 +244,32 @@ TEST(PlanCacheCommandsTest, planCacheClearInvalidParameter) {
OperationContextNoop txn;
// Query field type must be BSON object.
- ASSERT_NOT_OK(PlanCacheClear::clear(&txn, &planCache, ns, fromjson("{query: 12345}")));
+ ASSERT_NOT_OK(PlanCacheClear::clear(&txn, &planCache, nss.ns(), fromjson("{query: 12345}")));
ASSERT_NOT_OK(
- PlanCacheClear::clear(&txn, &planCache, ns, fromjson("{query: /keyisnotregex/}")));
+ PlanCacheClear::clear(&txn, &planCache, nss.ns(), fromjson("{query: /keyisnotregex/}")));
// Query must pass canonicalization.
- ASSERT_NOT_OK(
- PlanCacheClear::clear(&txn, &planCache, ns, fromjson("{query: {a: {$no_such_op: 1}}}")));
+ ASSERT_NOT_OK(PlanCacheClear::clear(
+ &txn, &planCache, nss.ns(), fromjson("{query: {a: {$no_such_op: 1}}}")));
// Sort present without query is an error.
- ASSERT_NOT_OK(PlanCacheClear::clear(&txn, &planCache, ns, fromjson("{sort: {a: 1}}")));
+ ASSERT_NOT_OK(PlanCacheClear::clear(&txn, &planCache, nss.ns(), fromjson("{sort: {a: 1}}")));
// Projection present without query is an error.
- ASSERT_NOT_OK(
- PlanCacheClear::clear(&txn, &planCache, ns, fromjson("{projection: {_id: 0, a: 1}}")));
+ ASSERT_NOT_OK(PlanCacheClear::clear(
+ &txn, &planCache, nss.ns(), fromjson("{projection: {_id: 0, a: 1}}")));
}
TEST(PlanCacheCommandsTest, planCacheClearUnknownKey) {
PlanCache planCache;
OperationContextNoop txn;
- ASSERT_OK(PlanCacheClear::clear(&txn, &planCache, ns, fromjson("{query: {a: 1}}")));
+ ASSERT_OK(PlanCacheClear::clear(&txn, &planCache, nss.ns(), fromjson("{query: {a: 1}}")));
}
TEST(PlanCacheCommandsTest, planCacheClearOneKey) {
// Create 2 canonical queries.
- auto statusWithCQA = CanonicalQuery::canonicalize(ns, fromjson("{a: 1}"));
+ auto statusWithCQA = CanonicalQuery::canonicalize(nss, fromjson("{a: 1}"));
ASSERT_OK(statusWithCQA.getStatus());
unique_ptr<CanonicalQuery> cqA = std::move(statusWithCQA.getValue());
- auto statusWithCQB = CanonicalQuery::canonicalize(ns, fromjson("{b: 1}"));
+ auto statusWithCQB = CanonicalQuery::canonicalize(nss, fromjson("{b: 1}"));
ASSERT_OK(statusWithCQB.getStatus());
unique_ptr<CanonicalQuery> cqB = std::move(statusWithCQB.getValue());
@@ -293,7 +296,8 @@ TEST(PlanCacheCommandsTest, planCacheClearOneKey) {
BSONObjBuilder bob;
OperationContextNoop txn;
- ASSERT_OK(PlanCacheClear::clear(&txn, &planCache, ns, BSON("query" << cqB->getQueryObj())));
+ ASSERT_OK(
+ PlanCacheClear::clear(&txn, &planCache, nss.ns(), BSON("query" << cqB->getQueryObj())));
vector<BSONObj> shapesAfter = getShapes(planCache);
ASSERT_EQUALS(shapesAfter.size(), 1U);
ASSERT_EQUALS(shapesAfter[0], shapeA);
@@ -347,7 +351,7 @@ vector<BSONObj> getPlans(const PlanCache& planCache,
BSONObjBuilder bob;
BSONObj cmdObj = BSON("query" << query << "sort" << sort << "projection" << projection);
- ASSERT_OK(PlanCacheListPlans::list(&txn, planCache, ns, cmdObj, &bob));
+ ASSERT_OK(PlanCacheListPlans::list(&txn, planCache, nss.ns(), cmdObj, &bob));
BSONObj resultObj = bob.obj();
BSONElement plansElt = resultObj.getField("plans");
ASSERT_EQUALS(plansElt.type(), mongo::Array);
@@ -364,12 +368,12 @@ TEST(PlanCacheCommandsTest, planCacheListPlansInvalidParameter) {
OperationContextNoop txn;
// Missing query field is not ok.
- ASSERT_NOT_OK(PlanCacheListPlans::list(&txn, planCache, ns, BSONObj(), &ignored));
+ ASSERT_NOT_OK(PlanCacheListPlans::list(&txn, planCache, nss.ns(), BSONObj(), &ignored));
// Query field type must be BSON object.
ASSERT_NOT_OK(
- PlanCacheListPlans::list(&txn, planCache, ns, fromjson("{query: 12345}"), &ignored));
+ PlanCacheListPlans::list(&txn, planCache, nss.ns(), fromjson("{query: 12345}"), &ignored));
ASSERT_NOT_OK(PlanCacheListPlans::list(
- &txn, planCache, ns, fromjson("{query: /keyisnotregex/}"), &ignored));
+ &txn, planCache, nss.ns(), fromjson("{query: /keyisnotregex/}"), &ignored));
}
TEST(PlanCacheCommandsTest, planCacheListPlansUnknownKey) {
@@ -378,12 +382,13 @@ TEST(PlanCacheCommandsTest, planCacheListPlansUnknownKey) {
OperationContextNoop txn;
BSONObjBuilder ignored;
- ASSERT_OK(PlanCacheListPlans::list(&txn, planCache, ns, fromjson("{query: {a: 1}}"), &ignored));
+ ASSERT_OK(
+ PlanCacheListPlans::list(&txn, planCache, nss.ns(), fromjson("{query: {a: 1}}"), &ignored));
}
TEST(PlanCacheCommandsTest, planCacheListPlansOnlyOneSolutionTrue) {
// Create a canonical query
- auto statusWithCQ = CanonicalQuery::canonicalize(ns, fromjson("{a: 1}"));
+ auto statusWithCQ = CanonicalQuery::canonicalize(nss, fromjson("{a: 1}"));
ASSERT_OK(statusWithCQ.getStatus());
unique_ptr<CanonicalQuery> cq = std::move(statusWithCQ.getValue());
@@ -402,7 +407,7 @@ TEST(PlanCacheCommandsTest, planCacheListPlansOnlyOneSolutionTrue) {
TEST(PlanCacheCommandsTest, planCacheListPlansOnlyOneSolutionFalse) {
// Create a canonical query
- auto statusWithCQ = CanonicalQuery::canonicalize(ns, fromjson("{a: 1}"));
+ auto statusWithCQ = CanonicalQuery::canonicalize(nss, fromjson("{a: 1}"));
ASSERT_OK(statusWithCQ.getStatus());
unique_ptr<CanonicalQuery> cq = std::move(statusWithCQ.getValue());
diff --git a/src/mongo/db/dbcommands.cpp b/src/mongo/db/dbcommands.cpp
index 447bc922943..42f7eb0fb27 100644
--- a/src/mongo/db/dbcommands.cpp
+++ b/src/mongo/db/dbcommands.cpp
@@ -577,7 +577,8 @@ public:
BSONObj sort = BSON("files_id" << 1 << "n" << 1);
MONGO_WRITE_CONFLICT_RETRY_LOOP_BEGIN {
- auto statusWithCQ = CanonicalQuery::canonicalize(ns, query, sort, BSONObj());
+ auto statusWithCQ =
+ CanonicalQuery::canonicalize(NamespaceString(ns), query, sort, BSONObj());
if (!statusWithCQ.isOK()) {
uasserted(17240, "Can't canonicalize query " + query.toString());
return 0;
diff --git a/src/mongo/db/dbhelpers.cpp b/src/mongo/db/dbhelpers.cpp
index d561b18beff..b8e073e9b1d 100644
--- a/src/mongo/db/dbhelpers.cpp
+++ b/src/mongo/db/dbhelpers.cpp
@@ -130,7 +130,7 @@ RecordId Helpers::findOne(OperationContext* txn,
const WhereCallbackReal whereCallback(txn, collection->ns().db());
- auto statusWithCQ = CanonicalQuery::canonicalize(collection->ns().ns(), query, whereCallback);
+ auto statusWithCQ = CanonicalQuery::canonicalize(collection->ns(), query, whereCallback);
massert(17244, "Could not canonicalize " + query.toString(), statusWithCQ.isOK());
unique_ptr<CanonicalQuery> cq = std::move(statusWithCQ.getValue());
diff --git a/src/mongo/db/exec/sort.cpp b/src/mongo/db/exec/sort.cpp
index d7281e1b38e..18bb6b2faa0 100644
--- a/src/mongo/db/exec/sort.cpp
+++ b/src/mongo/db/exec/sort.cpp
@@ -229,7 +229,7 @@ void SortStageKeyGenerator::getBoundsForSort(const BSONObj& queryObj, const BSON
params.indices.push_back(sortOrder);
auto statusWithQueryForSort =
- CanonicalQuery::canonicalize("fake_ns", queryObj, WhereCallbackNoop());
+ CanonicalQuery::canonicalize(NamespaceString("fake.ns"), queryObj, WhereCallbackNoop());
verify(statusWithQueryForSort.isOK());
unique_ptr<CanonicalQuery> queryForSort = std::move(statusWithQueryForSort.getValue());
diff --git a/src/mongo/db/ops/parsed_delete.cpp b/src/mongo/db/ops/parsed_delete.cpp
index ddb24fa2faf..e8fcaac5773 100644
--- a/src/mongo/db/ops/parsed_delete.cpp
+++ b/src/mongo/db/ops/parsed_delete.cpp
@@ -82,7 +82,7 @@ Status ParsedDelete::parseQueryToCQ() {
// The projection needs to be applied after the delete operation, so we specify an empty
// BSONObj as the projection during canonicalization.
const BSONObj emptyObj;
- auto statusWithCQ = CanonicalQuery::canonicalize(_request->getNamespaceString().ns(),
+ auto statusWithCQ = CanonicalQuery::canonicalize(_request->getNamespaceString(),
_request->getQuery(),
_request->getSort(),
emptyObj, // projection
diff --git a/src/mongo/db/ops/parsed_update.cpp b/src/mongo/db/ops/parsed_update.cpp
index 41b010f1d68..2fde7af84c9 100644
--- a/src/mongo/db/ops/parsed_update.cpp
+++ b/src/mongo/db/ops/parsed_update.cpp
@@ -86,7 +86,7 @@ Status ParsedUpdate::parseQueryToCQ() {
// The projection needs to be applied after the update operation, so we specify an empty
// BSONObj as the projection during canonicalization.
const BSONObj emptyObj;
- auto statusWithCQ = CanonicalQuery::canonicalize(_request->getNamespaceString().ns(),
+ auto statusWithCQ = CanonicalQuery::canonicalize(_request->getNamespaceString(),
_request->getQuery(),
_request->getSort(),
emptyObj, // projection
diff --git a/src/mongo/db/ops/update_driver.cpp b/src/mongo/db/ops/update_driver.cpp
index 9045b691e16..5a9dfb210da 100644
--- a/src/mongo/db/ops/update_driver.cpp
+++ b/src/mongo/db/ops/update_driver.cpp
@@ -172,7 +172,8 @@ Status UpdateDriver::populateDocumentWithQueryFields(const BSONObj& query,
// We canonicalize the query to collapse $and/$or, and the first arg (ns) is not needed
// Also, because this is for the upsert case, where we insert a new document if one was
// not found, the $where clause does not make sense, hence empty WhereCallback.
- auto statusWithCQ = CanonicalQuery::canonicalize("", query, WhereCallbackNoop());
+ auto statusWithCQ =
+ CanonicalQuery::canonicalize(NamespaceString(""), query, WhereCallbackNoop());
if (!statusWithCQ.isOK()) {
return statusWithCQ.getStatus();
}
diff --git a/src/mongo/db/pipeline/pipeline_d.cpp b/src/mongo/db/pipeline/pipeline_d.cpp
index 43ba3dcb2dd..7bba04b67ce 100644
--- a/src/mongo/db/pipeline/pipeline_d.cpp
+++ b/src/mongo/db/pipeline/pipeline_d.cpp
@@ -185,7 +185,7 @@ shared_ptr<PlanExecutor> PipelineD::prepareCursorSource(
if (sortStage) {
auto statusWithCQ = CanonicalQuery::canonicalize(
- pExpCtx->ns.ns(), queryObj, sortObj, projectionForQuery, whereCallback);
+ pExpCtx->ns, queryObj, sortObj, projectionForQuery, whereCallback);
if (statusWithCQ.isOK()) {
auto statusWithPlanExecutor = getExecutor(txn,
@@ -210,7 +210,7 @@ shared_ptr<PlanExecutor> PipelineD::prepareCursorSource(
if (!exec.get()) {
const BSONObj noSort;
auto statusWithCQ = CanonicalQuery::canonicalize(
- pExpCtx->ns.ns(), queryObj, noSort, projectionForQuery, whereCallback);
+ pExpCtx->ns, queryObj, noSort, projectionForQuery, whereCallback);
uassertStatusOK(statusWithCQ.getStatus());
exec = uassertStatusOK(getExecutor(txn,
diff --git a/src/mongo/db/query/canonical_query.cpp b/src/mongo/db/query/canonical_query.cpp
index aa5f9762920..b290ae74d24 100644
--- a/src/mongo/db/query/canonical_query.cpp
+++ b/src/mongo/db/query/canonical_query.cpp
@@ -102,21 +102,22 @@ bool matchExpressionLessThan(const MatchExpression* lhs, const MatchExpression*
// static
StatusWith<std::unique_ptr<CanonicalQuery>> CanonicalQuery::canonicalize(
- const std::string& ns,
+ NamespaceString nss,
const BSONObj& query,
const MatchExpressionParser::WhereCallback& whereCallback) {
const BSONObj emptyObj;
- return CanonicalQuery::canonicalize(ns, query, emptyObj, emptyObj, 0, 0, whereCallback);
+ return CanonicalQuery::canonicalize(
+ std::move(nss), query, emptyObj, emptyObj, 0, 0, whereCallback);
}
// static
StatusWith<std::unique_ptr<CanonicalQuery>> CanonicalQuery::canonicalize(
- const std::string& ns,
+ NamespaceString nss,
const BSONObj& query,
bool explain,
const MatchExpressionParser::WhereCallback& whereCallback) {
const BSONObj emptyObj;
- return CanonicalQuery::canonicalize(ns,
+ return CanonicalQuery::canonicalize(std::move(nss),
query,
emptyObj, // sort
emptyObj, // projection
@@ -132,28 +133,29 @@ StatusWith<std::unique_ptr<CanonicalQuery>> CanonicalQuery::canonicalize(
// static
StatusWith<std::unique_ptr<CanonicalQuery>> CanonicalQuery::canonicalize(
- const std::string& ns,
+ NamespaceString nss,
const BSONObj& query,
long long skip,
long long limit,
const MatchExpressionParser::WhereCallback& whereCallback) {
const BSONObj emptyObj;
- return CanonicalQuery::canonicalize(ns, query, emptyObj, emptyObj, skip, limit, whereCallback);
+ return CanonicalQuery::canonicalize(
+ std::move(nss), query, emptyObj, emptyObj, skip, limit, whereCallback);
}
// static
StatusWith<std::unique_ptr<CanonicalQuery>> CanonicalQuery::canonicalize(
- const std::string& ns,
+ NamespaceString nss,
const BSONObj& query,
const BSONObj& sort,
const BSONObj& proj,
const MatchExpressionParser::WhereCallback& whereCallback) {
- return CanonicalQuery::canonicalize(ns, query, sort, proj, 0, 0, whereCallback);
+ return CanonicalQuery::canonicalize(std::move(nss), query, sort, proj, 0, 0, whereCallback);
}
// static
StatusWith<std::unique_ptr<CanonicalQuery>> CanonicalQuery::canonicalize(
- const std::string& ns,
+ NamespaceString nss,
const BSONObj& query,
const BSONObj& sort,
const BSONObj& proj,
@@ -162,12 +164,12 @@ StatusWith<std::unique_ptr<CanonicalQuery>> CanonicalQuery::canonicalize(
const MatchExpressionParser::WhereCallback& whereCallback) {
const BSONObj emptyObj;
return CanonicalQuery::canonicalize(
- ns, query, sort, proj, skip, limit, emptyObj, whereCallback);
+ std::move(nss), query, sort, proj, skip, limit, emptyObj, whereCallback);
}
// static
StatusWith<std::unique_ptr<CanonicalQuery>> CanonicalQuery::canonicalize(
- const std::string& ns,
+ NamespaceString nss,
const BSONObj& query,
const BSONObj& sort,
const BSONObj& proj,
@@ -176,7 +178,7 @@ StatusWith<std::unique_ptr<CanonicalQuery>> CanonicalQuery::canonicalize(
const BSONObj& hint,
const MatchExpressionParser::WhereCallback& whereCallback) {
const BSONObj emptyObj;
- return CanonicalQuery::canonicalize(ns,
+ return CanonicalQuery::canonicalize(std::move(nss),
query,
sort,
proj,
@@ -267,7 +269,7 @@ StatusWith<std::unique_ptr<CanonicalQuery>> CanonicalQuery::canonicalize(
// static
StatusWith<std::unique_ptr<CanonicalQuery>> CanonicalQuery::canonicalize(
- const std::string& ns,
+ NamespaceString nss,
const BSONObj& query,
const BSONObj& sort,
const BSONObj& proj,
@@ -282,18 +284,8 @@ StatusWith<std::unique_ptr<CanonicalQuery>> CanonicalQuery::canonicalize(
// Pass empty sort and projection.
BSONObj emptyObj;
- auto lpqStatus = LiteParsedQuery::makeAsOpQuery(NamespaceString(ns),
- skip,
- limit,
- 0,
- query,
- proj,
- sort,
- hint,
- minObj,
- maxObj,
- snapshot,
- explain);
+ auto lpqStatus = LiteParsedQuery::makeAsOpQuery(
+ std::move(nss), skip, limit, 0, query, proj, sort, hint, minObj, maxObj, snapshot, explain);
if (!lpqStatus.isOK()) {
return lpqStatus.getStatus();
}
diff --git a/src/mongo/db/query/canonical_query.h b/src/mongo/db/query/canonical_query.h
index 34c93db9ab1..52d5a530aed 100644
--- a/src/mongo/db/query/canonical_query.h
+++ b/src/mongo/db/query/canonical_query.h
@@ -82,20 +82,20 @@ public:
MatchExpressionParser::WhereCallback());
static StatusWith<std::unique_ptr<CanonicalQuery>> canonicalize(
- const std::string& ns,
+ NamespaceString nss,
const BSONObj& query,
const MatchExpressionParser::WhereCallback& whereCallback =
MatchExpressionParser::WhereCallback());
static StatusWith<std::unique_ptr<CanonicalQuery>> canonicalize(
- const std::string& ns,
+ NamespaceString nss,
const BSONObj& query,
bool explain,
const MatchExpressionParser::WhereCallback& whereCallback =
MatchExpressionParser::WhereCallback());
static StatusWith<std::unique_ptr<CanonicalQuery>> canonicalize(
- const std::string& ns,
+ NamespaceString nss,
const BSONObj& query,
long long skip,
long long limit,
@@ -103,7 +103,7 @@ public:
MatchExpressionParser::WhereCallback());
static StatusWith<std::unique_ptr<CanonicalQuery>> canonicalize(
- const std::string& ns,
+ NamespaceString nss,
const BSONObj& query,
const BSONObj& sort,
const BSONObj& proj,
@@ -111,7 +111,7 @@ public:
MatchExpressionParser::WhereCallback());
static StatusWith<std::unique_ptr<CanonicalQuery>> canonicalize(
- const std::string& ns,
+ NamespaceString nss,
const BSONObj& query,
const BSONObj& sort,
const BSONObj& proj,
@@ -121,7 +121,7 @@ public:
MatchExpressionParser::WhereCallback());
static StatusWith<std::unique_ptr<CanonicalQuery>> canonicalize(
- const std::string& ns,
+ NamespaceString nss,
const BSONObj& query,
const BSONObj& sort,
const BSONObj& proj,
@@ -132,7 +132,7 @@ public:
MatchExpressionParser::WhereCallback());
static StatusWith<std::unique_ptr<CanonicalQuery>> canonicalize(
- const std::string& ns,
+ NamespaceString nss,
const BSONObj& query,
const BSONObj& sort,
const BSONObj& proj,
diff --git a/src/mongo/db/query/canonical_query_test.cpp b/src/mongo/db/query/canonical_query_test.cpp
index 022210fb8a6..34a4575bde7 100644
--- a/src/mongo/db/query/canonical_query_test.cpp
+++ b/src/mongo/db/query/canonical_query_test.cpp
@@ -460,7 +460,7 @@ TEST(CanonicalQueryTest, SortTreeNumChildrenComparison) {
*/
unique_ptr<CanonicalQuery> canonicalize(const char* queryStr) {
BSONObj queryObj = fromjson(queryStr);
- auto statusWithCQ = CanonicalQuery::canonicalize(nss.ns(), queryObj);
+ auto statusWithCQ = CanonicalQuery::canonicalize(nss, queryObj);
ASSERT_OK(statusWithCQ.getStatus());
return std::move(statusWithCQ.getValue());
}
@@ -471,7 +471,7 @@ std::unique_ptr<CanonicalQuery> canonicalize(const char* queryStr,
BSONObj queryObj = fromjson(queryStr);
BSONObj sortObj = fromjson(sortStr);
BSONObj projObj = fromjson(projStr);
- auto statusWithCQ = CanonicalQuery::canonicalize(nss.ns(), queryObj, sortObj, projObj);
+ auto statusWithCQ = CanonicalQuery::canonicalize(nss, queryObj, sortObj, projObj);
ASSERT_OK(statusWithCQ.getStatus());
return std::move(statusWithCQ.getValue());
}
diff --git a/src/mongo/db/query/get_executor.cpp b/src/mongo/db/query/get_executor.cpp
index ff8128782d9..0bcbda97f37 100644
--- a/src/mongo/db/query/get_executor.cpp
+++ b/src/mongo/db/query/get_executor.cpp
@@ -455,7 +455,7 @@ StatusWith<unique_ptr<PlanExecutor>> getExecutor(OperationContext* txn,
!collection->getIndexCatalog()->findIdIndex(txn)) {
const WhereCallbackReal whereCallback(txn, collection->ns().db());
auto statusWithCQ =
- CanonicalQuery::canonicalize(collection->ns().ns(), unparsedQuery, whereCallback);
+ CanonicalQuery::canonicalize(collection->ns(), unparsedQuery, whereCallback);
if (!statusWithCQ.isOK()) {
return statusWithCQ.getStatus();
}
@@ -952,7 +952,7 @@ StatusWith<unique_ptr<PlanExecutor>> getExecutorGroup(OperationContext* txn,
const WhereCallbackReal whereCallback(txn, nss.db());
auto statusWithCQ =
- CanonicalQuery::canonicalize(request.ns, request.query, request.explain, whereCallback);
+ CanonicalQuery::canonicalize(nss, request.query, request.explain, whereCallback);
if (!statusWithCQ.isOK()) {
return statusWithCQ.getStatus();
}
@@ -1185,7 +1185,7 @@ StatusWith<unique_ptr<PlanExecutor>> getExecutorCount(OperationContext* txn,
// If query or hint is not empty, canonicalize the query before working with collection.
typedef MatchExpressionParser::WhereCallback WhereCallback;
auto statusWithCQ = CanonicalQuery::canonicalize(
- request.getNs().ns(),
+ request.getNs(),
request.getQuery(),
BSONObj(), // sort
BSONObj(), // projection
@@ -1339,8 +1339,7 @@ StatusWith<unique_ptr<PlanExecutor>> getExecutorDistinct(OperationContext* txn,
// If there are no suitable indices for the distinct hack bail out now into regular planning
// with no projection.
if (plannerParams.indices.empty()) {
- auto statusWithCQ =
- CanonicalQuery::canonicalize(collection->ns().ns(), query, whereCallback);
+ auto statusWithCQ = CanonicalQuery::canonicalize(collection->ns(), query, whereCallback);
if (!statusWithCQ.isOK()) {
return statusWithCQ.getStatus();
}
@@ -1360,8 +1359,8 @@ StatusWith<unique_ptr<PlanExecutor>> getExecutorDistinct(OperationContext* txn,
BSONObj projection = getDistinctProjection(field);
// Apply a projection of the key. Empty BSONObj() is for the sort.
- auto statusWithCQ = CanonicalQuery::canonicalize(
- collection->ns().ns(), query, BSONObj(), projection, whereCallback);
+ auto statusWithCQ =
+ CanonicalQuery::canonicalize(collection->ns(), query, BSONObj(), projection, whereCallback);
if (!statusWithCQ.isOK()) {
return statusWithCQ.getStatus();
}
@@ -1448,7 +1447,7 @@ StatusWith<unique_ptr<PlanExecutor>> getExecutorDistinct(OperationContext* txn,
}
// We drop the projection from the 'cq'. Unfortunately this is not trivial.
- statusWithCQ = CanonicalQuery::canonicalize(collection->ns().ns(), query, whereCallback);
+ statusWithCQ = CanonicalQuery::canonicalize(collection->ns(), query, whereCallback);
if (!statusWithCQ.isOK()) {
return statusWithCQ.getStatus();
}
diff --git a/src/mongo/db/query/get_executor_test.cpp b/src/mongo/db/query/get_executor_test.cpp
index 0e8740fa089..5a052c6c301 100644
--- a/src/mongo/db/query/get_executor_test.cpp
+++ b/src/mongo/db/query/get_executor_test.cpp
@@ -43,7 +43,7 @@ namespace {
using std::unique_ptr;
-static const char* ns = "somebogusns";
+static const NamespaceString nss("test.collection");
/**
* Utility functions to create a CanonicalQuery
@@ -54,7 +54,7 @@ unique_ptr<CanonicalQuery> canonicalize(const char* queryStr,
BSONObj queryObj = fromjson(queryStr);
BSONObj sortObj = fromjson(sortStr);
BSONObj projObj = fromjson(projStr);
- auto statusWithCQ = CanonicalQuery::canonicalize(ns, queryObj, sortObj, projObj);
+ auto statusWithCQ = CanonicalQuery::canonicalize(nss, queryObj, sortObj, projObj);
ASSERT_OK(statusWithCQ.getStatus());
return std::move(statusWithCQ.getValue());
}
diff --git a/src/mongo/db/query/plan_cache_test.cpp b/src/mongo/db/query/plan_cache_test.cpp
index 7578893620d..81d7253a8fd 100644
--- a/src/mongo/db/query/plan_cache_test.cpp
+++ b/src/mongo/db/query/plan_cache_test.cpp
@@ -54,13 +54,13 @@ using std::string;
using std::unique_ptr;
using std::vector;
-static const char* ns = "somebogusns";
+static const NamespaceString nss("test.collection");
/**
* Utility functions to create a CanonicalQuery
*/
unique_ptr<CanonicalQuery> canonicalize(const BSONObj& queryObj) {
- auto statusWithCQ = CanonicalQuery::canonicalize(ns, queryObj);
+ auto statusWithCQ = CanonicalQuery::canonicalize(nss, queryObj);
ASSERT_OK(statusWithCQ.getStatus());
return std::move(statusWithCQ.getValue());
}
@@ -76,7 +76,7 @@ unique_ptr<CanonicalQuery> canonicalize(const char* queryStr,
BSONObj queryObj = fromjson(queryStr);
BSONObj sortObj = fromjson(sortStr);
BSONObj projObj = fromjson(projStr);
- auto statusWithCQ = CanonicalQuery::canonicalize(ns, queryObj, sortObj, projObj);
+ auto statusWithCQ = CanonicalQuery::canonicalize(nss, queryObj, sortObj, projObj);
ASSERT_OK(statusWithCQ.getStatus());
return std::move(statusWithCQ.getValue());
}
@@ -95,7 +95,7 @@ unique_ptr<CanonicalQuery> canonicalize(const char* queryStr,
BSONObj hintObj = fromjson(hintStr);
BSONObj minObj = fromjson(minStr);
BSONObj maxObj = fromjson(maxStr);
- auto statusWithCQ = CanonicalQuery::canonicalize(ns,
+ auto statusWithCQ = CanonicalQuery::canonicalize(nss,
queryObj,
sortObj,
projObj,
@@ -127,7 +127,7 @@ unique_ptr<CanonicalQuery> canonicalize(const char* queryStr,
BSONObj minObj = fromjson(minStr);
BSONObj maxObj = fromjson(maxStr);
auto statusWithCQ = CanonicalQuery::canonicalize(
- ns, queryObj, sortObj, projObj, skip, limit, hintObj, minObj, maxObj, snapshot, explain);
+ nss, queryObj, sortObj, projObj, skip, limit, hintObj, minObj, maxObj, snapshot, explain);
ASSERT_OK(statusWithCQ.getStatus());
return std::move(statusWithCQ.getValue());
}
@@ -507,7 +507,7 @@ protected:
solns.clear();
- auto statusWithCQ = CanonicalQuery::canonicalize(ns,
+ auto statusWithCQ = CanonicalQuery::canonicalize(nss,
query,
sort,
proj,
@@ -588,7 +588,7 @@ protected:
const BSONObj& sort,
const BSONObj& proj,
const QuerySolution& soln) const {
- auto statusWithCQ = CanonicalQuery::canonicalize(ns, query, sort, proj);
+ auto statusWithCQ = CanonicalQuery::canonicalize(nss, query, sort, proj);
ASSERT_OK(statusWithCQ.getStatus());
unique_ptr<CanonicalQuery> scopedCq = std::move(statusWithCQ.getValue());
diff --git a/src/mongo/db/query/query_planner_test.cpp b/src/mongo/db/query/query_planner_test.cpp
index 592c1e9acc0..d58f179399f 100644
--- a/src/mongo/db/query/query_planner_test.cpp
+++ b/src/mongo/db/query/query_planner_test.cpp
@@ -3883,7 +3883,8 @@ TEST(BadInputTest, CacheDataFromTaggedTree) {
// No relevant index matching the index tag.
relevantIndices.push_back(IndexEntry(BSON("a" << 1)));
- auto statusWithCQ = CanonicalQuery::canonicalize("ns", BSON("a" << 3));
+ auto statusWithCQ =
+ CanonicalQuery::canonicalize(NamespaceString("test.collection"), BSON("a" << 3));
ASSERT_OK(statusWithCQ.getStatus());
std::unique_ptr<CanonicalQuery> scopedCq = std::move(statusWithCQ.getValue());
scopedCq->root()->setTag(new IndexTag(1));
@@ -3894,7 +3895,9 @@ TEST(BadInputTest, CacheDataFromTaggedTree) {
}
TEST(BadInputTest, TagAccordingToCache) {
- auto statusWithCQ = CanonicalQuery::canonicalize("ns", BSON("a" << 3));
+ const NamespaceString nss("test.collection");
+
+ auto statusWithCQ = CanonicalQuery::canonicalize(nss, BSON("a" << 3));
ASSERT_OK(statusWithCQ.getStatus());
std::unique_ptr<CanonicalQuery> scopedCq = std::move(statusWithCQ.getValue());
@@ -3921,7 +3924,7 @@ TEST(BadInputTest, TagAccordingToCache) {
ASSERT_OK(s);
// Regenerate canonical query in order to clear tags.
- statusWithCQ = CanonicalQuery::canonicalize("ns", BSON("a" << 3));
+ statusWithCQ = CanonicalQuery::canonicalize(nss, BSON("a" << 3));
ASSERT_OK(statusWithCQ.getStatus());
scopedCq = std::move(statusWithCQ.getValue());
diff --git a/src/mongo/db/query/query_planner_test_fixture.cpp b/src/mongo/db/query/query_planner_test_fixture.cpp
index aaedb200d83..9e8446f5fcc 100644
--- a/src/mongo/db/query/query_planner_test_fixture.cpp
+++ b/src/mongo/db/query/query_planner_test_fixture.cpp
@@ -43,7 +43,7 @@ namespace mongo {
using unittest::assertGet;
-const char* QueryPlannerTest::ns = "somebogus.ns";
+const NamespaceString QueryPlannerTest::nss("test.collection");
void QueryPlannerTest::setUp() {
internalQueryPlannerEnableHashIntersection = true;
@@ -165,7 +165,7 @@ void QueryPlannerTest::runQueryFull(const BSONObj& query,
// Clean up any previous state from a call to runQueryFull
solns.clear();
- auto statusWithCQ = CanonicalQuery::canonicalize(ns,
+ auto statusWithCQ = CanonicalQuery::canonicalize(nss,
query,
sort,
proj,
@@ -230,7 +230,7 @@ void QueryPlannerTest::runInvalidQueryFull(const BSONObj& query,
bool snapshot) {
solns.clear();
- auto statusWithCQ = CanonicalQuery::canonicalize(ns,
+ auto statusWithCQ = CanonicalQuery::canonicalize(nss,
query,
sort,
proj,
@@ -250,7 +250,6 @@ void QueryPlannerTest::runInvalidQueryFull(const BSONObj& query,
void QueryPlannerTest::runQueryAsCommand(const BSONObj& cmdObj) {
solns.clear();
- const NamespaceString nss(ns);
invariant(nss.isValid());
const bool isExplain = false;
diff --git a/src/mongo/db/query/query_planner_test_fixture.h b/src/mongo/db/query/query_planner_test_fixture.h
index de229a89e45..2c2ed157c83 100644
--- a/src/mongo/db/query/query_planner_test_fixture.h
+++ b/src/mongo/db/query/query_planner_test_fixture.h
@@ -189,7 +189,7 @@ protected:
// Data members.
//
- static const char* ns;
+ static const NamespaceString nss;
BSONObj queryObj;
std::unique_ptr<CanonicalQuery> cq;
diff --git a/src/mongo/dbtests/documentsourcetests.cpp b/src/mongo/dbtests/documentsourcetests.cpp
index a0b065b8ab1..395ee11eb1e 100644
--- a/src/mongo/dbtests/documentsourcetests.cpp
+++ b/src/mongo/dbtests/documentsourcetests.cpp
@@ -44,7 +44,7 @@ using boost::intrusive_ptr;
using std::unique_ptr;
using std::vector;
-static const char* const ns = "unittests.documentsourcetests";
+static const NamespaceString nss("unittests.documentsourcetests");
static const BSONObj metaTextScore = BSON("$meta"
<< "textScore");
@@ -60,7 +60,7 @@ public:
CollectionBase() : client(&_opCtx) {}
~CollectionBase() {
- client.dropCollection(ns);
+ client.dropCollection(nss.ns());
}
protected:
@@ -74,7 +74,7 @@ using mongo::DocumentSourceCursor;
class Base : public CollectionBase {
public:
- Base() : _ctx(new ExpressionContext(&_opCtx, NamespaceString(ns))) {
+ Base() : _ctx(new ExpressionContext(&_opCtx, nss)) {
_ctx->tempDir = storageGlobalParams.dbpath + "/_tmp";
}
@@ -84,15 +84,15 @@ protected:
_source.reset();
_exec.reset();
- OldClientWriteContext ctx(&_opCtx, ns);
- auto cq = uassertStatusOK(CanonicalQuery::canonicalize(ns, /*query=*/BSONObj()));
+ OldClientWriteContext ctx(&_opCtx, nss.ns());
+ auto cq = uassertStatusOK(CanonicalQuery::canonicalize(nss, /*query=*/BSONObj()));
_exec = uassertStatusOK(
getExecutor(&_opCtx, ctx.getCollection(), std::move(cq), PlanExecutor::YIELD_MANUAL));
_exec->saveState();
_exec->registerExec();
- _source = DocumentSourceCursor::create(ns, _exec, _ctx);
+ _source = DocumentSourceCursor::create(nss.ns(), _exec, _ctx);
}
intrusive_ptr<ExpressionContext> ctx() {
return _ctx;
@@ -126,7 +126,7 @@ public:
class Iterate : public Base {
public:
void run() {
- client.insert(ns, BSON("a" << 1));
+ client.insert(nss.ns(), BSON("a" << 1));
createSource();
// The DocumentSourceCursor doesn't hold a read lock.
ASSERT(!_opCtx.lockState()->isReadLocked());
@@ -160,9 +160,9 @@ public:
class IterateDispose : public Base {
public:
void run() {
- client.insert(ns, BSON("a" << 1));
- client.insert(ns, BSON("a" << 2));
- client.insert(ns, BSON("a" << 3));
+ client.insert(nss.ns(), BSON("a" << 1));
+ client.insert(nss.ns(), BSON("a" << 2));
+ client.insert(nss.ns(), BSON("a" << 3));
createSource();
// The result is as expected.
boost::optional<Document> next = source()->getNext();
@@ -212,9 +212,9 @@ public:
return DocumentSourceLimit::create(ctx(), limit);
}
void run() {
- client.insert(ns, BSON("a" << 1));
- client.insert(ns, BSON("a" << 2));
- client.insert(ns, BSON("a" << 3));
+ client.insert(nss.ns(), BSON("a" << 1));
+ client.insert(nss.ns(), BSON("a" << 2));
+ client.insert(nss.ns(), BSON("a" << 3));
createSource();
// initial limit becomes limit of cursor
diff --git a/src/mongo/dbtests/executor_registry.cpp b/src/mongo/dbtests/executor_registry.cpp
index cfa67a3bf29..b71d11c2d90 100644
--- a/src/mongo/dbtests/executor_registry.cpp
+++ b/src/mongo/dbtests/executor_registry.cpp
@@ -49,19 +49,21 @@ namespace ExecutorRegistry {
using std::unique_ptr;
+static const NamespaceString nss("unittests.ExecutorRegistryDiskLocInvalidation");
+
class ExecutorRegistryBase {
public:
ExecutorRegistryBase() : _client(&_opCtx) {
- _ctx.reset(new OldClientWriteContext(&_opCtx, ns()));
- _client.dropCollection(ns());
+ _ctx.reset(new OldClientWriteContext(&_opCtx, nss.ns()));
+ _client.dropCollection(nss.ns());
for (int i = 0; i < N(); ++i) {
- _client.insert(ns(), BSON("foo" << i));
+ _client.insert(nss.ns(), BSON("foo" << i));
}
}
/**
- * Return a plan executor that is going over the collection in ns().
+ * Return a plan executor that is going over the collection in nss.ns().
*/
PlanExecutor* getCollscan() {
unique_ptr<WorkingSet> ws(new WorkingSet());
@@ -72,7 +74,7 @@ public:
unique_ptr<CollectionScan> scan(new CollectionScan(&_opCtx, params, ws.get(), NULL));
// Create a plan executor to hold it
- auto statusWithCQ = CanonicalQuery::canonicalize(ns(), BSONObj());
+ auto statusWithCQ = CanonicalQuery::canonicalize(nss, BSONObj());
ASSERT_OK(statusWithCQ.getStatus());
std::unique_ptr<CanonicalQuery> cq = std::move(statusWithCQ.getValue());
@@ -81,7 +83,7 @@ public:
std::move(ws),
std::move(scan),
std::move(cq),
- _ctx->db()->getCollection(ns()),
+ _ctx->db()->getCollection(nss.ns()),
PlanExecutor::YIELD_MANUAL);
ASSERT_OK(statusWithPlanExecutor.getStatus());
return statusWithPlanExecutor.getValue().release();
@@ -90,7 +92,7 @@ public:
void registerExecutor(PlanExecutor* exec) {
WriteUnitOfWork wuow(&_opCtx);
_ctx->db()
- ->getOrCreateCollection(&_opCtx, ns())
+ ->getOrCreateCollection(&_opCtx, nss.ns())
->getCursorManager()
->registerExecutor(exec);
wuow.commit();
@@ -99,7 +101,7 @@ public:
void deregisterExecutor(PlanExecutor* exec) {
WriteUnitOfWork wuow(&_opCtx);
_ctx->db()
- ->getOrCreateCollection(&_opCtx, ns())
+ ->getOrCreateCollection(&_opCtx, nss.ns())
->getCursorManager()
->deregisterExecutor(exec);
wuow.commit();
@@ -110,11 +112,7 @@ public:
}
Collection* collection() {
- return _ctx->db()->getCollection(ns());
- }
-
- static const char* ns() {
- return "unittests.ExecutorRegistryDiskLocInvalidation";
+ return _ctx->db()->getCollection(nss.ns());
}
// Order of these is important for initialization
@@ -148,8 +146,8 @@ public:
// stuff going on in the yield.
// Delete some data, namely the next 2 things we'd expect.
- _client.remove(ns(), BSON("foo" << 10));
- _client.remove(ns(), BSON("foo" << 11));
+ _client.remove(nss.ns(), BSON("foo" << 10));
+ _client.remove(nss.ns(), BSON("foo" << 11));
// At this point, we're done yielding. We recover our lock.
@@ -202,7 +200,7 @@ public:
registerExecutor(run.get());
// Drop our collection.
- _client.dropCollection(ns());
+ _client.dropCollection(nss.ns());
// Unregister and restore state.
deregisterExecutor(run.get());
@@ -220,7 +218,7 @@ public:
unique_ptr<PlanExecutor> run(getCollscan());
BSONObj obj;
- ASSERT_OK(dbtests::createIndex(&_opCtx, ns(), BSON("foo" << 1)));
+ ASSERT_OK(dbtests::createIndex(&_opCtx, nss.ns(), BSON("foo" << 1)));
// Read some of it.
for (int i = 0; i < 10; ++i) {
@@ -233,7 +231,7 @@ public:
registerExecutor(run.get());
// Drop all indices.
- _client.dropIndexes(ns());
+ _client.dropIndexes(nss.ns());
// Unregister and restore state.
deregisterExecutor(run.get());
@@ -251,7 +249,7 @@ public:
unique_ptr<PlanExecutor> run(getCollscan());
BSONObj obj;
- ASSERT_OK(dbtests::createIndex(&_opCtx, ns(), BSON("foo" << 1)));
+ ASSERT_OK(dbtests::createIndex(&_opCtx, nss.ns(), BSON("foo" << 1)));
// Read some of it.
for (int i = 0; i < 10; ++i) {
@@ -264,7 +262,7 @@ public:
registerExecutor(run.get());
// Drop a specific index.
- _client.dropIndex(ns(), BSON("foo" << 1));
+ _client.dropIndex(nss.ns(), BSON("foo" << 1));
// Unregister and restore state.
deregisterExecutor(run.get());
@@ -296,7 +294,7 @@ public:
// requires a "global write lock."
_ctx.reset();
_client.dropDatabase("somesillydb");
- _ctx.reset(new OldClientWriteContext(&_opCtx, ns()));
+ _ctx.reset(new OldClientWriteContext(&_opCtx, nss.ns()));
// Unregister and restore state.
deregisterExecutor(run.get());
@@ -312,7 +310,7 @@ public:
// Drop our DB. Once again, must give up the lock.
_ctx.reset();
_client.dropDatabase("unittests");
- _ctx.reset(new OldClientWriteContext(&_opCtx, ns()));
+ _ctx.reset(new OldClientWriteContext(&_opCtx, nss.ns()));
// Unregister and restore state.
deregisterExecutor(run.get());
diff --git a/src/mongo/dbtests/oplogstarttests.cpp b/src/mongo/dbtests/oplogstarttests.cpp
index 2d685959a24..417a0b05c3d 100644
--- a/src/mongo/dbtests/oplogstarttests.cpp
+++ b/src/mongo/dbtests/oplogstarttests.cpp
@@ -39,43 +39,35 @@ namespace OplogStartTests {
using std::unique_ptr;
using std::string;
+static const NamespaceString nss("unittests.oplogstarttests");
+
class Base {
public:
Base()
: _txn(),
_scopedXact(&_txn, MODE_X),
_lk(_txn.lockState()),
- _context(&_txn, ns()),
+ _context(&_txn, nss.ns()),
_client(&_txn) {
- Collection* c = _context.db()->getCollection(ns());
+ Collection* c = _context.db()->getCollection(nss.ns());
if (!c) {
WriteUnitOfWork wuow(&_txn);
- c = _context.db()->createCollection(&_txn, ns());
+ c = _context.db()->createCollection(&_txn, nss.ns());
wuow.commit();
}
ASSERT(c->getIndexCatalog()->haveIdIndex(&_txn));
}
~Base() {
- client()->dropCollection(ns());
+ client()->dropCollection(nss.ns());
// The OplogStart stage is not allowed to outlive it's RecoveryUnit.
_stage.reset();
}
protected:
- static const char* ns() {
- return "unittests.oplogstarttests";
- }
- static const char* dbname() {
- return "unittests";
- }
- static const char* collname() {
- return "oplogstarttests";
- }
-
Collection* collection() {
- return _context.db()->getCollection(ns());
+ return _context.db()->getCollection(nss.ns());
}
DBDirectClient* client() {
@@ -83,7 +75,7 @@ protected:
}
void setupFromQuery(const BSONObj& query) {
- auto statusWithCQ = CanonicalQuery::canonicalize(ns(), query);
+ auto statusWithCQ = CanonicalQuery::canonicalize(nss, query);
ASSERT_OK(statusWithCQ.getStatus());
_cq = std::move(statusWithCQ.getValue());
_oplogws.reset(new WorkingSet());
@@ -122,7 +114,7 @@ class OplogStartIsOldest : public Base {
public:
void run() {
for (int i = 0; i < 10; ++i) {
- client()->insert(ns(), BSON("_id" << i << "ts" << i));
+ client()->insert(nss.ns(), BSON("_id" << i << "ts" << i));
}
setupFromQuery(BSON("ts" << BSON("$gte" << 10)));
@@ -146,7 +138,7 @@ class OplogStartIsNewest : public Base {
public:
void run() {
for (int i = 0; i < 10; ++i) {
- client()->insert(ns(), BSON("_id" << i << "ts" << i));
+ client()->insert(nss.ns(), BSON("_id" << i << "ts" << i));
}
setupFromQuery(BSON("ts" << BSON("$gte" << 1)));
@@ -173,7 +165,7 @@ class OplogStartIsNewestExtentHop : public Base {
public:
void run() {
for (int i = 0; i < 10; ++i) {
- client()->insert(ns(), BSON("_id" << i << "ts" << i));
+ client()->insert(nss.ns(), BSON("_id" << i << "ts" << i));
}
setupFromQuery(BSON("ts" << BSON("$gte" << 1)));
@@ -194,10 +186,10 @@ public:
class SizedExtentHopBase : public Base {
public:
SizedExtentHopBase() {
- client()->dropCollection(ns());
+ client()->dropCollection(nss.ns());
}
virtual ~SizedExtentHopBase() {
- client()->dropCollection(ns());
+ client()->dropCollection(nss.ns());
}
void run() {
@@ -227,13 +219,13 @@ protected:
void buildCollection() {
BSONObj info;
// Create a collection with specified extent sizes
- BSONObj command = BSON("create" << collname() << "capped" << true << "$nExtents"
+ BSONObj command = BSON("create" << nss.coll() << "capped" << true << "$nExtents"
<< extentSizes() << "autoIndexId" << false);
- ASSERT(client()->runCommand(dbname(), command, info));
+ ASSERT(client()->runCommand(nss.db().toString(), command, info));
// Populate documents.
for (int i = 0; i < numDocs(); ++i) {
- client()->insert(ns(), BSON("_id" << i << "ts" << i << "payload" << payload8k()));
+ client()->insert(nss.ns(), BSON("_id" << i << "ts" << i << "payload" << payload8k()));
}
}
diff --git a/src/mongo/dbtests/plan_ranking.cpp b/src/mongo/dbtests/plan_ranking.cpp
index ef9e72bfdeb..ee50158167a 100644
--- a/src/mongo/dbtests/plan_ranking.cpp
+++ b/src/mongo/dbtests/plan_ranking.cpp
@@ -63,7 +63,7 @@ namespace PlanRankingTests {
using std::unique_ptr;
using std::vector;
-static const char* ns = "unittests.PlanRankingTests";
+static const NamespaceString nss("unittests.PlanRankingTests");
class PlanRankingTestBase {
public:
@@ -74,8 +74,8 @@ public:
// Run all tests with hash-based intersection enabled.
internalQueryPlannerEnableHashIntersection = true;
- OldClientWriteContext ctx(&_txn, ns);
- _client.dropCollection(ns);
+ OldClientWriteContext ctx(&_txn, nss.ns());
+ _client.dropCollection(nss.ns());
}
virtual ~PlanRankingTestBase() {
@@ -85,12 +85,12 @@ public:
}
void insert(const BSONObj& obj) {
- OldClientWriteContext ctx(&_txn, ns);
- _client.insert(ns, obj);
+ OldClientWriteContext ctx(&_txn, nss.ns());
+ _client.insert(nss.ns(), obj);
}
void addIndex(const BSONObj& obj) {
- ASSERT_OK(dbtests::createIndex(&_txn, ns, obj));
+ ASSERT_OK(dbtests::createIndex(&_txn, nss.ns(), obj));
}
/**
@@ -100,7 +100,7 @@ public:
* Does NOT take ownership of 'cq'. Caller DOES NOT own the returned QuerySolution*.
*/
QuerySolution* pickBestPlan(CanonicalQuery* cq) {
- AutoGetCollectionForRead ctx(&_txn, ns);
+ AutoGetCollectionForRead ctx(&_txn, nss.ns());
Collection* collection = ctx.getCollection();
QueryPlannerParams plannerParams;
@@ -189,7 +189,7 @@ public:
// Run the query {a:4, b:1}.
{
- auto statusWithCQ = CanonicalQuery::canonicalize(ns, BSON("a" << 100 << "b" << 1));
+ auto statusWithCQ = CanonicalQuery::canonicalize(nss, BSON("a" << 100 << "b" << 1));
verify(statusWithCQ.isOK());
cq = std::move(statusWithCQ.getValue());
ASSERT(cq.get());
@@ -206,7 +206,7 @@ public:
// And run the same query again.
{
- auto statusWithCQ = CanonicalQuery::canonicalize(ns, BSON("a" << 100 << "b" << 1));
+ auto statusWithCQ = CanonicalQuery::canonicalize(nss, BSON("a" << 100 << "b" << 1));
verify(statusWithCQ.isOK());
cq = std::move(statusWithCQ.getValue());
}
@@ -240,7 +240,7 @@ public:
// Run the query {a:1, b:{$gt:1}.
auto statusWithCQ =
- CanonicalQuery::canonicalize(ns, BSON("a" << 1 << "b" << BSON("$gt" << 1)));
+ CanonicalQuery::canonicalize(nss, BSON("a" << 1 << "b" << BSON("$gt" << 1)));
verify(statusWithCQ.isOK());
unique_ptr<CanonicalQuery> cq = std::move(statusWithCQ.getValue());
ASSERT(NULL != cq.get());
@@ -279,7 +279,7 @@ public:
// Query for a==27 with projection that wants 'a' and 'b'. BSONObj() is for sort.
auto statusWithCQ = CanonicalQuery::canonicalize(
- ns, BSON("a" << 27), BSONObj(), BSON("_id" << 0 << "a" << 1 << "b" << 1));
+ nss, BSON("a" << 27), BSONObj(), BSON("_id" << 0 << "a" << 1 << "b" << 1));
ASSERT_OK(statusWithCQ.getStatus());
unique_ptr<CanonicalQuery> cq = std::move(statusWithCQ.getValue());
ASSERT(NULL != cq.get());
@@ -312,7 +312,7 @@ public:
// There is no data that matches this query but we don't know that until EOF.
BSONObj queryObj = BSON("a" << 1 << "b" << 1 << "c" << 99);
- auto statusWithCQ = CanonicalQuery::canonicalize(ns, queryObj);
+ auto statusWithCQ = CanonicalQuery::canonicalize(nss, queryObj);
ASSERT_OK(statusWithCQ.getStatus());
unique_ptr<CanonicalQuery> cq = std::move(statusWithCQ.getValue());
ASSERT(NULL != cq.get());
@@ -349,7 +349,7 @@ public:
// returning any data.
auto statusWithCQ = CanonicalQuery::canonicalize(
- ns, BSON("a" << 2), BSONObj(), BSON("_id" << 0 << "a" << 1 << "b" << 1));
+ nss, BSON("a" << 2), BSONObj(), BSON("_id" << 0 << "a" << 1 << "b" << 1));
ASSERT_OK(statusWithCQ.getStatus());
unique_ptr<CanonicalQuery> cq = std::move(statusWithCQ.getValue());
ASSERT(NULL != cq.get());
@@ -380,7 +380,7 @@ public:
addIndex(BSON("b" << 1));
// Run the query {a:N+1, b:1}. (No such document.)
- auto statusWithCQ = CanonicalQuery::canonicalize(ns, BSON("a" << N + 1 << "b" << 1));
+ auto statusWithCQ = CanonicalQuery::canonicalize(nss, BSON("a" << N + 1 << "b" << 1));
verify(statusWithCQ.isOK());
unique_ptr<CanonicalQuery> cq = std::move(statusWithCQ.getValue());
ASSERT(NULL != cq.get());
@@ -415,7 +415,7 @@ public:
// Run the query {a:N+1, b:1}. (No such document.)
auto statusWithCQ =
- CanonicalQuery::canonicalize(ns, BSON("a" << BSON("$gte" << N + 1) << "b" << 1));
+ CanonicalQuery::canonicalize(nss, BSON("a" << BSON("$gte" << N + 1) << "b" << 1));
verify(statusWithCQ.isOK());
unique_ptr<CanonicalQuery> cq = std::move(statusWithCQ.getValue());
ASSERT(NULL != cq.get());
@@ -445,7 +445,7 @@ public:
BSONObj queryObj = BSON("_id" << BSON("$gte" << 20 << "$lte" << 200));
BSONObj sortObj = BSON("c" << 1);
BSONObj projObj = BSONObj();
- auto statusWithCQ = CanonicalQuery::canonicalize(ns, queryObj, sortObj, projObj);
+ auto statusWithCQ = CanonicalQuery::canonicalize(nss, queryObj, sortObj, projObj);
ASSERT_OK(statusWithCQ.getStatus());
unique_ptr<CanonicalQuery> cq = std::move(statusWithCQ.getValue());
@@ -472,7 +472,7 @@ public:
}
// Look for A Space Odyssey.
- auto statusWithCQ = CanonicalQuery::canonicalize(ns, BSON("foo" << 2001));
+ auto statusWithCQ = CanonicalQuery::canonicalize(nss, BSON("foo" << 2001));
verify(statusWithCQ.isOK());
unique_ptr<CanonicalQuery> cq = std::move(statusWithCQ.getValue());
ASSERT(NULL != cq.get());
@@ -503,7 +503,7 @@ public:
addIndex(BSON("d" << 1 << "e" << 1));
// Query: find({a: 1}).sort({d: 1})
- auto statusWithCQ = CanonicalQuery::canonicalize(ns,
+ auto statusWithCQ = CanonicalQuery::canonicalize(nss,
BSON("a" << 1),
BSON("d" << 1), // sort
BSONObj()); // projection
@@ -542,7 +542,7 @@ public:
// results. However, an index scan on 'b' will start producing results sooner
// than an index scan on 'a'.
auto statusWithCQ =
- CanonicalQuery::canonicalize(ns, fromjson("{a: 1, b: 1, c: {$gte: 5000}}"));
+ CanonicalQuery::canonicalize(nss, fromjson("{a: 1, b: 1, c: {$gte: 5000}}"));
ASSERT_OK(statusWithCQ.getStatus());
unique_ptr<CanonicalQuery> cq = std::move(statusWithCQ.getValue());
ASSERT(NULL != cq.get());
@@ -573,7 +573,7 @@ public:
addIndex(BSON("a" << 1));
auto statusWithCQ =
- CanonicalQuery::canonicalize(ns, fromjson("{a: 9, b: {$ne: 10}, c: 9}"));
+ CanonicalQuery::canonicalize(nss, fromjson("{a: 9, b: {$ne: 10}, c: 9}"));
ASSERT_OK(statusWithCQ.getStatus());
unique_ptr<CanonicalQuery> cq = std::move(statusWithCQ.getValue());
ASSERT(NULL != cq.get());
diff --git a/src/mongo/dbtests/query_multi_plan_runner.cpp b/src/mongo/dbtests/query_multi_plan_runner.cpp
index 04e889da587..94f61f6c14b 100644
--- a/src/mongo/dbtests/query_multi_plan_runner.cpp
+++ b/src/mongo/dbtests/query_multi_plan_runner.cpp
@@ -61,6 +61,8 @@ using std::unique_ptr;
using std::vector;
using stdx::make_unique;
+static const NamespaceString nss("unittests.QueryStageMultiPlanRunner");
+
/**
* Create query solution.
*/
@@ -75,31 +77,27 @@ QuerySolution* createQuerySolution() {
class MultiPlanRunnerBase {
public:
MultiPlanRunnerBase() : _client(&_txn) {
- OldClientWriteContext ctx(&_txn, ns());
- _client.dropCollection(ns());
+ OldClientWriteContext ctx(&_txn, nss.ns());
+ _client.dropCollection(nss.ns());
}
virtual ~MultiPlanRunnerBase() {
- OldClientWriteContext ctx(&_txn, ns());
- _client.dropCollection(ns());
+ OldClientWriteContext ctx(&_txn, nss.ns());
+ _client.dropCollection(nss.ns());
}
void addIndex(const BSONObj& obj) {
- ASSERT_OK(dbtests::createIndex(&_txn, ns(), obj));
+ ASSERT_OK(dbtests::createIndex(&_txn, nss.ns(), obj));
}
void insert(const BSONObj& obj) {
- OldClientWriteContext ctx(&_txn, ns());
- _client.insert(ns(), obj);
+ OldClientWriteContext ctx(&_txn, nss.ns());
+ _client.insert(nss.ns(), obj);
}
void remove(const BSONObj& obj) {
- OldClientWriteContext ctx(&_txn, ns());
- _client.remove(ns(), obj);
- }
-
- static const char* ns() {
- return "unittests.QueryStageMultiPlanRunner";
+ OldClientWriteContext ctx(&_txn, nss.ns());
+ _client.remove(nss.ns(), obj);
}
protected:
@@ -120,7 +118,7 @@ public:
addIndex(BSON("foo" << 1));
- AutoGetCollectionForRead ctx(&_txn, ns());
+ AutoGetCollectionForRead ctx(&_txn, nss.ns());
const Collection* coll = ctx.getCollection();
// Plan 0: IXScan over foo == 7
@@ -154,7 +152,7 @@ public:
new CollectionScan(&_txn, csparams, sharedWs.get(), filter.get()));
// Hand the plans off to the runner.
- auto statusWithCQ = CanonicalQuery::canonicalize(ns(), BSON("foo" << 7));
+ auto statusWithCQ = CanonicalQuery::canonicalize(nss, BSON("foo" << 7));
verify(statusWithCQ.isOK());
unique_ptr<CanonicalQuery> cq = std::move(statusWithCQ.getValue());
verify(NULL != cq.get());
@@ -204,11 +202,11 @@ public:
addIndex(BSON("a" << 1));
addIndex(BSON("b" << 1));
- AutoGetCollectionForRead ctx(&_txn, ns());
+ AutoGetCollectionForRead ctx(&_txn, nss.ns());
Collection* collection = ctx.getCollection();
// Query for both 'a' and 'b' and sort on 'b'.
- auto statusWithCQ = CanonicalQuery::canonicalize(ns(),
+ auto statusWithCQ = CanonicalQuery::canonicalize(nss,
BSON("a" << 1 << "b" << 1), // query
BSON("b" << 1), // sort
BSONObj()); // proj
diff --git a/src/mongo/dbtests/query_plan_executor.cpp b/src/mongo/dbtests/query_plan_executor.cpp
index e557cf844e7..6ceb45ef81c 100644
--- a/src/mongo/dbtests/query_plan_executor.cpp
+++ b/src/mongo/dbtests/query_plan_executor.cpp
@@ -53,32 +53,34 @@ using std::shared_ptr;
using std::string;
using std::unique_ptr;
+static const NamespaceString nss("unittests.QueryPlanExecutor");
+
class PlanExecutorBase {
public:
PlanExecutorBase() : _client(&_txn) {}
virtual ~PlanExecutorBase() {
- _client.dropCollection(ns());
+ _client.dropCollection(nss.ns());
}
void addIndex(const BSONObj& obj) {
- ASSERT_OK(dbtests::createIndex(&_txn, ns(), obj));
+ ASSERT_OK(dbtests::createIndex(&_txn, nss.ns(), obj));
}
void insert(const BSONObj& obj) {
- _client.insert(ns(), obj);
+ _client.insert(nss.ns(), obj);
}
void remove(const BSONObj& obj) {
- _client.remove(ns(), obj);
+ _client.remove(nss.ns(), obj);
}
void dropCollection() {
- _client.dropCollection(ns());
+ _client.dropCollection(nss.ns());
}
void update(BSONObj& query, BSONObj& updateSpec) {
- _client.update(ns(), query, updateSpec, false, false);
+ _client.update(nss.ns(), query, updateSpec, false, false);
}
/**
@@ -94,8 +96,8 @@ public:
csparams.direction = CollectionScanParams::FORWARD;
unique_ptr<WorkingSet> ws(new WorkingSet());
- // Canonicalize the query
- auto statusWithCQ = CanonicalQuery::canonicalize(ns(), filterObj);
+ // Canonicalize the query.
+ auto statusWithCQ = CanonicalQuery::canonicalize(nss, filterObj);
verify(statusWithCQ.isOK());
unique_ptr<CanonicalQuery> cq = std::move(statusWithCQ.getValue());
verify(NULL != cq.get());
@@ -133,13 +135,13 @@ public:
ixparams.bounds.endKeyInclusive = true;
ixparams.direction = 1;
- const Collection* coll = db->getCollection(ns());
+ const Collection* coll = db->getCollection(nss.ns());
unique_ptr<WorkingSet> ws(new WorkingSet());
IndexScan* ix = new IndexScan(&_txn, ixparams, ws.get(), NULL);
unique_ptr<PlanStage> root(new FetchStage(&_txn, ws.get(), ix, NULL, coll));
- auto statusWithCQ = CanonicalQuery::canonicalize(ns(), BSONObj());
+ auto statusWithCQ = CanonicalQuery::canonicalize(nss, BSONObj());
verify(statusWithCQ.isOK());
unique_ptr<CanonicalQuery> cq = std::move(statusWithCQ.getValue());
verify(NULL != cq.get());
@@ -151,12 +153,8 @@ public:
return statusWithPlanExecutor.getValue().release();
}
- static const char* ns() {
- return "unittests.QueryPlanExecutor";
- }
-
size_t numCursors() {
- AutoGetCollectionForRead ctx(&_txn, ns());
+ AutoGetCollectionForRead ctx(&_txn, nss.ns());
Collection* collection = ctx.getCollection();
if (!collection)
return 0;
@@ -165,18 +163,18 @@ public:
void registerExec(PlanExecutor* exec) {
// TODO: This is not correct (create collection under S-lock)
- AutoGetCollectionForRead ctx(&_txn, ns());
+ AutoGetCollectionForRead ctx(&_txn, nss.ns());
WriteUnitOfWork wunit(&_txn);
- Collection* collection = ctx.getDb()->getOrCreateCollection(&_txn, ns());
+ Collection* collection = ctx.getDb()->getOrCreateCollection(&_txn, nss.ns());
collection->getCursorManager()->registerExecutor(exec);
wunit.commit();
}
void deregisterExec(PlanExecutor* exec) {
// TODO: This is not correct (create collection under S-lock)
- AutoGetCollectionForRead ctx(&_txn, ns());
+ AutoGetCollectionForRead ctx(&_txn, nss.ns());
WriteUnitOfWork wunit(&_txn);
- Collection* collection = ctx.getDb()->getOrCreateCollection(&_txn, ns());
+ Collection* collection = ctx.getDb()->getOrCreateCollection(&_txn, nss.ns());
collection->getCursorManager()->deregisterExecutor(exec);
wunit.commit();
}
@@ -186,7 +184,7 @@ protected:
private:
IndexDescriptor* getIndex(Database* db, const BSONObj& obj) {
- Collection* collection = db->getCollection(ns());
+ Collection* collection = db->getCollection(nss.ns());
return collection->getIndexCatalog()->findIndexByKeyPattern(&_txn, obj);
}
@@ -200,7 +198,7 @@ private:
class DropCollScan : public PlanExecutorBase {
public:
void run() {
- OldClientWriteContext ctx(&_txn, ns());
+ OldClientWriteContext ctx(&_txn, nss.ns());
insert(BSON("_id" << 1));
insert(BSON("_id" << 2));
@@ -229,7 +227,7 @@ public:
class DropIndexScan : public PlanExecutorBase {
public:
void run() {
- OldClientWriteContext ctx(&_txn, ns());
+ OldClientWriteContext ctx(&_txn, nss.ns());
insert(BSON("_id" << 1 << "a" << 6));
insert(BSON("_id" << 2 << "a" << 7));
insert(BSON("_id" << 3 << "a" << 8));
@@ -258,7 +256,7 @@ public:
class DropIndexScanAgg : public PlanExecutorBase {
public:
void run() {
- OldClientWriteContext ctx(&_txn, ns());
+ OldClientWriteContext ctx(&_txn, nss.ns());
insert(BSON("_id" << 1 << "a" << 6));
insert(BSON("_id" << 2 << "a" << 7));
@@ -271,7 +269,7 @@ public:
// Create the aggregation pipeline.
boost::intrusive_ptr<ExpressionContext> expCtx =
- new ExpressionContext(&_txn, NamespaceString(ns()));
+ new ExpressionContext(&_txn, NamespaceString(nss.ns()));
string errmsg;
BSONObj inputBson = fromjson("{$match: {a: {$gte: 7, $lte: 10}}}");
@@ -352,7 +350,7 @@ protected:
class SnapshotControl : public SnapshotBase {
public:
void run() {
- OldClientWriteContext ctx(&_txn, ns());
+ OldClientWriteContext ctx(&_txn, nss.ns());
setupCollection();
BSONObj filterObj = fromjson("{a: {$gte: 2}}");
@@ -379,7 +377,7 @@ public:
class SnapshotTest : public SnapshotBase {
public:
void run() {
- OldClientWriteContext ctx(&_txn, ns());
+ OldClientWriteContext ctx(&_txn, nss.ns());
setupCollection();
BSONObj indexSpec = BSON("_id" << 1);
addIndex(indexSpec);
@@ -410,7 +408,7 @@ using mongo::ClientCursor;
class Invalidate : public PlanExecutorBase {
public:
void run() {
- OldClientWriteContext ctx(&_txn, ns());
+ OldClientWriteContext ctx(&_txn, nss.ns());
insert(BSON("a" << 1 << "b" << 1));
BSONObj filterObj = fromjson("{_id: {$gt: 0}, b: {$gt: 0}}");
@@ -419,7 +417,7 @@ public:
PlanExecutor* exec = makeCollScanExec(coll, filterObj);
// Make a client cursor from the runner.
- new ClientCursor(coll->getCursorManager(), exec, ns(), false, 0, BSONObj());
+ new ClientCursor(coll->getCursorManager(), exec, nss.ns(), false, 0, BSONObj());
// There should be one cursor before invalidation,
// and zero cursors after invalidation.
@@ -436,7 +434,7 @@ public:
class InvalidatePinned : public PlanExecutorBase {
public:
void run() {
- OldClientWriteContext ctx(&_txn, ns());
+ OldClientWriteContext ctx(&_txn, nss.ns());
insert(BSON("a" << 1 << "b" << 1));
Collection* collection = ctx.getCollection();
@@ -446,7 +444,7 @@ public:
// Make a client cursor from the runner.
ClientCursor* cc =
- new ClientCursor(collection->getCursorManager(), exec, ns(), false, 0, BSONObj());
+ new ClientCursor(collection->getCursorManager(), exec, nss.ns(), false, 0, BSONObj());
ClientCursorPin ccPin(collection->getCursorManager(), cc->cursorid());
// If the cursor is pinned, it sticks around,
@@ -478,19 +476,19 @@ class Timeout : public PlanExecutorBase {
public:
void run() {
{
- OldClientWriteContext ctx(&_txn, ns());
+ OldClientWriteContext ctx(&_txn, nss.ns());
insert(BSON("a" << 1 << "b" << 1));
}
{
- AutoGetCollectionForRead ctx(&_txn, ns());
+ AutoGetCollectionForRead ctx(&_txn, nss.ns());
Collection* collection = ctx.getCollection();
BSONObj filterObj = fromjson("{_id: {$gt: 0}, b: {$gt: 0}}");
PlanExecutor* exec = makeCollScanExec(collection, filterObj);
// Make a client cursor from the runner.
- new ClientCursor(collection->getCursorManager(), exec, ns(), false, 0, BSONObj());
+ new ClientCursor(collection->getCursorManager(), exec, nss.ns(), false, 0, BSONObj());
}
// There should be one cursor before timeout,
diff --git a/src/mongo/dbtests/query_stage_cached_plan.cpp b/src/mongo/dbtests/query_stage_cached_plan.cpp
index a0b7fd14b4a..9191ea5cc21 100644
--- a/src/mongo/dbtests/query_stage_cached_plan.cpp
+++ b/src/mongo/dbtests/query_stage_cached_plan.cpp
@@ -47,6 +47,8 @@
namespace QueryStageCachedPlan {
+static const NamespaceString nss("unittests.QueryStageCachedPlan");
+
class QueryStageCachedPlanBase {
public:
QueryStageCachedPlanBase() {
@@ -57,7 +59,7 @@ public:
addIndex(BSON("a" << 1));
addIndex(BSON("b" << 1));
- OldClientWriteContext ctx(&_txn, ns());
+ OldClientWriteContext ctx(&_txn, nss.ns());
Collection* collection = ctx.getCollection();
ASSERT(collection);
@@ -68,20 +70,19 @@ public:
}
void addIndex(const BSONObj& obj) {
- ASSERT_OK(dbtests::createIndex(&_txn, ns(), obj));
+ ASSERT_OK(dbtests::createIndex(&_txn, nss.ns(), obj));
}
void dropCollection() {
- const NamespaceString nsString(ns());
ScopedTransaction transaction(&_txn, MODE_X);
- Lock::DBLock dbLock(_txn.lockState(), nsString.db(), MODE_X);
- Database* database = dbHolder().get(&_txn, nsString.db());
+ Lock::DBLock dbLock(_txn.lockState(), nss.db(), MODE_X);
+ Database* database = dbHolder().get(&_txn, nss.db());
if (!database) {
return;
}
WriteUnitOfWork wuow(&_txn);
- database->dropCollection(&_txn, ns());
+ database->dropCollection(&_txn, nss.ns());
wuow.commit();
}
@@ -95,10 +96,6 @@ public:
wuow.commit();
}
- static const char* ns() {
- return "unittests.QueryStageCachedPlan";
- }
-
protected:
OperationContextImpl _txn;
WorkingSet _ws;
@@ -111,12 +108,12 @@ protected:
class QueryStageCachedPlanFailure : public QueryStageCachedPlanBase {
public:
void run() {
- AutoGetCollectionForRead ctx(&_txn, ns());
+ AutoGetCollectionForRead ctx(&_txn, nss.ns());
Collection* collection = ctx.getCollection();
ASSERT(collection);
// Query can be answered by either index on "a" or index on "b".
- auto statusWithCQ = CanonicalQuery::canonicalize(ns(), fromjson("{a: {$gte: 8}, b: 1}"));
+ auto statusWithCQ = CanonicalQuery::canonicalize(nss, fromjson("{a: {$gte: 8}, b: 1}"));
ASSERT_OK(statusWithCQ.getStatus());
const std::unique_ptr<CanonicalQuery> cq = std::move(statusWithCQ.getValue());
@@ -175,12 +172,12 @@ public:
class QueryStageCachedPlanHitMaxWorks : public QueryStageCachedPlanBase {
public:
void run() {
- AutoGetCollectionForRead ctx(&_txn, ns());
+ AutoGetCollectionForRead ctx(&_txn, nss.ns());
Collection* collection = ctx.getCollection();
ASSERT(collection);
// Query can be answered by either index on "a" or index on "b".
- auto statusWithCQ = CanonicalQuery::canonicalize(ns(), fromjson("{a: {$gte: 8}, b: 1}"));
+ auto statusWithCQ = CanonicalQuery::canonicalize(nss, fromjson("{a: {$gte: 8}, b: 1}"));
ASSERT_OK(statusWithCQ.getStatus());
const std::unique_ptr<CanonicalQuery> cq = std::move(statusWithCQ.getValue());
diff --git a/src/mongo/dbtests/query_stage_delete.cpp b/src/mongo/dbtests/query_stage_delete.cpp
index 5aeea451a22..32e6092131d 100644
--- a/src/mongo/dbtests/query_stage_delete.cpp
+++ b/src/mongo/dbtests/query_stage_delete.cpp
@@ -49,6 +49,8 @@ namespace QueryStageDelete {
using std::unique_ptr;
using std::vector;
+static const NamespaceString nss("unittests.QueryStageDelete");
+
//
// Stage-specific tests.
//
@@ -56,23 +58,23 @@ using std::vector;
class QueryStageDeleteBase {
public:
QueryStageDeleteBase() : _client(&_txn) {
- OldClientWriteContext ctx(&_txn, ns());
+ OldClientWriteContext ctx(&_txn, nss.ns());
for (size_t i = 0; i < numObj(); ++i) {
BSONObjBuilder bob;
bob.append("_id", static_cast<long long int>(i));
bob.append("foo", static_cast<long long int>(i));
- _client.insert(ns(), bob.obj());
+ _client.insert(nss.ns(), bob.obj());
}
}
virtual ~QueryStageDeleteBase() {
- OldClientWriteContext ctx(&_txn, ns());
- _client.dropCollection(ns());
+ OldClientWriteContext ctx(&_txn, nss.ns());
+ _client.dropCollection(nss.ns());
}
void remove(const BSONObj& obj) {
- _client.remove(ns(), obj);
+ _client.remove(nss.ns(), obj);
}
void getLocs(Collection* collection,
@@ -98,7 +100,7 @@ public:
}
unique_ptr<CanonicalQuery> canonicalize(const BSONObj& query) {
- auto statusWithCQ = CanonicalQuery::canonicalize(ns(), query);
+ auto statusWithCQ = CanonicalQuery::canonicalize(nss, query);
ASSERT_OK(statusWithCQ.getStatus());
return std::move(statusWithCQ.getValue());
}
@@ -107,10 +109,6 @@ public:
return 50;
}
- static const char* ns() {
- return "unittests.QueryStageDelete";
- }
-
protected:
OperationContextImpl _txn;
@@ -126,7 +124,7 @@ private:
class QueryStageDeleteInvalidateUpcomingObject : public QueryStageDeleteBase {
public:
void run() {
- OldClientWriteContext ctx(&_txn, ns());
+ OldClientWriteContext ctx(&_txn, nss.ns());
Collection* coll = ctx.getCollection();
@@ -189,9 +187,8 @@ class QueryStageDeleteReturnOldDoc : public QueryStageDeleteBase {
public:
void run() {
// Various variables we'll need.
- OldClientWriteContext ctx(&_txn, ns());
+ OldClientWriteContext ctx(&_txn, nss.ns());
Collection* coll = ctx.getCollection();
- const NamespaceString nss(ns());
const int targetDocIndex = 0;
const BSONObj query = BSON("foo" << BSON("$gte" << targetDocIndex));
const unique_ptr<WorkingSet> ws(stdx::make_unique<WorkingSet>());
@@ -257,7 +254,7 @@ class QueryStageDeleteSkipOwnedObjects : public QueryStageDeleteBase {
public:
void run() {
// Various variables we'll need.
- OldClientWriteContext ctx(&_txn, ns());
+ OldClientWriteContext ctx(&_txn, nss.ns());
Collection* coll = ctx.getCollection();
const BSONObj query = BSONObj();
const unique_ptr<WorkingSet> ws(stdx::make_unique<WorkingSet>());
diff --git a/src/mongo/dbtests/query_stage_subplan.cpp b/src/mongo/dbtests/query_stage_subplan.cpp
index cde78293033..9c83ca6c34b 100644
--- a/src/mongo/dbtests/query_stage_subplan.cpp
+++ b/src/mongo/dbtests/query_stage_subplan.cpp
@@ -44,25 +44,23 @@
namespace QueryStageSubplan {
+static const NamespaceString nss("unittests.QueryStageSubplan");
+
class QueryStageSubplanBase {
public:
QueryStageSubplanBase() : _client(&_txn) {}
virtual ~QueryStageSubplanBase() {
- OldClientWriteContext ctx(&_txn, ns());
- _client.dropCollection(ns());
+ OldClientWriteContext ctx(&_txn, nss.ns());
+ _client.dropCollection(nss.ns());
}
void addIndex(const BSONObj& obj) {
- ASSERT_OK(dbtests::createIndex(&_txn, ns(), obj));
+ ASSERT_OK(dbtests::createIndex(&_txn, nss.ns(), obj));
}
void insert(const BSONObj& doc) {
- _client.insert(ns(), doc);
- }
-
- static const char* ns() {
- return "unittests.QueryStageSubplan";
+ _client.insert(nss.ns(), doc);
}
protected:
@@ -72,7 +70,6 @@ protected:
std::unique_ptr<CanonicalQuery> cqFromFindCommand(const std::string& findCmd) {
BSONObj cmdObj = fromjson(findCmd);
- const NamespaceString nss("testns.testcoll");
bool isExplain = false;
auto lpq =
unittest::assertGet(LiteParsedQuery::makeFromFindCommand(nss, cmdObj, isExplain));
@@ -96,7 +93,7 @@ private:
class QueryStageSubplanGeo2dOr : public QueryStageSubplanBase {
public:
void run() {
- OldClientWriteContext ctx(&_txn, ns());
+ OldClientWriteContext ctx(&_txn, nss.ns());
addIndex(BSON("a"
<< "2d"
<< "b" << 1));
@@ -107,7 +104,7 @@ public:
"{$or: [{a: {$geoWithin: {$centerSphere: [[0,0],10]}}},"
"{a: {$geoWithin: {$centerSphere: [[1,1],10]}}}]}");
- auto statusWithCQ = CanonicalQuery::canonicalize(ns(), query);
+ auto statusWithCQ = CanonicalQuery::canonicalize(nss, query);
ASSERT_OK(statusWithCQ.getStatus());
std::unique_ptr<CanonicalQuery> cq = std::move(statusWithCQ.getValue());
@@ -133,7 +130,7 @@ public:
class QueryStageSubplanPlanFromCache : public QueryStageSubplanBase {
public:
void run() {
- OldClientWriteContext ctx(&_txn, ns());
+ OldClientWriteContext ctx(&_txn, nss.ns());
addIndex(BSON("a" << 1));
addIndex(BSON("a" << 1 << "b" << 1));
@@ -150,7 +147,7 @@ public:
Collection* collection = ctx.getCollection();
- auto statusWithCQ = CanonicalQuery::canonicalize(ns(), query);
+ auto statusWithCQ = CanonicalQuery::canonicalize(nss, query);
ASSERT_OK(statusWithCQ.getStatus());
std::unique_ptr<CanonicalQuery> cq = std::move(statusWithCQ.getValue());
@@ -380,7 +377,7 @@ public:
class QueryStageSubplanPlanContainedOr : public QueryStageSubplanBase {
public:
void run() {
- OldClientWriteContext ctx(&_txn, ns());
+ OldClientWriteContext ctx(&_txn, nss.ns());
addIndex(BSON("b" << 1 << "a" << 1));
addIndex(BSON("c" << 1 << "a" << 1));
@@ -392,7 +389,7 @@ public:
insert(BSON("_id" << 3 << "a" << 1 << "c" << 3));
insert(BSON("_id" << 4 << "a" << 1 << "c" << 4));
- auto cq = unittest::assertGet(CanonicalQuery::canonicalize(ns(), query));
+ auto cq = unittest::assertGet(CanonicalQuery::canonicalize(nss, query));
Collection* collection = ctx.getCollection();
@@ -438,7 +435,7 @@ public:
class QueryStageSubplanPlanRootedOrNE : public QueryStageSubplanBase {
public:
void run() {
- OldClientWriteContext ctx(&_txn, ns());
+ OldClientWriteContext ctx(&_txn, nss.ns());
addIndex(BSON("a" << 1 << "b" << 1));
addIndex(BSON("a" << 1 << "c" << 1));
@@ -451,7 +448,7 @@ public:
BSONObj query = fromjson("{$or: [{a: 1}, {a: {$ne:1}}]}");
BSONObj sort = BSON("d" << 1);
BSONObj projection;
- auto cq = unittest::assertGet(CanonicalQuery::canonicalize(ns(), query, sort, projection));
+ auto cq = unittest::assertGet(CanonicalQuery::canonicalize(nss, query, sort, projection));
Collection* collection = ctx.getCollection();
diff --git a/src/mongo/dbtests/query_stage_update.cpp b/src/mongo/dbtests/query_stage_update.cpp
index 330acf33b8f..fa8370dd3ee 100644
--- a/src/mongo/dbtests/query_stage_update.cpp
+++ b/src/mongo/dbtests/query_stage_update.cpp
@@ -56,34 +56,35 @@ namespace QueryStageUpdate {
using std::unique_ptr;
using std::vector;
+static const NamespaceString nss("unittests.QueryStageUpdate");
+
class QueryStageUpdateBase {
public:
- QueryStageUpdateBase()
- : _client(&_txn), _ns("unittests.QueryStageUpdate"), _nsString(StringData(ns())) {
- OldClientWriteContext ctx(&_txn, ns());
- _client.dropCollection(ns());
- _client.createCollection(ns());
+ QueryStageUpdateBase() : _client(&_txn) {
+ OldClientWriteContext ctx(&_txn, nss.ns());
+ _client.dropCollection(nss.ns());
+ _client.createCollection(nss.ns());
}
virtual ~QueryStageUpdateBase() {
- OldClientWriteContext ctx(&_txn, ns());
- _client.dropCollection(ns());
+ OldClientWriteContext ctx(&_txn, nss.ns());
+ _client.dropCollection(nss.ns());
}
void insert(const BSONObj& doc) {
- _client.insert(ns(), doc);
+ _client.insert(nss.ns(), doc);
}
void remove(const BSONObj& obj) {
- _client.remove(ns(), obj);
+ _client.remove(nss.ns(), obj);
}
size_t count(const BSONObj& query) {
- return _client.count(ns(), query, 0, 0, 0);
+ return _client.count(nss.ns(), query, 0, 0, 0);
}
unique_ptr<CanonicalQuery> canonicalize(const BSONObj& query) {
- auto statusWithCQ = CanonicalQuery::canonicalize(ns(), query);
+ auto statusWithCQ = CanonicalQuery::canonicalize(nss, query);
ASSERT_OK(statusWithCQ.getStatus());
return std::move(statusWithCQ.getValue());
}
@@ -163,22 +164,11 @@ public:
ASSERT(foundDoc);
}
- const char* ns() {
- return _ns.c_str();
- }
-
- const NamespaceString& nsString() {
- return _nsString;
- }
-
protected:
OperationContextImpl _txn;
private:
DBDirectClient _client;
-
- std::string _ns;
- NamespaceString _nsString;
};
/**
@@ -189,7 +179,7 @@ public:
void run() {
// Run the update.
{
- OldClientWriteContext ctx(&_txn, ns());
+ OldClientWriteContext ctx(&_txn, nss.ns());
CurOp& curOp = *CurOp::get(_txn);
OpDebug* opDebug = &curOp.debug();
UpdateDriver driver((UpdateDriver::Options()));
@@ -198,8 +188,8 @@ public:
// Collection should be empty.
ASSERT_EQUALS(0U, count(BSONObj()));
- UpdateRequest request(nsString());
- UpdateLifecycleImpl updateLifecycle(false, nsString());
+ UpdateRequest request(nss);
+ UpdateLifecycleImpl updateLifecycle(false, nss);
request.setLifecycle(&updateLifecycle);
// Update is the upsert {_id: 0, x: 1}, {$set: {y: 2}}.
@@ -228,7 +218,7 @@ public:
// Verify the contents of the resulting collection.
{
- AutoGetCollectionForRead ctx(&_txn, ns());
+ AutoGetCollectionForRead ctx(&_txn, nss.ns());
Collection* collection = ctx.getCollection();
vector<BSONObj> objs;
@@ -250,7 +240,7 @@ public:
void run() {
// Run the update.
{
- OldClientWriteContext ctx(&_txn, ns());
+ OldClientWriteContext ctx(&_txn, nss.ns());
// Populate the collection.
for (int i = 0; i < 10; ++i) {
@@ -262,14 +252,14 @@ public:
OpDebug* opDebug = &curOp.debug();
UpdateDriver driver((UpdateDriver::Options()));
Database* db = ctx.db();
- Collection* coll = db->getCollection(ns());
+ Collection* coll = db->getCollection(nss.ns());
// Get the RecordIds that would be returned by an in-order scan.
vector<RecordId> locs;
getLocs(coll, CollectionScanParams::FORWARD, &locs);
- UpdateRequest request(nsString());
- UpdateLifecycleImpl updateLifecycle(false, nsString());
+ UpdateRequest request(nss);
+ UpdateLifecycleImpl updateLifecycle(false, nss);
request.setLifecycle(&updateLifecycle);
// Update is a multi-update that sets 'bar' to 3 in every document
@@ -334,7 +324,7 @@ public:
// Check the contents of the collection.
{
- AutoGetCollectionForRead ctx(&_txn, ns());
+ AutoGetCollectionForRead ctx(&_txn, nss.ns());
Collection* collection = ctx.getCollection();
vector<BSONObj> objs;
@@ -368,11 +358,11 @@ public:
ASSERT_EQUALS(10U, count(BSONObj()));
// Various variables we'll need.
- OldClientWriteContext ctx(&_txn, ns());
+ OldClientWriteContext ctx(&_txn, nss.ns());
OpDebug* opDebug = &CurOp::get(_txn)->debug();
Collection* coll = ctx.getCollection();
- UpdateLifecycleImpl updateLifecycle(false, nsString());
- UpdateRequest request(nsString());
+ UpdateLifecycleImpl updateLifecycle(false, nss);
+ UpdateRequest request(nss);
UpdateDriver driver((UpdateDriver::Options()));
const int targetDocIndex = 0; // We'll be working with the first doc in the collection.
const BSONObj query = BSON("foo" << BSON("$gte" << targetDocIndex));
@@ -456,11 +446,11 @@ public:
ASSERT_EQUALS(50U, count(BSONObj()));
// Various variables we'll need.
- OldClientWriteContext ctx(&_txn, ns());
+ OldClientWriteContext ctx(&_txn, nss.ns());
OpDebug* opDebug = &CurOp::get(_txn)->debug();
Collection* coll = ctx.getCollection();
- UpdateLifecycleImpl updateLifecycle(false, nsString());
- UpdateRequest request(nsString());
+ UpdateLifecycleImpl updateLifecycle(false, nss);
+ UpdateRequest request(nss);
UpdateDriver driver((UpdateDriver::Options()));
const int targetDocIndex = 10;
const BSONObj query = BSON("foo" << BSON("$gte" << targetDocIndex));
@@ -538,11 +528,11 @@ class QueryStageUpdateSkipOwnedObjects : public QueryStageUpdateBase {
public:
void run() {
// Various variables we'll need.
- OldClientWriteContext ctx(&_txn, ns());
+ OldClientWriteContext ctx(&_txn, nss.ns());
OpDebug* opDebug = &CurOp::get(_txn)->debug();
Collection* coll = ctx.getCollection();
- UpdateLifecycleImpl updateLifecycle(false, nsString());
- UpdateRequest request(nsString());
+ UpdateLifecycleImpl updateLifecycle(false, nss);
+ UpdateRequest request(nss);
UpdateDriver driver((UpdateDriver::Options()));
const BSONObj query = BSONObj();
const unique_ptr<WorkingSet> ws(stdx::make_unique<WorkingSet>());
diff --git a/src/mongo/s/chunk_manager.cpp b/src/mongo/s/chunk_manager.cpp
index 9cc400ae1a6..b200ce4e482 100644
--- a/src/mongo/s/chunk_manager.cpp
+++ b/src/mongo/s/chunk_manager.cpp
@@ -466,7 +466,8 @@ ChunkPtr ChunkManager::findIntersectingChunk(const BSONObj& shardKey) const {
}
void ChunkManager::getShardIdsForQuery(set<ShardId>& shardIds, const BSONObj& query) const {
- auto statusWithCQ = CanonicalQuery::canonicalize(_ns, query, WhereCallbackNoop());
+ auto statusWithCQ =
+ CanonicalQuery::canonicalize(NamespaceString(_ns), query, WhereCallbackNoop());
uassertStatusOK(statusWithCQ.getStatus());
unique_ptr<CanonicalQuery> cq = std::move(statusWithCQ.getValue());
diff --git a/src/mongo/s/chunk_manager_targeter_test.cpp b/src/mongo/s/chunk_manager_targeter_test.cpp
index ff6d83cf0ea..8a8a629102b 100644
--- a/src/mongo/s/chunk_manager_targeter_test.cpp
+++ b/src/mongo/s/chunk_manager_targeter_test.cpp
@@ -55,7 +55,8 @@ using std::make_pair;
// Utility function to create a CanonicalQuery
unique_ptr<CanonicalQuery> canonicalize(const char* queryStr) {
BSONObj queryObj = fromjson(queryStr);
- auto statusWithCQ = CanonicalQuery::canonicalize("test.foo", queryObj, WhereCallbackNoop());
+ const NamespaceString nss("test.foo");
+ auto statusWithCQ = CanonicalQuery::canonicalize(nss, queryObj, WhereCallbackNoop());
ASSERT_OK(statusWithCQ.getStatus());
return std::move(statusWithCQ.getValue());
}
diff --git a/src/mongo/s/shard_key_pattern.cpp b/src/mongo/s/shard_key_pattern.cpp
index 24485148810..48b3eb13268 100644
--- a/src/mongo/s/shard_key_pattern.cpp
+++ b/src/mongo/s/shard_key_pattern.cpp
@@ -265,7 +265,8 @@ StatusWith<BSONObj> ShardKeyPattern::extractShardKeyFromQuery(const BSONObj& bas
return StatusWith<BSONObj>(BSONObj());
// Extract equalities from query
- auto statusWithCQ = CanonicalQuery::canonicalize("", basicQuery, WhereCallbackNoop());
+ auto statusWithCQ =
+ CanonicalQuery::canonicalize(NamespaceString(""), basicQuery, WhereCallbackNoop());
if (!statusWithCQ.isOK()) {
return StatusWith<BSONObj>(statusWithCQ.getStatus());
}