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

minor: whitespace

This commit is contained in:
Mike Dirolf 2009-09-11 14:15:28 -04:00
parent eae40d3e62
commit bf5faae277
2 changed files with 31 additions and 31 deletions

View File

@ -33,13 +33,13 @@ public:
("out,o" , po::value<string>() , "output directory" ) ("out,o" , po::value<string>() , "output directory" )
; ;
} }
void doCollection( const string coll , path outputFile ) { void doCollection( const string coll , path outputFile ) {
cout << "\t" << coll << " to " << outputFile.string() << endl; cout << "\t" << coll << " to " << outputFile.string() << endl;
int out = open( outputFile.string().c_str() , O_WRONLY | O_CREAT | O_TRUNC , 0666 ); int out = open( outputFile.string().c_str() , O_WRONLY | O_CREAT | O_TRUNC , 0666 );
assert( out ); assert( out );
auto_ptr<DBClientCursor> cursor = conn( true ).query( coll.c_str() , Query().snapshot() , 0 , 0 , 0 , Option_SlaveOk | Option_NoCursorTimeout ); auto_ptr<DBClientCursor> cursor = conn( true ).query( coll.c_str() , Query().snapshot() , 0 , 0 , 0 , Option_SlaveOk | Option_NoCursorTimeout );
int num = 0; int num = 0;
@ -48,17 +48,17 @@ public:
write( out , obj.objdata() , obj.objsize() ); write( out , obj.objdata() , obj.objsize() );
num++; num++;
} }
cout << "\t\t " << num << " objects" << endl; cout << "\t\t " << num << " objects" << endl;
close( out ); close( out );
} }
void go( const string db , const path outdir ) { void go( const string db , const path outdir ) {
cout << "DATABASE: " << db << "\t to \t" << outdir.string() << endl; cout << "DATABASE: " << db << "\t to \t" << outdir.string() << endl;
create_directories( outdir ); create_directories( outdir );
string sns = db + ".system.namespaces"; string sns = db + ".system.namespaces";
auto_ptr<DBClientCursor> cursor = conn( true ).query( sns.c_str() , Query() , 0 , 0 , 0 , Option_SlaveOk | Option_NoCursorTimeout ); auto_ptr<DBClientCursor> cursor = conn( true ).query( sns.c_str() , Query() , 0 , 0 , 0 , Option_SlaveOk | Option_NoCursorTimeout );
@ -66,37 +66,37 @@ public:
BSONObj obj = cursor->next(); BSONObj obj = cursor->next();
if ( obj.toString().find( ".$" ) != string::npos ) if ( obj.toString().find( ".$" ) != string::npos )
continue; continue;
const string name = obj.getField( "name" ).valuestr(); const string name = obj.getField( "name" ).valuestr();
const string filename = name.substr( db.size() + 1 ); const string filename = name.substr( db.size() + 1 );
if ( _coll.length() > 0 && db + "." + _coll != name && _coll != name ) if ( _coll.length() > 0 && db + "." + _coll != name && _coll != name )
continue; continue;
doCollection( name.c_str() , outdir / ( filename + ".bson" ) ); doCollection( name.c_str() , outdir / ( filename + ".bson" ) );
} }
} }
int run(){ int run(){
path root( getParam( "out" , "dump" ) ); path root( getParam( "out" , "dump" ) );
string db = _db; string db = _db;
if ( db == "*" ){ if ( db == "*" ){
cout << "all dbs" << endl; cout << "all dbs" << endl;
auth( "admin" ); auth( "admin" );
BSONObj res = conn( true ).findOne( "admin.$cmd" , BSON( "listDatabases" << 1 ) ); BSONObj res = conn( true ).findOne( "admin.$cmd" , BSON( "listDatabases" << 1 ) );
BSONObj dbs = res.getField( "databases" ).embeddedObjectUserCheck(); BSONObj dbs = res.getField( "databases" ).embeddedObjectUserCheck();
set<string> keys; set<string> keys;
dbs.getFieldNames( keys ); dbs.getFieldNames( keys );
for ( set<string>::iterator i = keys.begin() ; i != keys.end() ; i++ ) { for ( set<string>::iterator i = keys.begin() ; i != keys.end() ; i++ ) {
string key = *i; string key = *i;
BSONObj dbobj = dbs.getField( key ).embeddedObjectUserCheck(); BSONObj dbobj = dbs.getField( key ).embeddedObjectUserCheck();
const char * dbName = dbobj.getField( "name" ).valuestr(); const char * dbName = dbobj.getField( "name" ).valuestr();
if ( (string)dbName == "local" ) if ( (string)dbName == "local" )
continue; continue;

View File

@ -37,13 +37,13 @@ public:
; ;
addPositionArg( "dir" , 1 ); addPositionArg( "dir" , 1 );
} }
int run(){ int run(){
auth(); auth();
drillDown( getParam( "dir" ) ); drillDown( getParam( "dir" ) );
return 0; return 0;
} }
void drillDown( path root ) { void drillDown( path root ) {
if ( is_directory( root ) ) { if ( is_directory( root ) ) {
@ -56,15 +56,15 @@ public:
} }
return; return;
} }
if ( ! ( endsWith( root.string().c_str() , ".bson" ) || if ( ! ( endsWith( root.string().c_str() , ".bson" ) ||
endsWith( root.string().c_str() , ".bin" ) ) ) { endsWith( root.string().c_str() , ".bin" ) ) ) {
cerr << "don't know what to do with [" << root.string() << "]" << endl; cerr << "don't know what to do with [" << root.string() << "]" << endl;
return; return;
} }
out() << root.string() << endl; out() << root.string() << endl;
string ns; string ns;
{ {
string dir = root.branch_path().string(); string dir = root.branch_path().string();
@ -73,39 +73,39 @@ public:
else else
ns += dir.substr( dir.find_last_of( "/" ) + 1 ); ns += dir.substr( dir.find_last_of( "/" ) + 1 );
} }
{ {
string l = root.leaf(); string l = root.leaf();
l = l.substr( 0 , l.find_last_of( "." ) ); l = l.substr( 0 , l.find_last_of( "." ) );
ns += "." + l; ns += "." + l;
} }
if ( boost::filesystem::file_size( root ) == 0 ) { if ( boost::filesystem::file_size( root ) == 0 ) {
out() << "file " + root.native_file_string() + " empty, skipping" << endl; out() << "file " + root.native_file_string() + " empty, skipping" << endl;
return; return;
} }
out() << "\t going into namespace [" << ns << "]" << endl; out() << "\t going into namespace [" << ns << "]" << endl;
MemoryMappedFile mmf; MemoryMappedFile mmf;
long fileLength; long fileLength;
assert( mmf.map( root.string().c_str() , fileLength ) ); assert( mmf.map( root.string().c_str() , fileLength ) );
log(1) << "\t file size: " << fileLength << endl; log(1) << "\t file size: " << fileLength << endl;
char * data = (char*)mmf.viewOfs(); char * data = (char*)mmf.viewOfs();
long read = 0; long read = 0;
long num = 0; long num = 0;
int msgDelay = (int)(1000 * ( 1 + ( mmf.length() / ( 1024.0 * 1024 * 400 ) ) ) ); int msgDelay = (int)(1000 * ( 1 + ( mmf.length() / ( 1024.0 * 1024 * 400 ) ) ) );
log(1) << "\t msg delay: " << msgDelay << endl; log(1) << "\t msg delay: " << msgDelay << endl;
while ( read < mmf.length() ) { while ( read < mmf.length() ) {
BSONObj o( data ); BSONObj o( data );
conn().insert( ns.c_str() , o ); conn().insert( ns.c_str() , o );
read += o.objsize(); read += o.objsize();
data += o.objsize(); data += o.objsize();
@ -113,7 +113,7 @@ public:
if ( logLevel > 0 && num < 10 || ! ( num % msgDelay ) ) if ( logLevel > 0 && num < 10 || ! ( num % msgDelay ) )
out() << "read " << read << "/" << mmf.length() << " bytes so far. (" << (int)( (read * 100) / mmf.length()) << "%) " << num << " objects" << endl; out() << "read " << read << "/" << mmf.length() << " bytes so far. (" << (int)( (read * 100) / mmf.length()) << "%) " << num << " objects" << endl;
} }
out() << "\t " << num << " objects" << endl; out() << "\t " << num << " objects" << endl;
} }
}; };