diff options
author | Greg Studer <greg@10gen.com> | 2014-08-29 12:59:13 -0400 |
---|---|---|
committer | Greg Studer <greg@10gen.com> | 2014-09-03 12:13:12 -0400 |
commit | a39b938918e09bda67ea9e516101f43b9ef25a51 (patch) | |
tree | 269b9d0fa3986d175dc70c2f05893673faa00006 | |
parent | 5d05a2b0767f2f6122ee509678e0df3fa36f94a7 (diff) | |
download | mongo-a39b938918e09bda67ea9e516101f43b9ef25a51.tar.gz |
SERVER-5022 cleanup keypattern.h and shardkey.h, remove dead code
-rw-r--r-- | src/mongo/db/exec/filter.h | 1 | ||||
-rw-r--r-- | src/mongo/db/exec/shard_filter.cpp | 3 | ||||
-rw-r--r-- | src/mongo/db/keypattern.cpp | 49 | ||||
-rw-r--r-- | src/mongo/db/keypattern.h | 67 | ||||
-rw-r--r-- | src/mongo/dbtests/keypatterntests.cpp | 156 | ||||
-rw-r--r-- | src/mongo/s/chunk.cpp | 13 | ||||
-rw-r--r-- | src/mongo/s/chunk_manager_targeter_test.cpp | 10 | ||||
-rw-r--r-- | src/mongo/s/shardkey.cpp | 124 | ||||
-rw-r--r-- | src/mongo/s/shardkey.h | 30 |
9 files changed, 26 insertions, 427 deletions
diff --git a/src/mongo/db/exec/filter.h b/src/mongo/db/exec/filter.h index 964f5d7f6f7..23970976e35 100644 --- a/src/mongo/db/exec/filter.h +++ b/src/mongo/db/exec/filter.h @@ -29,6 +29,7 @@ #pragma once #include "mongo/db/exec/working_set.h" +#include "mongo/db/matcher/expression.h" #include "mongo/db/matcher/matchable.h" namespace mongo { diff --git a/src/mongo/db/exec/shard_filter.cpp b/src/mongo/db/exec/shard_filter.cpp index 8d889098b2d..009cec15dd9 100644 --- a/src/mongo/db/exec/shard_filter.cpp +++ b/src/mongo/db/exec/shard_filter.cpp @@ -28,10 +28,9 @@ #include "mongo/db/exec/shard_filter.h" -#include "mongo/db/keypattern.h" -#include "mongo/db/matcher/expression.h" #include "mongo/db/exec/filter.h" #include "mongo/db/exec/working_set_common.h" +#include "mongo/db/keypattern.h" #include "mongo/util/log.h" namespace mongo { diff --git a/src/mongo/db/keypattern.cpp b/src/mongo/db/keypattern.cpp index 18a0d270a7f..e0476f94358 100644 --- a/src/mongo/db/keypattern.cpp +++ b/src/mongo/db/keypattern.cpp @@ -31,25 +31,12 @@ #include "mongo/db/keypattern.h" #include "mongo/db/hasher.h" +#include "mongo/db/index_names.h" #include "mongo/util/mongoutils/str.h" -using namespace mongoutils; - namespace mongo { - KeyPattern::KeyPattern( const BSONObj& pattern ): _pattern( pattern ) { - - // Extract all prefixes of each field in pattern. - BSONForEach( field, _pattern ) { - StringData fieldName = field.fieldName(); - size_t pos = fieldName.find( '.' ); - while ( pos != string::npos ) { - _prefixes.insert( StringData( field.fieldName(), pos ) ); - pos = fieldName.find( '.', pos+1 ); - } - _prefixes.insert( fieldName ); - } - } + KeyPattern::KeyPattern( const BSONObj& pattern ): _pattern( pattern ) {} bool KeyPattern::isIdKeyPattern(const BSONObj& pattern) { BSONObjIterator i(pattern); @@ -63,6 +50,7 @@ namespace mongo { } BSONObj KeyPattern::extractShardKeyFromQuery(const BSONObj& query) const { + if (_pattern.isEmpty()) return BSONObj(); @@ -75,6 +63,10 @@ namespace mongo { return query.extractFields(_pattern); } + bool KeyPattern::isOrderedKeyPattern(const BSONObj& pattern) { + return IndexNames::BTREE == IndexNames::findPluginName(pattern); + } + BSONObj KeyPattern::extractShardKeyFromDoc(const BSONObj& doc) const { BSONMatchableDocument matchable(doc); return extractShardKeyFromMatchable(matchable); @@ -117,31 +109,6 @@ namespace mongo { return keyBuilder.obj(); } - - bool KeyPattern::isSpecial() const { - BSONForEach(e, _pattern) { - int fieldVal = e.numberInt(); - if ( fieldVal != 1 && fieldVal != -1 ){ - return true; - } - } - return false; - } - - bool KeyPattern::isCoveredBy( const KeyPattern& other ) const { - BSONForEach( e, _pattern ) { - BSONElement otherfield = other.getField( e.fieldName() ); - if ( otherfield.eoo() ){ - return false; - } - - if ( otherfield.numberInt() != 1 && otherfield.numberInt() != -1 && otherfield != e ){ - return false; - } - } - return true; - } - BSONObj KeyPattern::extendRangeBound( const BSONObj& bound , bool makeUpperInclusive ) const { BSONObjBuilder newBound( bound.objsize() ); @@ -177,7 +144,7 @@ namespace mongo { return newBound.obj(); } - BoundList KeyPattern::keyBounds( const BSONObj& keyPattern, const IndexBounds& indexBounds ) { + BoundList KeyPattern::flattenBounds( const BSONObj& keyPattern, const IndexBounds& indexBounds ) { invariant(indexBounds.fields.size() == (size_t)keyPattern.nFields()); // If any field is unsatisfied, return empty bound list. diff --git a/src/mongo/db/keypattern.h b/src/mongo/db/keypattern.h index c4c8e849fd1..77e30b883d2 100644 --- a/src/mongo/db/keypattern.h +++ b/src/mongo/db/keypattern.h @@ -73,26 +73,17 @@ namespace mongo { */ BSONObj toBSON() const { return _pattern; } - /* - * Returns true if the given fieldname is the (dotted prefix of the) name of one - * element of the (potentially) compound key described by this KeyPattern. - */ - bool hasField( const StringData& fieldname ) const { - return _prefixes.find( fieldname ) != _prefixes.end(); - } - - /* - * Gets the element of this pattern corresponding to the given fieldname. - * Returns eoo if none exists. - */ - BSONElement getField( const char* fieldname ) const { return _pattern[ fieldname ]; } - /** * Is the provided key pattern the index over the ID field? * The always required ID index is always {_id: 1} or {_id: -1}. */ static bool isIdKeyPattern(const BSONObj& pattern); + /** + * Is the provided key pattern ordered increasing or decreasing or not? + */ + static bool isOrderedKeyPattern(const BSONObj& pattern); + /* Takes a BSONObj whose field names are a prefix of the fields in this keyPattern, and * outputs a new bound with MinKey values appended to match the fields in this keyPattern * (or MaxKey values for descending -1 fields). This is useful in sharding for @@ -118,21 +109,6 @@ namespace mongo { */ BSONObj extendRangeBound( const BSONObj& bound , bool makeUpperInclusive ) const; - /** - * Returns true if this KeyPattern contains any computed values, (e.g. {a : "hashed"}), - * and false if this KeyPattern consists of only ascending/descending fields - * (e.g. {a : 1, b : -1}). With our current index expression language, "special" patterns - * are any patterns that are not a simple list of field names and 1/-1 values. - */ - bool isSpecial() const; - - /** - * Returns true if the quantities stored in this KeyPattern can be used to compute all the - * quantities in "other". Useful for determining whether an index based on one KeyPattern - * can be used as a covered index for a query based on another. - */ - bool isCoveredBy( const KeyPattern& other ) const; - std::string toString() const{ return toBSON().toString(); } /** @@ -192,41 +168,10 @@ namespace mongo { * 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" ); - } + static BoundList flattenBounds( const BSONObj& keyPattern, const IndexBounds& indexBounds ); private: BSONObj _pattern; - - // Each field in the '_pattern' may be itself a dotted field. We store all the prefixes - // of each field here. For instance, if a pattern is { 'a.b.c': 1, x: 1 }, we'll store - // here 'a', 'a.b', 'a.b.c', and 'x'. - // - // Since we're indexing into '_pattern's field names, it must stay constant after - // constructed. - struct PrefixHasher { - size_t operator()( const StringData& strData ) const { - size_t result = 0; - const char* p = strData.rawData(); - for (size_t len = strData.size(); len > 0; len-- ) { - result = ( result * 131 ) + *p++; - } - return result; - } - }; - unordered_set<StringData, PrefixHasher> _prefixes; - - bool isAscending( const BSONElement& fieldExpression ) const { - return ( fieldExpression.isNumber() && fieldExpression.numberInt() == 1 ); - } - - bool isDescending( const BSONElement& fieldExpression ) const { - return ( fieldExpression.isNumber() && fieldExpression.numberInt() == -1 ); - } - }; } // namespace mongo diff --git a/src/mongo/dbtests/keypatterntests.cpp b/src/mongo/dbtests/keypatterntests.cpp index 17bd419cbd1..b4a96cd3a1e 100644 --- a/src/mongo/dbtests/keypatterntests.cpp +++ b/src/mongo/dbtests/keypatterntests.cpp @@ -107,161 +107,6 @@ namespace KeyPatternTests { } }; - class HasFieldTests { - public: - void run() { - // TEST(HasField, SameKey) - { - KeyPattern keyPat( BSON( "x" << 1 ) ); - ASSERT_TRUE( keyPat.hasField( "x" ) ); - } - - // TEST( HasField, DifferentKey ) - { - KeyPattern keyPat( BSON( "x" << 1 ) ); - ASSERT_FALSE( keyPat.hasField( "y" ) ); - } - - // TEST( HasField, SameKey2Levels ) - { - KeyPattern keyPat( BSON( "x.y" << 1 ) ); - ASSERT_TRUE( keyPat.hasField( "x.y" ) ); - } - - // TEST( HasField, SameKeyPartial ) - { - KeyPattern keyPat( BSON( "xyz.a" << 1 ) ); - ASSERT_TRUE( keyPat.hasField( "xyz" ) ); - } - - // TEST( HasField, DifferentChildKey ) - { - KeyPattern keyPat( BSON( "x.y" << 1 ) ); - ASSERT_FALSE( keyPat.hasField( "x.b" ) ); - } - - // TEST( HasField, DifferentRootKeyDotted ) - { - KeyPattern keyPat( BSON( "x.y" << 1 ) ); - ASSERT_FALSE( keyPat.hasField( "a.y" ) ); - } - - // TEST( HasField, SameRootKeyPartial ) - { - KeyPattern keyPat( BSON( "x.y" << 1 ) ); - ASSERT_TRUE( keyPat.hasField( "x" ) ); - } - - // TEST( HasField, DifferentRootKeyPartial ) - { - KeyPattern keyPat( BSON( "x.y" << 1 ) ); - ASSERT_FALSE( keyPat.hasField( "a" ) ); - } - - // TEST( HasField, DifferentMatchingChildKey ) - { - KeyPattern keyPat( BSON( "x.y" << 1 ) ); - ASSERT_FALSE( keyPat.hasField( "y" ) ); - } - - // TEST( HasField, SameKey3Level ) - { - KeyPattern keyPat( BSON( "x.y.z" << 1 ) ); - ASSERT_TRUE( keyPat.hasField( "x.y.z" ) ); - } - - // TEST( HasField, Same3LevelKeyPartialUpto1 ) - { - KeyPattern keyPat( BSON( "x.y.z" << 1 ) ); - ASSERT_TRUE( keyPat.hasField( "x" ) ); - } - - // TEST( HasField, Same3LevelKeyPartialUpto2 ) - { - KeyPattern keyPat( BSON( "x.y.z" << 1 ) ); - ASSERT_TRUE( keyPat.hasField( "x.y" ) ); - } - - // TEST( HasField, DifferentDottedRoot3Level ) - { - KeyPattern keyPat( BSON( "x.y.z" << 1 ) ); - ASSERT_FALSE( keyPat.hasField( "x.b" ) ); - } - - // TEST( HasField, DifferentRoot3Levels ) - { - KeyPattern keyPat( BSON( "x.y.z" << 1 ) ); - ASSERT_FALSE( keyPat.hasField( "a" ) ); - } - - // TEST( HasField, SameCompoundHasField ) - { - KeyPattern keyPat( BSON( "x" << 1 << "y" << -1 ) ); - ASSERT_TRUE( keyPat.hasField( "y" ) ); - } - - // TEST( HasField, SameDottedCompoundHasField ) - { - KeyPattern keyPat( BSON( "x.y" << 1 << "a.b" << -1 ) ); - ASSERT_TRUE( keyPat.hasField( "a.b" ) ); - } - - // TEST( HasField, Same3LevelEmbeddedCompoundHasField ) - { - KeyPattern keyPat( BSON( "x.y" << 1 << "a.b.c" << -1 ) ); - ASSERT_TRUE( keyPat.hasField( "a" ) ); - } - - // TEST( HasField, DifferentCompoundHasField ) - { - KeyPattern keyPat( BSON( "x" << 1 << "y" << -1 ) ); - ASSERT_FALSE( keyPat.hasField( "z" ) ); - } - - // TEST( HasField, DifferentDottedCompoundHasField ) - { - KeyPattern keyPat( BSON( "x.y" << 1 << "a.b" << -1 ) ); - ASSERT_FALSE( keyPat.hasField( "a.j" ) ); - } - - // TEST( HasField, SameRootLongerObjKey ) - { - KeyPattern keyPat( BSON( "x" << 1 ) ); - ASSERT_FALSE( keyPat.hasField( "x.y.z" ) ); - } - - // TEST( HasField, DifferentRootLongerObjKey ) - { - KeyPattern keyPat( BSON( "x" << 1 ) ); - ASSERT_FALSE( keyPat.hasField( "a.b.c" ) ); - } - - // TEST( HasField, DifferentRootPrefixObjKey ) - { - KeyPattern keyPat( BSON( "xyz.a" << 1 ) ); - ASSERT_FALSE( keyPat.hasField( "xy" ) ); - } - - // TEST( HasField, DifferentRootPrefixHasField ) - { - KeyPattern keyPat( BSON( "xyz" << 1 ) ); - ASSERT_FALSE( keyPat.hasField( "xyzabc" ) ); - } - - // TEST( HasField, DifferentRootPartialPrefixObjKey ) - { - KeyPattern keyPat( BSON( "xyz" << 1 ) ); - ASSERT_FALSE( keyPat.hasField( "xy.z" ) ); - } - - // TEST( HasField, DifferentRootPartialPrefixHasField ) - { - KeyPattern keyPat( BSON( "xy.z" << 1 ) ); - ASSERT_FALSE( keyPat.hasField( "xyz" ) ); - } - } - }; - class All : public Suite { public: All() : Suite( "keypattern" ) { @@ -269,7 +114,6 @@ namespace KeyPatternTests { void setupTests() { add< ExtendRangeBoundTests >(); - add< HasFieldTests >(); } } myall; diff --git a/src/mongo/s/chunk.cpp b/src/mongo/s/chunk.cpp index 46afd515eea..a9ffd904d89 100644 --- a/src/mongo/s/chunk.cpp +++ b/src/mongo/s/chunk.cpp @@ -38,6 +38,7 @@ #include "mongo/client/connpool.h" #include "mongo/client/dbclientcursor.h" #include "mongo/db/query/lite_parsed_query.h" +#include "mongo/db/index_names.h" #include "mongo/db/lasterror.h" #include "mongo/db/write_concern.h" #include "mongo/platform/random.h" @@ -328,9 +329,7 @@ namespace mongo { // the very first (or last) key as a split point. // This heuristic is skipped for "special" shard key patterns that are not likely to // produce monotonically increasing or decreasing values (e.g. hashed shard keys). - // TODO: need better way to detect when shard keys vals are increasing/decreasing, and - // use that better method to determine whether to apply heuristic here. - if ( ! skey().isSpecial() ){ + if (KeyPattern::isOrderedKeyPattern(skey().key())) { if ( minIsInf() ) { BSONObj key = _getExtremeKey( 1 ); if ( ! key.isEmpty() ) { @@ -1272,7 +1271,7 @@ namespace mongo { // Key { a : 1, b : 1 } // Bounds { a : [1, 2), b : [3, 4) } // => Ranges { a : 1, b : 3 } => { a : 2, b : 4 } - BoundList ranges = KeyPattern::keyBounds(_key.key(), bounds); + BoundList ranges = KeyPattern::flattenBounds(_key.key(), bounds); for ( BoundList::const_iterator it=ranges.begin(); it != ranges.end(); ++it ){ getShardsForRange( shards, it->first /*min*/, it->second /*max*/ ); @@ -1325,10 +1324,8 @@ namespace mongo { } // Consider shard key as an index - string accessMethod = IndexNames::BTREE; - if (KeyPattern::isHashed(key.firstElement())) { - accessMethod = IndexNames::HASHED; - } + string accessMethod = IndexNames::findPluginName(key); + dassert(accessMethod == IndexNames::BTREE || accessMethod == IndexNames::HASHED); // Use query framework to generate index bounds QueryPlannerParams plannerParams; diff --git a/src/mongo/s/chunk_manager_targeter_test.cpp b/src/mongo/s/chunk_manager_targeter_test.cpp index 00fc22d1ae7..f47466f4b18 100644 --- a/src/mongo/s/chunk_manager_targeter_test.cpp +++ b/src/mongo/s/chunk_manager_targeter_test.cpp @@ -410,7 +410,7 @@ namespace { BoundList expectedList; expectedList.push_back(make_pair(fromjson("{a: 0}"), fromjson("{a: 0}"))); - BoundList list = KeyPattern::keyBounds(fromjson("{a: 1}"), indexBounds); + BoundList list = KeyPattern::flattenBounds(fromjson("{a: 1}"), indexBounds); CheckBoundList(list, expectedList); } @@ -425,7 +425,7 @@ namespace { BoundList expectedList; expectedList.push_back(make_pair(fromjson("{a: 2}"), fromjson("{a: 3}"))); - BoundList list = KeyPattern::keyBounds(fromjson("{a: 1}"), indexBounds); + BoundList list = KeyPattern::flattenBounds(fromjson("{a: 1}"), indexBounds); CheckBoundList(list, expectedList); } @@ -448,7 +448,7 @@ namespace { fromjson("{ a: 2, b: 2, c: 2 }"), fromjson("{ a: 3, b: 3, c: 3 }"))); - BoundList list = KeyPattern::keyBounds(fromjson("{a: 1, b: 1, c: 1}"), indexBounds); + BoundList list = KeyPattern::flattenBounds(fromjson("{a: 1, b: 1, c: 1}"), indexBounds); CheckBoundList(list, expectedList); } @@ -486,7 +486,7 @@ namespace { fromjson("{ a: 0, b: 6, c: 2 }"), fromjson("{ a: 0, b: 6, c: 3 }"))); - BoundList list = KeyPattern::keyBounds(fromjson("{a: 1, b: 1, c: 1}"), indexBounds); + BoundList list = KeyPattern::flattenBounds(fromjson("{a: 1, b: 1, c: 1}"), indexBounds); CheckBoundList(list, expectedList); } @@ -516,7 +516,7 @@ namespace { expectedList.push_back(make_pair( fromjson("{ a: 0, b: 4, c: 2 }"), fromjson("{ a: 1, b: 6, c: 3 }"))); - BoundList list = KeyPattern::keyBounds(fromjson("{a: 1, b: 1, c: 1}"), indexBounds); + BoundList list = KeyPattern::flattenBounds(fromjson("{a: 1, b: 1, c: 1}"), indexBounds); CheckBoundList(list, expectedList); } diff --git a/src/mongo/s/shardkey.cpp b/src/mongo/s/shardkey.cpp index 30a92a66d75..6c70878cdd9 100644 --- a/src/mongo/s/shardkey.cpp +++ b/src/mongo/s/shardkey.cpp @@ -97,69 +97,6 @@ namespace mongo { return pattern.toString(); } - BSONObj ShardKeyPattern::moveToFront(const BSONObj& obj) const { - vector<const char*> keysToMove; - keysToMove.push_back("_id"); - BSONForEach(e, pattern.toBSON()) { - if (strchr(e.fieldName(), '.') == NULL && strcmp(e.fieldName(), "_id") != 0) - keysToMove.push_back(e.fieldName()); - } - - if (keysToMove.size() == 1) { - return obj; - - } - else { - BufBuilder buf (sizeof(BSONObj::Holder) + obj.objsize()); - buf.skip(sizeof(BSONObj::Holder)); - buf.appendNum(obj.objsize()); - - vector<pair<const char*, size_t> > copies; - pair<const char*, size_t> toCopy ((const char*)NULL, 0); // C++ NULL isn't a pointer type yet - - BSONForEach(e, obj) { - bool moveToFront = false; - for (vector<const char*>::const_iterator it(keysToMove.begin()), end(keysToMove.end()); it!=end; ++it) { - if (strcmp(e.fieldName(), *it) == 0) { - moveToFront = true; - break; - } - } - - if (moveToFront) { - buf.appendBuf(e.fieldName()-1, e.size()); - if (toCopy.first) { - copies.push_back(toCopy); - toCopy.first = NULL; - } - } - else { - if (!toCopy.first) { - toCopy.first = e.fieldName()-1; - toCopy.second = e.size(); - } - else { - toCopy.second += e.size(); - } - } - } - - for (vector<pair<const char*, size_t> >::const_iterator it(copies.begin()), end(copies.end()); it!=end; ++it) { - buf.appendBuf(it->first, it->second); - } - - if (toCopy.first) { - buf.appendBuf(toCopy.first, toCopy.second); - } - - buf.appendChar('\0'); - - char* const bufData = buf.buf(); - buf.decouple(); - return BSONObj::takeOwnership(bufData); - } - } - /* things to test for compound : \ middle (deprecating?) */ @@ -221,36 +158,6 @@ namespace mongo { verify( k.extractKeyFromQueryOrDoc( fromjson("{sub:{b:2,c:3},a:1}") ).binaryEqual(x) ); } - void isSpecialTest() { - ShardKeyPattern k1( BSON( "a" << 1) ); - verify( ! k1.isSpecial() ); - - ShardKeyPattern k2( BSON( "a" << -1 << "b" << 1 ) ); - verify( ! k2.isSpecial() ); - - ShardKeyPattern k3( BSON( "a" << "hashed") ); - verify( k3.isSpecial() ); - - ShardKeyPattern k4( BSON( "a" << 1 << "b" << "hashed") ); - verify( k4.isSpecial() ); - } - - void moveToFrontTest() { - ShardKeyPattern sk (BSON("a" << 1 << "b" << 1)); - - BSONObj ret; - - ret = sk.moveToFront(BSON("z" << 1 << "_id" << 1 << "y" << 1 << "a" << 1 << "x" << 1 << "b" << 1 << "w" << 1)); - verify(ret.binaryEqual(BSON("_id" << 1 << "a" << 1 << "b" << 1 << "z" << 1 << "y" << 1 << "x" << 1 << "w" << 1))); - - ret = sk.moveToFront(BSON("_id" << 1 << "a" << 1 << "b" << 1 << "z" << 1 << "y" << 1 << "x" << 1 << "w" << 1)); - verify(ret.binaryEqual(BSON("_id" << 1 << "a" << 1 << "b" << 1 << "z" << 1 << "y" << 1 << "x" << 1 << "w" << 1))); - - ret = sk.moveToFront(BSON("z" << 1 << "y" << 1 << "a" << 1 << "b" << 1 << "Z" << 1 << "Y" << 1)); - verify(ret.binaryEqual(BSON("a" << 1 << "b" << 1 << "z" << 1 << "y" << 1 << "Z" << 1 << "Y" << 1))); - - } - void uniqueIndexCompatibleTest() { ShardKeyPattern k1( BSON( "a" << 1 ) ); verify( k1.isUniqueIndexCompatible( BSON( "_id" << 1 ) ) ); @@ -263,27 +170,6 @@ namespace mongo { verify( ! k2.isUniqueIndexCompatible( BSON( "b" << 1 ) ) ); } - void moveToFrontBenchmark(int numFields) { - BSONObjBuilder bb; - bb.append("_id", 1); - for (int i=0; i < numFields; i++) - bb.append(BSONObjBuilder::numStr(i), 1); - bb.append("key", 1); - BSONObj o = bb.obj(); - - ShardKeyPattern sk (BSON("key" << 1)); - - Timer t; - const int iterations = 100*1000; - for (int i=0; i< iterations; i++) { - sk.moveToFront(o); - } - - const double secs = t.micros() / 1000000.0; - const double ops_per_sec = iterations / secs; - - cout << "moveToFront (" << numFields << " fields) secs: " << secs << " ops_per_sec: " << ops_per_sec << endl; - } void run() { extractkeytest(); @@ -310,20 +196,10 @@ namespace mongo { verify( k.extractKeyFromQueryOrDoc( a ) < k.extractKeyFromQueryOrDoc( b ) ); - isSpecialTest(); - // add middle multitype tests - moveToFrontTest(); - uniqueIndexCompatibleTest(); - if (0) { // toggle to run benchmark - moveToFrontBenchmark(0); - moveToFrontBenchmark(10); - moveToFrontBenchmark(100); - } - LOG(1) << "shardKeyTest passed" << endl; } } shardKeyTest; diff --git a/src/mongo/s/shardkey.h b/src/mongo/s/shardkey.h index bfbaf532fa8..a9f8eb2925c 100644 --- a/src/mongo/s/shardkey.h +++ b/src/mongo/s/shardkey.h @@ -63,18 +63,6 @@ namespace mongo { */ BSONObj globalMax() const { return gMax; } - bool isGlobalMin( const BSONObj& k ) const { - return k.woCompare( globalMin() ) == 0; - } - - bool isGlobalMax( const BSONObj& k ) const { - return k.woCompare( globalMax() ) == 0; - } - - bool isGlobal( const BSONObj& k ) const { - return isGlobalMin( k ) || isGlobalMax( k ); - } - /** @return whether or not obj has all fields in this shard key pattern e.g. @@ -106,10 +94,6 @@ namespace mongo { */ BSONObj extractKeyFromQueryOrDoc(const BSONObj& from) const; - bool partOfShardKey(const StringData& key ) const { - return pattern.hasField(key); - } - BSONObj extendRangeBound( const BSONObj& bound , bool makeUpperInclusive ) const { return pattern.extendRangeBound( bound , makeUpperInclusive ); } @@ -137,20 +121,6 @@ namespace mongo { */ bool isUniqueIndexCompatible( const KeyPattern& uniqueIndexPattern ) const; - /** - * @return - * true if keyPattern contains any computed values, (e.g. {a : "hashed"}) - * false if keyPattern consists of only ascending/descending fields (e.g. {a : 1, b : -1}) - * With our current index expression language, "special" shard keys are any keys - * that are not a simple list of field names and 1/-1 values. - */ - bool isSpecial() const { return pattern.isSpecial(); } - - /** - * @return BSONObj with _id and shardkey at front. May return original object. - */ - BSONObj moveToFront(const BSONObj& obj) const; - private: KeyPattern pattern; BSONObj gMin; |