summaryrefslogtreecommitdiff
path: root/src/mongo/s
diff options
context:
space:
mode:
authorKaloian Manassiev <kaloian.manassiev@mongodb.com>2017-12-05 13:47:54 -0500
committerKaloian Manassiev <kaloian.manassiev@mongodb.com>2017-12-06 09:04:36 -0500
commitd5be73dbe4d28211994746dc1f5b47fb840ccdbd (patch)
tree4a27750cfaad68c90671bc14ef83759e0e607a47 /src/mongo/s
parenta18859168f73428522d4338fee982329d9d431ed (diff)
downloadmongo-d5be73dbe4d28211994746dc1f5b47fb840ccdbd.tar.gz
SERVER-31056 Remove the KeyRange type from non-test code
Diffstat (limited to 'src/mongo/s')
-rw-r--r--src/mongo/s/catalog/type_chunk.h4
-rw-r--r--src/mongo/s/write_ops/mock_ns_targeter.h60
2 files changed, 51 insertions, 13 deletions
diff --git a/src/mongo/s/catalog/type_chunk.h b/src/mongo/s/catalog/type_chunk.h
index f792510c109..2852955deb6 100644
--- a/src/mongo/s/catalog/type_chunk.h
+++ b/src/mongo/s/catalog/type_chunk.h
@@ -100,8 +100,8 @@ public:
ChunkRange unionWith(ChunkRange const& other) const;
private:
- const BSONObj _minKey;
- const BSONObj _maxKey;
+ BSONObj _minKey;
+ BSONObj _maxKey;
};
/**
diff --git a/src/mongo/s/write_ops/mock_ns_targeter.h b/src/mongo/s/write_ops/mock_ns_targeter.h
index 5046c60c277..213a5abcb6a 100644
--- a/src/mongo/s/write_ops/mock_ns_targeter.h
+++ b/src/mongo/s/write_ops/mock_ns_targeter.h
@@ -32,6 +32,7 @@
#include "mongo/bson/bsonobj.h"
#include "mongo/bson/bsonobjbuilder.h"
#include "mongo/db/range_arithmetic.h"
+#include "mongo/s/catalog/type_chunk.h"
#include "mongo/s/ns_targeter.h"
#include "mongo/stdx/memory.h"
#include "mongo/unittest/unittest.h"
@@ -39,6 +40,45 @@
namespace mongo {
/**
+ * A KeyRange represents a range over keys of documents in a namespace, qualified by a
+ * key pattern which defines the documents that are in the key range.
+ *
+ * There may be many different expressions to generate the same key fields from a document - the
+ * keyPattern tells us these expressions.
+ *
+ * Ex:
+ * DocA : { field : "aaaa" }
+ * DocB : { field : "bbb" }
+ * DocC : { field : "ccccc" }
+ *
+ * keyPattern : { field : 1 }
+ * minKey : { field : "aaaa" } : Id(DocA)
+ * maxKey : { field : "ccccc" } : Id(DocB)
+ *
+ * contains Id(DocB)
+ *
+ * keyPattern : { field : "numberofletters" }
+ * minKey : { field : 4 } : numberofletters(DocA)
+ * maxKey : { field : 5 } : numberofletters(DocC)
+ *
+ * does not contain numberofletters(DocB)
+ */
+struct KeyRange {
+ KeyRange(const std::string& ns,
+ const BSONObj& minKey,
+ const BSONObj& maxKey,
+ const BSONObj& keyPattern)
+ : ns(ns), minKey(minKey), maxKey(maxKey), keyPattern(keyPattern) {}
+
+ KeyRange() {}
+
+ std::string ns;
+ BSONObj minKey;
+ BSONObj maxKey;
+ BSONObj keyPattern;
+};
+
+/**
* A MockRange represents a range with endpoint that a MockNSTargeter uses to direct writes to
* a particular endpoint.
*/
@@ -155,14 +195,12 @@ public:
}
private:
- KeyRange parseRange(const BSONObj& query) const {
- std::string fieldName = query.firstElement().fieldName();
+ ChunkRange parseRange(const BSONObj& query) const {
+ const std::string fieldName = query.firstElement().fieldName();
if (query.firstElement().isNumber()) {
- return KeyRange("",
- BSON(fieldName << query.firstElement().numberInt()),
- BSON(fieldName << query.firstElement().numberInt() + 1),
- BSON(fieldName << 1));
+ return ChunkRange(BSON(fieldName << query.firstElement().numberInt()),
+ BSON(fieldName << query.firstElement().numberInt() + 1));
} else if (query.firstElement().type() == Object) {
BSONObj queryRange = query.firstElement().Obj();
@@ -174,11 +212,11 @@ private:
BSONObjBuilder maxKeyB;
maxKeyB.appendAs(queryRange[LT.l_], fieldName);
- return KeyRange("", minKeyB.obj(), maxKeyB.obj(), BSON(fieldName << 1));
+ return ChunkRange(minKeyB.obj(), maxKeyB.obj());
}
ASSERT(false);
- return KeyRange("", BSONObj(), BSONObj(), BSONObj());
+ return ChunkRange({}, {});
}
/**
@@ -187,15 +225,15 @@ private:
*/
Status targetQuery(const BSONObj& query,
std::vector<std::unique_ptr<ShardEndpoint>>* endpoints) const {
- KeyRange queryRange = parseRange(query);
+ ChunkRange queryRange(parseRange(query));
const std::vector<MockRange*>& ranges = getRanges();
for (std::vector<MockRange*>::const_iterator it = ranges.begin(); it != ranges.end();
++it) {
const MockRange* range = *it;
- if (rangeOverlaps(queryRange.minKey,
- queryRange.maxKey,
+ if (rangeOverlaps(queryRange.getMin(),
+ queryRange.getMax(),
range->range.minKey,
range->range.maxKey)) {
endpoints->push_back(stdx::make_unique<ShardEndpoint>(range->endpoint));