summaryrefslogtreecommitdiff
path: root/src/mongo/db/keypattern.h
diff options
context:
space:
mode:
authorSiyuan Zhou <siyuan.zhou@mongodb.com>2014-04-14 19:05:49 -0400
committerSiyuan Zhou <siyuan.zhou@mongodb.com>2014-05-01 13:41:58 -0400
commit1d317f1794044fb640e7591a8b611b4374207772 (patch)
treeffd11d52fd0e7e7a03452756329498de662683c4 /src/mongo/db/keypattern.h
parent4eb9988846e1e7d49ec26facd9a2ff6b89f8cdde (diff)
downloadmongo-1d317f1794044fb640e7591a8b611b4374207772.tar.gz
SERVER-13656 Use new query framework in getShardsForQuery on mongos
Diffstat (limited to 'src/mongo/db/keypattern.h')
-rw-r--r--src/mongo/db/keypattern.h30
1 files changed, 26 insertions, 4 deletions
diff --git a/src/mongo/db/keypattern.h b/src/mongo/db/keypattern.h
index b5ba777cecd..3e99a1c9d85 100644
--- a/src/mongo/db/keypattern.h
+++ b/src/mongo/db/keypattern.h
@@ -34,6 +34,7 @@
#include "mongo/db/jsobj.h"
#include "mongo/platform/unordered_set.h"
#include "mongo/util/mongoutils/str.h"
+#include "mongo/db/query/index_bounds.h"
namespace mongo {
@@ -173,6 +174,31 @@ namespace mongo {
*/
BoundList keyBounds( const FieldRangeSet& queryConstraints ) const;
+ /**
+ * Return an ordered list of bounds generated using this KeyPattern and the
+ * bounds from the IndexBounds. This function is used in sharding to
+ * determine where to route queries according to the shard key pattern.
+ *
+ * Examples:
+ *
+ * Key { a: 1 }, Bounds a: [0] => { a: 0 } -> { a: 0 }
+ * Key { a: 1 }, Bounds a: [2, 3) => { a: 2 } -> { a: 3 } // bound inclusion ignored.
+ *
+ * The bounds returned by this function may be a superset of those defined
+ * by the constraints. For instance, if this KeyPattern is {a : 1, b: 1}
+ * Bounds: { a : {$in : [1,2]} , b : {$in : [3,4,5]} }
+ * => {a : 1 , b : 3} -> {a : 1 , b : 5}, {a : 2 , b : 3} -> {a : 2 , b : 5}
+ *
+ * If the IndexBounds are not defined for all the fields in this keypattern, which
+ * means some fields are unsatisfied, an empty BoundList could return.
+ *
+ */
+ static BoundList keyBounds( const BSONObj& keyPattern, const IndexBounds& indexBounds );
+
+ static bool isHashed( const BSONElement& fieldExpression ) {
+ return mongoutils::str::equals( fieldExpression.valuestrsafe() , "hashed" );
+ }
+
private:
BSONObj _pattern;
@@ -202,10 +228,6 @@ namespace mongo {
return ( fieldExpression.isNumber() && fieldExpression.numberInt() == -1 );
}
- bool isHashed( const BSONElement& fieldExpression ) const {
- return mongoutils::str::equals( fieldExpression.valuestrsafe() , "hashed" );
- }
-
/* Takes a list of intervals corresponding to constraints on a given field
* in this keypattern, and transforms them into a list of bounds
* based on the expression for 'field'