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

don't use any files for external sort if its in 1 chunk

This commit is contained in:
Eliot Horowitz 2009-09-25 11:22:43 -04:00
parent ab135dd2f4
commit c2c136a3f2
3 changed files with 36 additions and 3 deletions

View File

@ -56,6 +56,10 @@ namespace mongo {
_sorted = true;
if ( _map && _files.size() == 0 ){
return;
}
if ( _map ){
finishMap();
}
@ -120,11 +124,20 @@ namespace mongo {
// ---------------------------------
BSONObjExternalSorter::Iterator::Iterator( BSONObjExternalSorter * sorter ) : _cmp( sorter->_order ){
BSONObjExternalSorter::Iterator::Iterator( BSONObjExternalSorter * sorter ) :
_cmp( sorter->_order ) , _in( 0 ){
for ( list<string>::iterator i=sorter->_files.begin(); i!=sorter->_files.end(); i++ ){
_files.push_back( new FileIterator( *i ) );
_stash.push_back( pair<Data,bool>( Data( BSONObj() , DiskLoc() ) , false ) );
}
if ( _files.size() == 0 && sorter->_map ){
_in = sorter->_map;
_it = sorter->_map->begin();
}
}
BSONObjExternalSorter::Iterator::~Iterator(){
@ -134,6 +147,10 @@ namespace mongo {
}
bool BSONObjExternalSorter::Iterator::more(){
if ( _in )
return _it != _in->end();
for ( vector<FileIterator*>::iterator i=_files.begin(); i!=_files.end(); i++ )
if ( (*i)->more() )
return true;
@ -144,6 +161,11 @@ namespace mongo {
}
pair<BSONObj,DiskLoc> BSONObjExternalSorter::Iterator::next(){
if ( _in ){
return *(_it++);
}
Data best;
int slot = -1;

View File

@ -77,6 +77,10 @@ namespace mongo {
MyCmp _cmp;
vector<FileIterator*> _files;
vector< pair<Data,bool> > _stash;
InMemory * _in;
InMemory::iterator _it;
};
BSONObjExternalSorter( const BSONObj & order = BSONObj() , long maxFileSize = 1024 * 1024 * 100 );
@ -95,6 +99,10 @@ namespace mongo {
return auto_ptr<Iterator>( new Iterator( this ) );
}
int numFiles(){
return _files.size();
}
private:
void sort( string file );

View File

@ -826,7 +826,9 @@ namespace JsobjTests {
ASSERT( 0 );
num++;
}
ASSERT_EQUALS( 0 , sorter.numFiles() );
}
};
@ -944,7 +946,7 @@ namespace JsobjTests {
}
sorter.sort();
auto_ptr<BSONObjExternalSorter::Iterator> i = sorter.iterator();
int num=0;
double prev = 0;
@ -956,6 +958,7 @@ namespace JsobjTests {
prev = cur;
}
assert( num == total );
ASSERT( sorter.numFiles() > 2 );
}
};