summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaloian Manassiev <kaloian.manassiev@mongodb.com>2017-03-01 14:20:23 -0500
committerKaloian Manassiev <kaloian.manassiev@mongodb.com>2017-03-02 18:53:24 -0500
commit0453687cfd42029d91201d8092b760f65624ae0d (patch)
treefaeebf1f891a8696842f66600820791129ead8ef
parent2c90ba1e6bbcb096f0d61e706b57b31a3d83d1f1 (diff)
downloadmongo-0453687cfd42029d91201d8092b760f65624ae0d.tar.gz
SERVER-28155 Move ChunkManagerTargeter in the sharding commands library
(cherry picked from commit 14c45cd2ddc67ecb3a21001dce416dd41eed5163)
-rw-r--r--src/mongo/s/SConscript20
-rw-r--r--src/mongo/s/chunk_manager_index_bounds_test.cpp (renamed from src/mongo/s/chunk_manager_targeter_test.cpp)239
-rw-r--r--src/mongo/s/commands/SConscript3
-rw-r--r--src/mongo/s/commands/chunk_manager_targeter.cpp (renamed from src/mongo/s/chunk_manager_targeter.cpp)2
-rw-r--r--src/mongo/s/commands/chunk_manager_targeter.h (renamed from src/mongo/s/chunk_manager_targeter.h)0
-rw-r--r--src/mongo/s/commands/cluster_write.cpp2
-rw-r--r--src/mongo/s/commands/cluster_write_cmd.cpp2
-rw-r--r--src/mongo/s/write_ops/batch_write_exec_test.cpp2
-rw-r--r--src/mongo/s/write_ops/batch_write_op_test.cpp2
-rw-r--r--src/mongo/s/write_ops/mock_ns_targeter.h (renamed from src/mongo/s/mock_ns_targeter.h)0
-rw-r--r--src/mongo/s/write_ops/write_op_test.cpp2
11 files changed, 126 insertions, 148 deletions
diff --git a/src/mongo/s/SConscript b/src/mongo/s/SConscript
index 73e4b6831b7..492a7c01431 100644
--- a/src/mongo/s/SConscript
+++ b/src/mongo/s/SConscript
@@ -188,20 +188,6 @@ env.CppUnitTest(
]
)
-env.CppUnitTest(
- target='chunk_manager_targeter_test',
- source=[
- 'chunk_manager_targeter_test.cpp',
- ],
- LIBDEPS=[
- 'coreshard',
- 'mongoscore',
- '$BUILD_DIR/mongo/db/auth/authorization_manager_mock_init',
- '$BUILD_DIR/mongo/db/query/query_test_service_context',
- '$BUILD_DIR/mongo/db/service_context_noop_init',
- ]
-)
-
env.CppUnitTest('request_types_test',
source=[
'request_types/add_shard_request_test.cpp',
@@ -249,7 +235,8 @@ env.Library(
env.CppUnitTest(
target='catalog_cache_test',
source=[
- 'chunk_manager_test.cpp'
+ 'chunk_manager_test.cpp',
+ 'chunk_manager_index_bounds_test.cpp',
],
LIBDEPS=[
'$BUILD_DIR/mongo/s/catalog/sharding_catalog_test_fixture',
@@ -275,7 +262,6 @@ env.Library(
env.Library(
target='mongoscore',
source=[
- 'chunk_manager_targeter.cpp',
'cluster_cursor_stats.cpp',
'mongos_options.cpp',
's_only.cpp',
@@ -291,8 +277,6 @@ env.Library(
'$BUILD_DIR/mongo/s/query/cluster_query',
'$BUILD_DIR/mongo/util/concurrency/task',
'cluster_last_error_info',
- 'write_ops/cluster_write_op',
- 'write_ops/cluster_write_op_conversion',
],
)
diff --git a/src/mongo/s/chunk_manager_targeter_test.cpp b/src/mongo/s/chunk_manager_index_bounds_test.cpp
index 14a346644eb..5a6aa4ec7bf 100644
--- a/src/mongo/s/chunk_manager_targeter_test.cpp
+++ b/src/mongo/s/chunk_manager_index_bounds_test.cpp
@@ -1,5 +1,5 @@
/**
- * Copyright (C) 2014 10gen Inc.
+ * Copyright (C) 2017 MongoDB Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
@@ -17,13 +17,13 @@
* code of portions of this program with the OpenSSL library under certain
* conditions as described in each individual source file and distribute
* linked combinations including the program with the OpenSSL library. You
- * must comply with the GNU Affero General Public License in all respects
- * for all of the code used other than as permitted herein. If you modify
- * file(s) with this exception, you may extend this exception to your
- * version of the file(s), but you are not obligated to do so. If you do not
- * wish to do so, delete this exception statement from your version. If you
- * delete this exception statement from all source files in the program,
- * then also delete it in the license file.
+ * must comply with the GNU Affero General Public License in all respects for
+ * all of the code used other than as permitted herein. If you modify file(s)
+ * with this exception, you may extend this exception to your version of the
+ * file(s), but you are not obligated to do so. If you do not wish to do so,
+ * delete this exception statement from your version. If you delete this
+ * exception statement from all source files in the program, then also delete
+ * it in the license file.
*/
#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kSharding
@@ -34,100 +34,93 @@
#include "mongo/db/matcher/extensions_callback_noop.h"
#include "mongo/db/namespace_string.h"
#include "mongo/db/query/canonical_query.h"
-#include "mongo/db/query/query_test_service_context.h"
#include "mongo/s/chunk_manager.h"
#include "mongo/s/shard_key_pattern.h"
+#include "mongo/s/sharding_test_fixture.h"
#include "mongo/unittest/unittest.h"
#include "mongo/util/log.h"
+namespace mongo {
namespace {
-using namespace mongo;
-
-using std::unique_ptr;
-using std::make_pair;
+const double INF = std::numeric_limits<double>::infinity();
/**
- * ChunkManager targeting test
- *
- * TODO:
- * Pull the implementation out of chunk.cpp
+ * Test the chunk manager index bounds for query functionality.
*/
+class CMCollapseTreeTest : public ShardingTestFixture {
+protected:
+ // Utility function to create a CanonicalQuery
+ std::unique_ptr<CanonicalQuery> canonicalize(const char* queryStr) {
+ BSONObj queryObj = fromjson(queryStr);
+ const NamespaceString nss("test.foo");
+ auto qr = stdx::make_unique<QueryRequest>(nss);
+ qr->setFilter(queryObj);
+ auto statusWithCQ = CanonicalQuery::canonicalize(
+ operationContext(), std::move(qr), ExtensionsCallbackNoop());
+ ASSERT_OK(statusWithCQ.getStatus());
+ return std::move(statusWithCQ.getValue());
+ }
-// Utility function to create a CanonicalQuery
-unique_ptr<CanonicalQuery> canonicalize(const char* queryStr) {
- QueryTestServiceContext serviceContext;
- auto txn = serviceContext.makeOperationContext();
-
- BSONObj queryObj = fromjson(queryStr);
- const NamespaceString nss("test.foo");
- auto qr = stdx::make_unique<QueryRequest>(nss);
- qr->setFilter(queryObj);
- auto statusWithCQ =
- CanonicalQuery::canonicalize(txn.get(), std::move(qr), ExtensionsCallbackNoop());
- ASSERT_OK(statusWithCQ.getStatus());
- return std::move(statusWithCQ.getValue());
-}
-
-void checkIndexBoundsWithKey(const char* keyStr,
- const char* queryStr,
- const IndexBounds& expectedBounds) {
- unique_ptr<CanonicalQuery> query(canonicalize(queryStr));
- ASSERT(query.get() != NULL);
-
- BSONObj key = fromjson(keyStr);
-
- IndexBounds indexBounds = ChunkManager::getIndexBoundsForQuery(key, *query.get());
- ASSERT_EQUALS(indexBounds.size(), expectedBounds.size());
- for (size_t i = 0; i < indexBounds.size(); i++) {
- const OrderedIntervalList& oil = indexBounds.fields[i];
- const OrderedIntervalList& expectedOil = expectedBounds.fields[i];
- ASSERT_EQUALS(oil.intervals.size(), expectedOil.intervals.size());
- for (size_t i = 0; i < oil.intervals.size(); i++) {
- if (Interval::INTERVAL_EQUALS != oil.intervals[i].compare(expectedOil.intervals[i])) {
- log() << oil.intervals[i] << " != " << expectedOil.intervals[i];
+ void checkIndexBoundsWithKey(const char* keyStr,
+ const char* queryStr,
+ const IndexBounds& expectedBounds) {
+ auto query(canonicalize(queryStr));
+ ASSERT(query.get() != NULL);
+
+ BSONObj key = fromjson(keyStr);
+
+ IndexBounds indexBounds = ChunkManager::getIndexBoundsForQuery(key, *query.get());
+ ASSERT_EQUALS(indexBounds.size(), expectedBounds.size());
+ for (size_t i = 0; i < indexBounds.size(); i++) {
+ const OrderedIntervalList& oil = indexBounds.fields[i];
+ const OrderedIntervalList& expectedOil = expectedBounds.fields[i];
+ ASSERT_EQUALS(oil.intervals.size(), expectedOil.intervals.size());
+ for (size_t i = 0; i < oil.intervals.size(); i++) {
+ if (Interval::INTERVAL_EQUALS !=
+ oil.intervals[i].compare(expectedOil.intervals[i])) {
+ log() << oil.intervals[i] << " != " << expectedOil.intervals[i];
+ }
+ ASSERT_EQUALS(Interval::INTERVAL_EQUALS,
+ oil.intervals[i].compare(expectedOil.intervals[i]));
}
- ASSERT_EQUALS(Interval::INTERVAL_EQUALS,
- oil.intervals[i].compare(expectedOil.intervals[i]));
}
}
-}
-// Assume shard key is { a: 1 }
-void checkIndexBounds(const char* queryStr, const OrderedIntervalList& expectedOil) {
- unique_ptr<CanonicalQuery> query(canonicalize(queryStr));
- ASSERT(query.get() != NULL);
+ // Assume shard key is { a: 1 }
+ void checkIndexBounds(const char* queryStr, const OrderedIntervalList& expectedOil) {
+ auto query(canonicalize(queryStr));
+ ASSERT(query.get() != NULL);
- BSONObj key = fromjson("{a: 1}");
+ BSONObj key = fromjson("{a: 1}");
- IndexBounds indexBounds = ChunkManager::getIndexBoundsForQuery(key, *query.get());
- ASSERT_EQUALS(indexBounds.size(), 1U);
- const OrderedIntervalList& oil = indexBounds.fields.front();
+ IndexBounds indexBounds = ChunkManager::getIndexBoundsForQuery(key, *query.get());
+ ASSERT_EQUALS(indexBounds.size(), 1U);
+ const OrderedIntervalList& oil = indexBounds.fields.front();
- if (oil.intervals.size() != expectedOil.intervals.size()) {
- for (size_t i = 0; i < oil.intervals.size(); i++) {
- log() << oil.intervals[i];
+ if (oil.intervals.size() != expectedOil.intervals.size()) {
+ for (size_t i = 0; i < oil.intervals.size(); i++) {
+ log() << oil.intervals[i];
+ }
}
- }
- ASSERT_EQUALS(oil.intervals.size(), expectedOil.intervals.size());
- for (size_t i = 0; i < oil.intervals.size(); i++) {
- ASSERT_EQUALS(Interval::INTERVAL_EQUALS,
- oil.intervals[i].compare(expectedOil.intervals[i]));
+ ASSERT_EQUALS(oil.intervals.size(), expectedOil.intervals.size());
+ for (size_t i = 0; i < oil.intervals.size(); i++) {
+ ASSERT_EQUALS(Interval::INTERVAL_EQUALS,
+ oil.intervals[i].compare(expectedOil.intervals[i]));
+ }
}
-}
-
-const double INF = std::numeric_limits<double>::infinity();
+};
// { a: 2 } -> a: [2, 2]
-TEST(CMCollapseTreeTest, Basic) {
+TEST_F(CMCollapseTreeTest, Basic) {
OrderedIntervalList expected;
expected.intervals.push_back(Interval(BSON("" << 2 << "" << 2), true, true));
checkIndexBounds("{a: 2}", expected);
}
// { b: 2 } -> a: [MinKey, MaxKey]
-TEST(CMCollapseTreeTest, AllValue) {
+TEST_F(CMCollapseTreeTest, AllValue) {
OrderedIntervalList expected;
BSONObjBuilder builder;
builder.appendMinKey("");
@@ -137,7 +130,7 @@ TEST(CMCollapseTreeTest, AllValue) {
}
// { 'a' : { '$not' : { '$gt' : 1 } } } -> a: [MinKey, 1.0], (inf.0, MaxKey]
-TEST(CMCollapseTreeTest, NegativeGT) {
+TEST_F(CMCollapseTreeTest, NegativeGT) {
OrderedIntervalList expected;
{
BSONObjBuilder builder;
@@ -155,7 +148,7 @@ TEST(CMCollapseTreeTest, NegativeGT) {
}
// {$or: [{a: 20}, {$and: [{a:1}, {b:7}]}]} -> a: [1.0, 1.0], [20.0, 20.0]
-TEST(CMCollapseTreeTest, OrWithAndChild) {
+TEST_F(CMCollapseTreeTest, OrWithAndChild) {
OrderedIntervalList expected;
expected.intervals.push_back(Interval(BSON("" << 1.0 << "" << 1.0), true, true));
expected.intervals.push_back(Interval(BSON("" << 20.0 << "" << 20.0), true, true));
@@ -163,7 +156,7 @@ TEST(CMCollapseTreeTest, OrWithAndChild) {
}
// {a:20, $or: [{b:1}, {c:7}]} -> a: [20.0, 20.0]
-TEST(CMCollapseTreeTest, AndWithUnindexedOrChild) {
+TEST_F(CMCollapseTreeTest, AndWithUnindexedOrChild) {
// Logic rewrite could give a tree with root OR.
OrderedIntervalList expected;
expected.intervals.push_back(Interval(BSON("" << 20.0 << "" << 20.0), true, true));
@@ -171,7 +164,7 @@ TEST(CMCollapseTreeTest, AndWithUnindexedOrChild) {
}
// {$or: [{a:{$gt:2,$lt:10}}, {a:{$gt:0,$lt:5}}]} -> a: (0.0, 10.0)
-TEST(CMCollapseTreeTest, OrOfAnd) {
+TEST_F(CMCollapseTreeTest, OrOfAnd) {
OrderedIntervalList expected;
expected.intervals.push_back(Interval(BSON("" << 0.0 << "" << 10.0), false, false));
checkIndexBounds("{$or: [{a:{$gt:2,$lt:10}}, {a:{$gt:0,$lt:5}}]}", expected);
@@ -179,7 +172,7 @@ TEST(CMCollapseTreeTest, OrOfAnd) {
// {$or: [{a:{$gt:2,$lt:10}}, {a:{$gt:0,$lt:15}}, {a:{$gt:20}}]}
// -> a: (0.0, 15.0), (20.0, inf.0]
-TEST(CMCollapseTreeTest, OrOfAnd2) {
+TEST_F(CMCollapseTreeTest, OrOfAnd2) {
OrderedIntervalList expected;
expected.intervals.push_back(Interval(BSON("" << 0.0 << "" << 15.0), false, false));
expected.intervals.push_back(Interval(BSON("" << 20.0 << "" << INF), false, true));
@@ -187,7 +180,7 @@ TEST(CMCollapseTreeTest, OrOfAnd2) {
}
// "{$or: [{a:{$gt:1,$lt:5},b:6}, {a:3,b:{$gt:0,$lt:10}}]}" -> a: (1.0, 5.0)
-TEST(CMCollapseTreeTest, OrOfAnd3) {
+TEST_F(CMCollapseTreeTest, OrOfAnd3) {
OrderedIntervalList expected;
expected.intervals.push_back(Interval(BSON("" << 1.0 << "" << 5.0), false, false));
checkIndexBounds("{$or: [{a:{$gt:1,$lt:5},b:6}, {a:3,b:{$gt:0,$lt:10}}]}", expected);
@@ -200,7 +193,7 @@ TEST(CMCollapseTreeTest, OrOfAnd3) {
// "{$or: [{a:{$gt:1,$lt:5}, b:{$gt:0,$lt:3}, c:6}, "
// "{a:3, b:{$gt:1,$lt:2}, c:{$gt:0,$lt:10}}]}",
// -> a: (1.0, 5.0), b: (0.0, 3.0)
-TEST(CMCollapseTreeTest, OrOfAnd4) {
+TEST_F(CMCollapseTreeTest, OrOfAnd4) {
IndexBounds expectedBounds;
expectedBounds.fields.push_back(OrderedIntervalList());
expectedBounds.fields.push_back(OrderedIntervalList());
@@ -219,7 +212,7 @@ TEST(CMCollapseTreeTest, OrOfAnd4) {
// "{$or: [{a:{$gt:1,$lt:5}, c:6}, "
// "{a:3, b:{$gt:1,$lt:2}, c:{$gt:0,$lt:10}}]}"));
// ->
-TEST(CMCollapseTreeTest, OrOfAnd5) {
+TEST_F(CMCollapseTreeTest, OrOfAnd5) {
IndexBounds expectedBounds;
expectedBounds.fields.push_back(OrderedIntervalList());
expectedBounds.fields.push_back(OrderedIntervalList());
@@ -239,7 +232,7 @@ TEST(CMCollapseTreeTest, OrOfAnd5) {
// {$or: [{a:{$in:[1]},b:{$in:[1]}}, {a:{$in:[1,5]},b:{$in:[1,5]}}]}
// -> a: [1], [5]; b: [1], [5]
-TEST(CMCollapseTreeTest, OrOfAnd6) {
+TEST_F(CMCollapseTreeTest, OrOfAnd6) {
IndexBounds expectedBounds;
expectedBounds.fields.push_back(OrderedIntervalList());
expectedBounds.fields.push_back(OrderedIntervalList());
@@ -267,7 +260,7 @@ TEST(CMCollapseTreeTest, OrOfAnd6) {
// {a : {$elemMatch: {b:1}}} -> a.b: [MinKey, MaxKey]
// Shard key doesn't allow multikey, but query on array should succeed without error.
-TEST(CMCollapseTreeTest, ElemMatchOneField) {
+TEST_F(CMCollapseTreeTest, ElemMatchOneField) {
IndexBounds expectedBounds;
expectedBounds.fields.push_back(OrderedIntervalList());
OrderedIntervalList& oil = expectedBounds.fields.front();
@@ -278,11 +271,11 @@ TEST(CMCollapseTreeTest, ElemMatchOneField) {
// {foo: {$all: [ {$elemMatch: {a:1, b:1}}, {$elemMatch: {a:2, b:2}}]}}
// -> foo.a: [1, 1]
// Or -> foo.a: [2, 2]
-TEST(CMCollapseTreeTest, BasicAllElemMatch) {
+TEST_F(CMCollapseTreeTest, BasicAllElemMatch) {
Interval expectedInterval(BSON("" << 1 << "" << 1), true, true);
const char* queryStr = "{foo: {$all: [ {$elemMatch: {a:1, b:1}} ]}}";
- unique_ptr<CanonicalQuery> query(canonicalize(queryStr));
+ auto query(canonicalize(queryStr));
ASSERT(query.get() != NULL);
BSONObj key = fromjson("{'foo.a': 1}");
@@ -299,7 +292,7 @@ TEST(CMCollapseTreeTest, BasicAllElemMatch) {
}
// {a : [1, 2, 3]} -> a: [1, 1], [[1, 2, 3], [1, 2, 3]]
-TEST(CMCollapseTreeTest, ArrayEquality) {
+TEST_F(CMCollapseTreeTest, ArrayEquality) {
OrderedIntervalList expected;
expected.intervals.push_back(Interval(BSON("" << 1 << "" << 1), true, true));
BSONArray array(BSON_ARRAY(1 << 2 << 3));
@@ -315,7 +308,7 @@ TEST(CMCollapseTreeTest, ArrayEquality) {
//
// { a: /abc/ } -> a: ["", {}), [/abc/, /abc/]
-TEST(CMCollapseTreeTest, Regex) {
+TEST_F(CMCollapseTreeTest, Regex) {
OrderedIntervalList expected;
expected.intervals.push_back(Interval(BSON(""
<< ""
@@ -331,7 +324,7 @@ TEST(CMCollapseTreeTest, Regex) {
}
// {$where: 'this.credits == this.debits' }
-TEST(CMCollapseTreeTest, Where) {
+TEST_F(CMCollapseTreeTest, Where) {
OrderedIntervalList expected;
BSONObjBuilder builder;
builder.appendMinKey("");
@@ -341,7 +334,7 @@ TEST(CMCollapseTreeTest, Where) {
}
// { $text: { $search: "coffee -cake" } }
-TEST(CMCollapseTreeTest, Text) {
+TEST_F(CMCollapseTreeTest, Text) {
OrderedIntervalList expected;
BSONObjBuilder builder;
builder.appendMinKey("");
@@ -351,7 +344,7 @@ TEST(CMCollapseTreeTest, Text) {
}
// { a: 2, $text: { $search: "leche", $language: "es" } }
-TEST(CMCollapseTreeTest, TextWithQuery) {
+TEST_F(CMCollapseTreeTest, TextWithQuery) {
OrderedIntervalList expected;
BSONObjBuilder builder;
builder.appendMinKey("");
@@ -361,9 +354,9 @@ TEST(CMCollapseTreeTest, TextWithQuery) {
}
// { a: 0 } -> hashed a: [hash(0), hash(0)]
-TEST(CMCollapseTreeTest, HashedSinglePoint) {
+TEST_F(CMCollapseTreeTest, HashedSinglePoint) {
const char* queryStr = "{ a: 0 }";
- unique_ptr<CanonicalQuery> query(canonicalize(queryStr));
+ auto query(canonicalize(queryStr));
ASSERT(query.get() != NULL);
BSONObj key = fromjson("{a: 'hashed'}");
@@ -377,7 +370,7 @@ TEST(CMCollapseTreeTest, HashedSinglePoint) {
}
// { a: { $lt: 2, $gt: 1} } -> hashed a: [Minkey, Maxkey]
-TEST(CMCollapseTreeTest, HashedRange) {
+TEST_F(CMCollapseTreeTest, HashedRange) {
IndexBounds expectedBounds;
expectedBounds.fields.push_back(OrderedIntervalList());
OrderedIntervalList& expectedOil = expectedBounds.fields.front();
@@ -389,7 +382,7 @@ TEST(CMCollapseTreeTest, HashedRange) {
}
// { a: /abc/ } -> hashed a: [Minkey, Maxkey]
-TEST(CMCollapseTreeTest, HashedRegex) {
+TEST_F(CMCollapseTreeTest, HashedRegex) {
IndexBounds expectedBounds;
expectedBounds.fields.push_back(OrderedIntervalList());
OrderedIntervalList& expectedOil = expectedBounds.fields.front();
@@ -402,50 +395,52 @@ TEST(CMCollapseTreeTest, HashedRegex) {
}
/**
- * KeyPattern key bounds generation test
+ * Tests the KeyPattern key bounds generation logic.
*/
-
-void CheckBoundList(const BoundList& list, const BoundList& expected) {
- ASSERT_EQUALS(list.size(), expected.size());
- for (size_t i = 0; i < list.size(); i++) {
- ASSERT_EQUALS(list[i].first.woCompare(expected[i].first), 0);
- ASSERT_EQUALS(list[i].second.woCompare(expected[i].second), 0);
+class CMKeyBoundsTest : public mongo::unittest::Test {
+protected:
+ void checkBoundList(const BoundList& list, const BoundList& expected) {
+ ASSERT_EQUALS(list.size(), expected.size());
+ for (size_t i = 0; i < list.size(); i++) {
+ ASSERT_EQUALS(list[i].first.woCompare(expected[i].first), 0);
+ ASSERT_EQUALS(list[i].second.woCompare(expected[i].second), 0);
+ }
}
-}
+};
// Key { a: 1 }, Bounds a: [0]
// => { a: 0 } -> { a: 0 }
-TEST(CMKeyBoundsTest, Basic) {
+TEST_F(CMKeyBoundsTest, Basic) {
IndexBounds indexBounds;
indexBounds.fields.push_back(OrderedIntervalList());
indexBounds.fields.front().intervals.push_back(Interval(BSON("" << 0 << "" << 0), true, true));
BoundList expectedList;
- expectedList.push_back(make_pair(fromjson("{a: 0}"), fromjson("{a: 0}")));
+ expectedList.emplace_back(fromjson("{a: 0}"), fromjson("{a: 0}"));
ShardKeyPattern skeyPattern(fromjson("{a: 1}"));
BoundList list = skeyPattern.flattenBounds(indexBounds);
- CheckBoundList(list, expectedList);
+ checkBoundList(list, expectedList);
}
// Key { a: 1 }, Bounds a: [2, 3)
// => { a: 2 } -> { a: 3 } // bound inclusion is ignored.
-TEST(CMKeyBoundsTest, SingleInterval) {
+TEST_F(CMKeyBoundsTest, SingleInterval) {
IndexBounds indexBounds;
indexBounds.fields.push_back(OrderedIntervalList());
indexBounds.fields.front().intervals.push_back(Interval(BSON("" << 2 << "" << 3), true, false));
BoundList expectedList;
- expectedList.push_back(make_pair(fromjson("{a: 2}"), fromjson("{a: 3}")));
+ expectedList.emplace_back(fromjson("{a: 2}"), fromjson("{a: 3}"));
ShardKeyPattern skeyPattern(fromjson("{a: 1}"));
BoundList list = skeyPattern.flattenBounds(indexBounds);
- CheckBoundList(list, expectedList);
+ checkBoundList(list, expectedList);
}
// Key { a: 1, b: 1, c: 1 }, Bounds a: [2, 3), b: [2, 3), c: [2: 3)
// => { a: 2, b: 2, c: 2 } -> { a: 3, b: 3, c: 3 }
-TEST(CMKeyBoundsTest, MultiIntervals) {
+TEST_F(CMKeyBoundsTest, MultiIntervals) {
IndexBounds indexBounds;
indexBounds.fields.push_back(OrderedIntervalList());
indexBounds.fields.push_back(OrderedIntervalList());
@@ -455,19 +450,18 @@ TEST(CMKeyBoundsTest, MultiIntervals) {
indexBounds.fields[2].intervals.push_back(Interval(BSON("" << 2 << "" << 3), true, false));
BoundList expectedList;
- expectedList.push_back(
- make_pair(fromjson("{ a: 2, b: 2, c: 2 }"), fromjson("{ a: 3, b: 3, c: 3 }")));
+ expectedList.emplace_back(fromjson("{ a: 2, b: 2, c: 2 }"), fromjson("{ a: 3, b: 3, c: 3 }"));
ShardKeyPattern skeyPattern(fromjson("{a: 1, b: 1, c: 1}"));
BoundList list = skeyPattern.flattenBounds(indexBounds);
- CheckBoundList(list, expectedList);
+ checkBoundList(list, expectedList);
}
// Key { a: 1, b: 1, c: 1 }, Bounds a: [0, 0], b: { $in: [4, 5, 6] }, c: [2: 3)
// => { a: 0, b: 4, c: 2 } -> { a: 0, b: 4, c: 3 }
// { a: 0, b: 5, c: 2 } -> { a: 0, b: 5, c: 3 }
// { a: 0, b: 6, c: 2 } -> { a: 0, b: 6, c: 3 }
-TEST(CMKeyBoundsTest, IntervalExpansion) {
+TEST_F(CMKeyBoundsTest, IntervalExpansion) {
IndexBounds indexBounds;
indexBounds.fields.push_back(OrderedIntervalList());
indexBounds.fields.push_back(OrderedIntervalList());
@@ -482,22 +476,19 @@ TEST(CMKeyBoundsTest, IntervalExpansion) {
indexBounds.fields[2].intervals.push_back(Interval(BSON("" << 2 << "" << 3), true, false));
BoundList expectedList;
- expectedList.push_back(
- make_pair(fromjson("{ a: 0, b: 4, c: 2 }"), fromjson("{ a: 0, b: 4, c: 3 }")));
- expectedList.push_back(
- make_pair(fromjson("{ a: 0, b: 5, c: 2 }"), fromjson("{ a: 0, b: 5, c: 3 }")));
- expectedList.push_back(
- make_pair(fromjson("{ a: 0, b: 6, c: 2 }"), fromjson("{ a: 0, b: 6, c: 3 }")));
+ expectedList.emplace_back(fromjson("{ a: 0, b: 4, c: 2 }"), fromjson("{ a: 0, b: 4, c: 3 }"));
+ expectedList.emplace_back(fromjson("{ a: 0, b: 5, c: 2 }"), fromjson("{ a: 0, b: 5, c: 3 }"));
+ expectedList.emplace_back(fromjson("{ a: 0, b: 6, c: 2 }"), fromjson("{ a: 0, b: 6, c: 3 }"));
ShardKeyPattern skeyPattern(fromjson("{a: 1, b: 1, c: 1}"));
BoundList list = skeyPattern.flattenBounds(indexBounds);
- CheckBoundList(list, expectedList);
+ checkBoundList(list, expectedList);
}
// Key { a: 1, b: 1, c: 1 }, Bounds a: [0, 1], b: { $in: [4, 5, 6] }, c: [2: 3)
// => { a: 0, b: 4, c: 2 } -> { a: 1, b: 6, c: 3 }
// Since field "a" is not a point, expasion after "a" is not allowed.
-TEST(CMKeyBoundsTest, NonPointIntervalExpasion) {
+TEST_F(CMKeyBoundsTest, NonPointIntervalExpasion) {
IndexBounds indexBounds;
indexBounds.fields.push_back(OrderedIntervalList());
indexBounds.fields.push_back(OrderedIntervalList());
@@ -512,12 +503,12 @@ TEST(CMKeyBoundsTest, NonPointIntervalExpasion) {
indexBounds.fields[2].intervals.push_back(Interval(BSON("" << 2 << "" << 3), true, false));
BoundList expectedList;
- expectedList.push_back(
- make_pair(fromjson("{ a: 0, b: 4, c: 2 }"), fromjson("{ a: 1, b: 6, c: 3 }")));
+ expectedList.emplace_back(fromjson("{ a: 0, b: 4, c: 2 }"), fromjson("{ a: 1, b: 6, c: 3 }"));
ShardKeyPattern skeyPattern(fromjson("{a: 1, b: 1, c: 1}"));
BoundList list = skeyPattern.flattenBounds(indexBounds);
- CheckBoundList(list, expectedList);
+ checkBoundList(list, expectedList);
}
} // namespace
+} // namespace mongo
diff --git a/src/mongo/s/commands/SConscript b/src/mongo/s/commands/SConscript
index 940fe0bc6fc..0b0caf06e3a 100644
--- a/src/mongo/s/commands/SConscript
+++ b/src/mongo/s/commands/SConscript
@@ -19,6 +19,7 @@ env.Library(
env.Library(
target='cluster_commands',
source=[
+ 'chunk_manager_targeter.cpp',
'cluster_add_shard_cmd.cpp',
'cluster_add_shard_to_zone_cmd.cpp',
'cluster_aggregate.cpp',
@@ -86,6 +87,8 @@ env.Library(
'$BUILD_DIR/mongo/s/client/parallel',
'$BUILD_DIR/mongo/s/coreshard',
'$BUILD_DIR/mongo/s/mongoscore',
+ '$BUILD_DIR/mongo/s/write_ops/cluster_write_op',
+ '$BUILD_DIR/mongo/s/write_ops/cluster_write_op_conversion',
'$BUILD_DIR/mongo/transport/transport_layer_common',
]
)
diff --git a/src/mongo/s/chunk_manager_targeter.cpp b/src/mongo/s/commands/chunk_manager_targeter.cpp
index 2ffc7efeb55..9dfef97dfda 100644
--- a/src/mongo/s/chunk_manager_targeter.cpp
+++ b/src/mongo/s/commands/chunk_manager_targeter.cpp
@@ -30,7 +30,7 @@
#include "mongo/platform/basic.h"
-#include "mongo/s/chunk_manager_targeter.h"
+#include "mongo/s/commands/chunk_manager_targeter.h"
#include <boost/thread/tss.hpp>
diff --git a/src/mongo/s/chunk_manager_targeter.h b/src/mongo/s/commands/chunk_manager_targeter.h
index 9c8f136dad8..9c8f136dad8 100644
--- a/src/mongo/s/chunk_manager_targeter.h
+++ b/src/mongo/s/commands/chunk_manager_targeter.h
diff --git a/src/mongo/s/commands/cluster_write.cpp b/src/mongo/s/commands/cluster_write.cpp
index c36c47750dd..e235c3fa673 100644
--- a/src/mongo/s/commands/cluster_write.cpp
+++ b/src/mongo/s/commands/cluster_write.cpp
@@ -40,9 +40,9 @@
#include "mongo/s/catalog/sharding_catalog_client.h"
#include "mongo/s/catalog/type_collection.h"
#include "mongo/s/chunk.h"
-#include "mongo/s/chunk_manager_targeter.h"
#include "mongo/s/client/dbclient_multi_command.h"
#include "mongo/s/client/shard_registry.h"
+#include "mongo/s/commands/chunk_manager_targeter.h"
#include "mongo/s/config_server_client.h"
#include "mongo/s/grid.h"
#include "mongo/s/shard_util.h"
diff --git a/src/mongo/s/commands/cluster_write_cmd.cpp b/src/mongo/s/commands/cluster_write_cmd.cpp
index c7784629993..3200ac75bee 100644
--- a/src/mongo/s/commands/cluster_write_cmd.cpp
+++ b/src/mongo/s/commands/cluster_write_cmd.cpp
@@ -38,10 +38,10 @@
#include "mongo/db/lasterror.h"
#include "mongo/db/stats/counters.h"
#include "mongo/db/stats/counters.h"
-#include "mongo/s/chunk_manager_targeter.h"
#include "mongo/s/client/dbclient_multi_command.h"
#include "mongo/s/client/shard_registry.h"
#include "mongo/s/cluster_last_error_info.h"
+#include "mongo/s/commands/chunk_manager_targeter.h"
#include "mongo/s/commands/cluster_explain.h"
#include "mongo/s/commands/cluster_write.h"
#include "mongo/s/grid.h"
diff --git a/src/mongo/s/write_ops/batch_write_exec_test.cpp b/src/mongo/s/write_ops/batch_write_exec_test.cpp
index d79e45a1fa9..30833b726eb 100644
--- a/src/mongo/s/write_ops/batch_write_exec_test.cpp
+++ b/src/mongo/s/write_ops/batch_write_exec_test.cpp
@@ -36,10 +36,10 @@
#include "mongo/s/catalog/type_shard.h"
#include "mongo/s/client/mock_multi_write_command.h"
#include "mongo/s/client/shard_registry.h"
-#include "mongo/s/mock_ns_targeter.h"
#include "mongo/s/sharding_test_fixture.h"
#include "mongo/s/write_ops/batched_command_request.h"
#include "mongo/s/write_ops/batched_command_response.h"
+#include "mongo/s/write_ops/mock_ns_targeter.h"
#include "mongo/stdx/memory.h"
#include "mongo/unittest/unittest.h"
diff --git a/src/mongo/s/write_ops/batch_write_op_test.cpp b/src/mongo/s/write_ops/batch_write_op_test.cpp
index 01513e0eb76..ea50d84a996 100644
--- a/src/mongo/s/write_ops/batch_write_op_test.cpp
+++ b/src/mongo/s/write_ops/batch_write_op_test.cpp
@@ -30,10 +30,10 @@
#include "mongo/base/owned_pointer_vector.h"
#include "mongo/db/operation_context_noop.h"
-#include "mongo/s/mock_ns_targeter.h"
#include "mongo/s/write_ops/batch_write_op.h"
#include "mongo/s/write_ops/batched_command_request.h"
#include "mongo/s/write_ops/batched_delete_document.h"
+#include "mongo/s/write_ops/mock_ns_targeter.h"
#include "mongo/s/write_ops/write_error_detail.h"
#include "mongo/unittest/unittest.h"
diff --git a/src/mongo/s/mock_ns_targeter.h b/src/mongo/s/write_ops/mock_ns_targeter.h
index 44bc5be18c2..44bc5be18c2 100644
--- a/src/mongo/s/mock_ns_targeter.h
+++ b/src/mongo/s/write_ops/mock_ns_targeter.h
diff --git a/src/mongo/s/write_ops/write_op_test.cpp b/src/mongo/s/write_ops/write_op_test.cpp
index 1f43d6188be..c54d4f7070a 100644
--- a/src/mongo/s/write_ops/write_op_test.cpp
+++ b/src/mongo/s/write_ops/write_op_test.cpp
@@ -31,9 +31,9 @@
#include "mongo/base/error_codes.h"
#include "mongo/base/owned_pointer_vector.h"
#include "mongo/db/operation_context_noop.h"
-#include "mongo/s/mock_ns_targeter.h"
#include "mongo/s/write_ops/batched_command_request.h"
#include "mongo/s/write_ops/batched_delete_document.h"
+#include "mongo/s/write_ops/mock_ns_targeter.h"
#include "mongo/s/write_ops/write_error_detail.h"
#include "mongo/s/write_ops/write_op.h"
#include "mongo/unittest/unittest.h"