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

removing duplicate logic

This commit is contained in:
Eliot Horowitz 2010-04-14 13:57:51 -04:00
parent 8bed26cdf8
commit b0eb9fff83
2 changed files with 17 additions and 36 deletions

View File

@ -140,10 +140,16 @@ namespace mongo {
_advance();
return ret;
}
BSONObj FilteringClientCursor::peek(){
if ( _next.isEmpty() )
_advance();
return _next;
}
void FilteringClientCursor::_advance(){
assert( _next.isEmpty() );
if ( ! _cursor.get() )
if ( ! _cursor.get() || _done )
return;
while ( _cursor->more() ){
@ -215,7 +221,6 @@ namespace mongo {
void ParallelSortClusteredCursor::_init(){
_numServers = _servers.size();
_cursors = new FilteringClientCursor[_numServers];
_nexts = new BSONObj[_numServers];
// TODO: parellize
int num = 0;
@ -228,14 +233,10 @@ namespace mongo {
ParallelSortClusteredCursor::~ParallelSortClusteredCursor(){
delete [] _cursors;
delete [] _nexts;
}
bool ParallelSortClusteredCursor::more(){
for ( int i=0; i<_numServers; i++ ){
if ( ! _nexts[i].isEmpty() )
return true;
if ( _cursors[i].more() )
return true;
}
@ -243,53 +244,35 @@ namespace mongo {
}
BSONObj ParallelSortClusteredCursor::next(){
advance();
BSONObj best = BSONObj();
int bestFrom = -1;
for ( int i=0; i<_numServers; i++){
if ( _nexts[i].isEmpty() )
if ( ! _cursors[i].more() )
continue;
BSONObj me = _cursors[i].peek();
if ( best.isEmpty() ){
best = _nexts[i];
best = me;
bestFrom = i;
continue;
}
int comp = best.woSortOrder( _nexts[i] , _sortKey );
int comp = best.woSortOrder( me , _sortKey );
if ( comp < 0 )
continue;
best = _nexts[i];
best = me;
bestFrom = i;
}
uassert( 10019 , "no more elements" , ! best.isEmpty() );
_nexts[bestFrom] = BSONObj();
_cursors[bestFrom].next();
return best;
}
void ParallelSortClusteredCursor::advance(){
for ( int i=0; i<_numServers; i++ ){
if ( ! _nexts[i].isEmpty() ){
// already have a good object there
continue;
}
if ( ! _cursors[i].more() ){
// cursor is dead, oh well
continue;
}
_nexts[i] = _cursors[i].next();
}
}
// -----------------
// ---- Future -----
// -----------------

View File

@ -102,7 +102,8 @@ namespace mongo {
bool more();
BSONObj next();
BSONObj peek();
private:
void _advance();
@ -147,14 +148,11 @@ namespace mongo {
private:
void _init();
void advance();
int _numServers;
set<ServerAndQuery> _servers;
BSONObj _sortKey;
FilteringClientCursor * _cursors;
BSONObj * _nexts;
};
/**