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

Merge branch 'master' of git@github.com:mongodb/mongo

This commit is contained in:
Aaron 2009-02-23 17:55:26 -05:00
commit 6bf2c76169
5 changed files with 100 additions and 8 deletions

View File

@ -25,6 +25,7 @@ db.foo.save( { num : -1 , name : "joe" } );
s.adminCommand( "connpoolsync" );
assert.eq( 3 , s.getServer( "test" ).getDB( "test" ).foo.find().length() , "not right directly to db A" );
assert.eq( 3 , db.foo.find().length() );
primary = s.getServer( "test" ).getDB( "test" );
seconday = s.getOther( primary ).getDB( "test" );
@ -66,11 +67,12 @@ s.adminCommand( "connpoolsync" );
assert.eq( 2 , primary.foo.find().length() , "boundary A" );
assert.eq( 4 , seconday.foo.find().length() , "boundary B" );
// TODO: findOne
// findOne
assert.eq( "eliot" , db.foo.findOne( { num : 1 } ).name );
assert.eq( "funny man" , db.foo.findOne( { num : -2 } ).name );
// TODO: getAll
//assert.eq( 3 , db.foo.find().length() );
// TODO: sort by num

View File

@ -24,7 +24,7 @@ namespace mongo {
class Shard;
/**
NOTE: the implementation for this is tempoary.
it only currently works for a single numeric field
@ -34,22 +34,47 @@ namespace mongo {
ShardKey( BSONObj fieldsAndOrder = emptyObj );
void init( BSONObj fieldsAndOrder );
virtual ~ShardKey() {}
/**
global min is the lowest possible value for this key
*/
void globalMin( BSONObjBuilder & b );
BSONObj globalMin(){ BSONObjBuilder b; globalMin( b ); return b.obj(); }
/**
global max is the lowest possible value for this key
*/
void globalMax( BSONObjBuilder & b );
BSONObj globalMax(){ BSONObjBuilder b; globalMax( b ); return b.obj(); }
/**
return the key inbetween min and max
note: min and max could cross type boundaries
*/
void middle( BSONObjBuilder & b , BSONObj & min , BSONObj & max );
BSONObj middle( BSONObj & min , BSONObj & max ){ BSONObjBuilder b; middle( b , min , max ); return b.obj(); }
/**
l < r negative
l == r 0
l > r positive
*/
int compare( const BSONObj& l , const BSONObj& r ) const;
/**
* @return whether or not obj has all fields in this shard key
*/
bool hasShardKey( const BSONObj& obj );
/**
returns a filter relevant that returns results only for that range
*/
void getFilter( BSONObjBuilder& b , const BSONObj& min, const BSONObj& max );
/**
@return whether or not shard should be looked at for query
*/
bool relevantForQuery( const BSONObj& query , Shard * shard );
BSONObj& key(){

View File

@ -19,6 +19,17 @@ namespace mongo {
void insert( string server , const char * ns , const BSONObj& obj );
};
class ShardedCursor {
public:
ShardedCursor(){}
virtual ~ShardedCursor(){}
virtual void sendNextBatch( Request& r ) = 0;
private:
long long _id;
};
extern Strategy * SINGLE;
extern Strategy * SHARDED;

View File

@ -7,7 +7,41 @@
#include "../db/commands.h"
namespace mongo {
class DownstreamServerState {
public:
DownstreamServerState( string name ) : _name( name ) , _used(0){
}
string _name;
bool _used;
long long _cursor;
};
class SerialServerShardedCursor : public ShardedCursor {
public:
SerialServerShardedCursor( set<string> servers , string ns , const BSONObj& q ){
for ( set<string>::iterator i = servers.begin(); i!=servers.end(); i++ )
_servers.push_back( DownstreamServerState( *i ) );
_serverIndex = 0;
_ns = ns;
_query = q.copy();
}
virtual void sendNextBatch( Request& r ){
throw UserException( "SerialServerShardedCursor doesn't work yet" );
}
private:
vector<DownstreamServerState> _servers;
int _serverIndex;
string _ns;
BSONObj _query;
};
class ShardStrategy : public Strategy {
virtual void queryOp( Request& r ){
@ -24,13 +58,33 @@ namespace mongo {
Query query( q.query );
vector<Shard*> shards;
if ( info->getShardsForQuery( shards , query.getFilter() ) == 1 ){
doQuery( r , shards[0]->getServer() );
info->getShardsForQuery( shards , query.getFilter() );
set<string> servers;
for ( vector<Shard*>::iterator i = shards.begin(); i != shards.end(); i++ ){
servers.insert( (*i)->getServer() );
}
if ( servers.size() == 1 ){
doQuery( r , *(servers.begin()) );
return;
}
SerialServerShardedCursor * cursor = 0;
if ( query.getSort().isEmpty() ){
// 1. no sort, can just hit them in serial
cursor = new SerialServerShardedCursor( servers , q.ns , q.query );
}
else {
// 2. sort on shard key, can do in serial intelligently
// 3. sort on non-sharded key, pull back a portion from each server and iterate slowly
throw UserException( "sorting and sharding doesn't work yet" );
}
throw UserException( "real sharding doesn't nwork" );
assert( cursor );
cursor->sendNextBatch( r );
}
virtual void getMore( Request& r ){

View File

@ -324,7 +324,7 @@ Handle<Value> mongoFind(const Arguments& args){
return c;
}
catch ( ... ){
return v8::ThrowException( v8::String::New( "socket error on insert" ) );
return v8::ThrowException( v8::String::New( "socket error on query" ) );
}
}