0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-12-01 09:32:32 +01:00

mongod chunk filtering seems to be working SERVER-943

This commit is contained in:
Eliot Horowitz 2010-06-15 23:05:45 -04:00
parent d3481595d2
commit 15aebb0706
6 changed files with 42 additions and 36 deletions

View File

@ -637,7 +637,7 @@ namespace mongo {
_nscannedObjects++;
DiskLoc cl = _c->currLoc();
if ( _chunkMatcher && ! _chunkMatcher->belongsToMe( _c->currKey(), _c->currLoc() ) ){
cout << "TEMP skipping un-owned chunk: " << _c->current() << endl;
// cout << "TEMP skipping un-owned chunk: " << _c->current() << endl;
}
else if( _c->getsetdup(cl) ) {
// dup

View File

@ -7,7 +7,7 @@ types = [
{ name : "double" , values : [ 1.2 , 3.5 , 4.5 , 4.6 , 6.7 , 9.9 ] , keyfield : "a" } ,
{ name : "date" , values : [ new Date( 1000000 ) , new Date( 2000000 ) , new Date( 3000000 ) , new Date( 4000000 ) , new Date( 5000000 ) , new Date( 6000000 ) ] , keyfield : "a" } ,
{ name : "string_id" , values : [ "allan" , "bob" , "eliot" , "joe" , "mark" , "sara" ] , keyfield : "_id" },
{ name : "embedded" , values : [ "allan" , "bob" , "eliot" , "joe" , "mark" , "sara" ] , keyfield : "a.b" } ,
{ name : "embedded 1" , values : [ "allan" , "bob" , "eliot" , "joe" , "mark" , "sara" ] , keyfield : "a.b" } ,
{ name : "embedded 2" , values : [ "allan" , "bob" , "eliot" , "joe" , "mark" , "sara" ] , keyfield : "a.b.c" } ,
{ name : "object" , values : [ {a:1, b:1.2}, {a:1, b:3.5}, {a:1, b:4.5}, {a:2, b:1.2}, {a:2, b:3.5}, {a:2, b:4.5} ] , keyfield : "o" } ,
{ name : "oid_id" , values : [ ObjectId() , ObjectId() , ObjectId() , ObjectId() , ObjectId() , ObjectId() ] , keyfield : "_id" } ,

View File

@ -315,7 +315,6 @@ namespace mongo {
shared_ptr<ChunkRange> c = *i;
BSONObj myCommand = fixCmdObj( cmdObj , c );
cout << "myCommand: " << myCommand << endl;
ShardConnection conn( c->getShard() , fullns );
BSONObj res;
bool ok = conn->runCommand( conf->getName() , myCommand , res );

View File

@ -75,7 +75,7 @@ namespace mongo {
void appendInfo( BSONObjBuilder& b );
ChunkMatcherPtr getChunkMatcher( const string& ns , bool load=false , ConfigVersion version=0 );
ChunkMatcherPtr getChunkMatcher( const string& ns );
private:

View File

@ -138,38 +138,24 @@ namespace mongo {
}
ChunkMatcherPtr ShardingState::getChunkMatcher( const string& ns , bool load , ConfigVersion version ){
return ChunkMatcherPtr();// ERH ERH ERH
ChunkMatcherPtr ShardingState::getChunkMatcher( const string& ns ){
if ( ! _enabled )
return ChunkMatcherPtr();
if ( ! ShardedConnectionInfo::get( false ) )
return ChunkMatcherPtr();
ConfigVersion version;
{
scoped_lock lk( _mutex );
if ( ! version )
version = _versions[ns];
version = _versions[ns];
if ( ! version )
return ChunkMatcherPtr();
ChunkMatcherPtr p = _chunks[ns];
if ( p ){
if ( ! load )
return p;
if ( p->_version >= version )
return p;
}
else {
if ( ! load ){
stringstream ss;
ss << "getChunkMatcher called with load false for ns: " << ns;
msgasserted( 13300 , ss.str() );
}
}
if ( p && p->_version >= version )
return p;
}
BSONObj q;
@ -179,12 +165,25 @@ namespace mongo {
b.append( "shard" , BSON( "$in" << BSON_ARRAY( _shardHost << _shardName ) ) );
q = b.obj();
}
auto_ptr<ScopedDbConnection> scoped;
auto_ptr<DBDirectClient> direct;
ScopedDbConnection conn( _configServer );
DBClientBase * conn;
if ( _configServer == _shardHost ){
direct.reset( new DBDirectClient() );
conn = direct.get();
}
else {
scoped.reset( new ScopedDbConnection( _configServer ) );
conn = scoped->get();
}
auto_ptr<DBClientCursor> cursor = conn->query( "config.chunks" , Query(q).sort( "min" ) );
if ( ! cursor->more() ){
conn.done();
if ( scoped.get() )
scoped->done();
return ChunkMatcherPtr();
}
@ -212,7 +211,8 @@ namespace mongo {
assert( ! min.isEmpty() );
p->gotRange( min.getOwned() , max.getOwned() );
conn.done();
if ( scoped.get() )
scoped->done();
{
scoped_lock lk( _mutex );
@ -420,7 +420,7 @@ namespace mongo {
{
dbtemprelease unlock;
shardingState.getChunkMatcher( ns , true , version );
shardingState.getChunkMatcher( ns );
}
result.appendTimestamp( "oldVersion" , oldVersion );
@ -534,17 +534,24 @@ namespace mongo {
}
bool ChunkMatcher::belongsToMe( const BSONObj& key , const DiskLoc& loc ) const {
return true; // ERH ERH ERH
if ( _map.size() == 0 )
return false;
BSONObj x = loc.obj().getFieldDotted( _field.c_str() ).wrap(); // TODO: this is slow
BSONObj x = loc.obj().getFieldDotted( _field.c_str() ).wrap( _field.c_str() ); // TODO: this is slow
MyMap::const_iterator a = _map.upper_bound( x );
if ( a == _map.end() )
a--;
a--;
return x.woCompare( a->second.first ) >= 0 && x.woCompare( a->second.second ) < 0;
bool good = x.woCompare( a->second.first ) >= 0 && x.woCompare( a->second.second ) < 0;
#if 0
if ( ! good ){
cout << "bad: " << x << "\t" << a->second.first << "\t" << x.woCompare( a->second.first ) << "\t" << x.woCompare( a->second.second ) << endl;
for ( MyMap::const_iterator i=_map.begin(); i!=_map.end(); ++i ){
cout << "\t" << i->first << "\t" << i->second.first << "\t" << i->second.second << endl;
}
}
#endif
return good;
}
}

View File

@ -50,8 +50,8 @@ namespace mongo {
set<ServerAndQuery> servers;
for ( vector<shared_ptr<ChunkRange> >::iterator i = shards.begin(); i != shards.end(); i++ ){
shared_ptr<ChunkRange> c = *i;
//servers.insert( ServerAndQuery( c->getShard().getConnString() , BSONObj() ) ); // ERH ERH ERH
servers.insert( ServerAndQuery( c->getShard().getConnString() , c->getFilter() ) );
servers.insert( ServerAndQuery( c->getShard().getConnString() , BSONObj() ) );
//servers.insert( ServerAndQuery( c->getShard().getConnString() , c->getFilter() ) ); // this is what does mongod size filtering, TODO: clean up apis
}
if ( logLevel > 4 ){