0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-11-30 00:56:44 +01:00

make mongoimportjson not crash with small objects, some ProgressMeter enhancements SERVER-342

This commit is contained in:
Eliot Horowitz 2009-10-08 10:11:26 -04:00
parent 914bca4ff4
commit a54742b3de
2 changed files with 25 additions and 14 deletions

View File

@ -45,6 +45,7 @@ public:
int run(){
string filename = getParam( "file" );
long long fileSize = -1;
istream * in = &cin;
@ -52,6 +53,7 @@ public:
if ( filename.size() > 0 && filename != "-" ){
in = &file;
fileSize = file_size( filename );
}
string ns;
@ -78,29 +80,35 @@ public:
time_t start = time(0);
ProgressMeter pm( fileSize );
const int BUF_SIZE = 1024 * 1024 * 4;
char line[ (1024 * 1024 * 4) + 128];
while ( *in ){
in->getline( line , BUF_SIZE );
int len = strlen( line );
if ( ! len )
break;
char * buf = line;
while( isspace( buf[0] ) ) buf++;
int len = strlen( buf );
if ( ! len )
continue;
if ( in->rdstate() == ios_base::eofbit )
break;
assert( in->rdstate() == 0 );
try {
BSONObj o = fromjson( line );
BSONObj o = fromjson( buf );
conn().insert( ns.c_str() , o );
}
catch ( MsgAssertionException& ma ){
cout << "exception:" << ma.toString() << endl;
cout << line << endl;
cout << buf << endl;
}
if ( ++num % 10000 == 0 ){
cout << num << "\t" << ( num / ( time(0) - start ) ) << "/second" << endl;
num++;
if ( pm.hit( len + 1 ) ){
cout << "\t\t\t" << num << "\t" << ( num / ( time(0) - start ) ) << "/second" << endl;
}
}

View File

@ -328,19 +328,22 @@ namespace mongo {
_done(0) , _hits(0) , _lastTime( (int) time(0) ){
}
void hit( int n = 1 ){
bool hit( int n = 1 ){
_done += n;
_hits++;
if ( _hits % _checkInterval )
return;
return false;
int t = (int) time(0);
if ( t - _lastTime < _secondsBetween )
return;
return false;
int per = (int)( ( (double)_done * 100.0 ) / (double)_total );
cout << "\t\t" << _done << "/" << _total << "\t" << per << "%" << endl;
if ( _total > 0 ){
int per = (int)( ( (double)_done * 100.0 ) / (double)_total );
cout << "\t\t" << _done << "/" << _total << "\t" << per << "%" << endl;
}
_lastTime = t;
return true;
}
long long done(){