void processDiagLog( const char * file ) { Connection c; MemoryMappedFile f; long length; unsigned long long L = 0; char * root = (char*)f.map( file , L, MemoryMappedFile::SEQUENTIAL ); verify( L < 0x80000000 ); length = (long) L; verify( root ); verify( length > 0 ); char * pos = root; long read = 0; while ( read < length ) { Message m(pos,false); int len = m.header()->len; DbMessage d(m); cout << len << " " << d.getns() << endl; processMessage( c , m ); read += len; pos += len; } f.close(); }
/** remember "last sequence number" to speed recoveries */ void lsnThread() { Client::initThread("lsn"); time_t last = 0; while( 1 ) { unsigned long long lsn = j.toStoreLastSeqNum.take(); // if you are on a really fast fsync interval, we don't write this as often if( time(0) - last < 5 ) continue; last = time(0); try { // os can flush as it likes. if it flushes slowly, we will just do extra work on recovery. // however, given we actually close the file, that seems unlikely. MemoryMappedFile f; unsigned long long length = 8; unsigned long long *L = static_cast<unsigned long long*>(f.map(lsnPath().string().c_str(), length)); assert(L); *L = lsn; } catch(std::exception& e) { log() << "write to lsn file fails " << e.what() << endl; } } }
unsigned long long journalReadLSN() { try { // os can flush as it likes. if it flushes slowly, we will just do extra work on recovery. // however, given we actually close the file, that seems unlikely. MemoryMappedFile f; unsigned long long *L = static_cast<unsigned long long*>(f.map(lsnPath().string().c_str())); assert(L); return *L; } catch(std::exception& e) { log() << "couldn't read journal/lsn file - if a recovery is needed will apply all files. " << e.what() << endl; } return 0; }
int test2_old9() { out() << "test2" << endl; printStackTrace(); if ( 1 ) return 1; MemoryMappedFile f; long len = 64*1024*1024; char *p = (char *) f.map("/tmp/test.dat", len); char *start = p; char *end = p + 64*1024*1024-2; end[1] = 'z'; int i; while ( p < end ) { *p++ = ' '; if ( ++i%64 == 0 ) { *p++ = '\n'; *p++ = 'x'; } } *p = 'a'; f.flush(true); out() << "done" << endl; char *x = start + 32 * 1024 * 1024; char *y = start + 48 * 1024 * 1024; char *z = start + 62 * 1024 * 1024; strcpy(z, "zfoo"); out() << "y" << endl; strcpy(y, "yfoo"); strcpy(x, "xfoo"); strcpy(start, "xfoo"); dbexit( EXIT_TEST ); return 1; }
void drillDown( path root ) { if ( is_directory( root ) ) { directory_iterator end; directory_iterator i(root); while ( i != end ) { path p = *i; drillDown( p ); i++; } return; } if ( ! ( endsWith( root.string().c_str() , ".bson" ) || endsWith( root.string().c_str() , ".bin" ) ) ) { cerr << "don't know what to do with [" << root.string() << "]" << endl; return; } out() << root.string() << endl; string ns; { string dir = root.branch_path().string(); if ( dir.find( "/" ) == string::npos ) ns += dir; else ns += dir.substr( dir.find_last_of( "/" ) + 1 ); } { string l = root.leaf(); l = l.substr( 0 , l.find_last_of( "." ) ); ns += "." + l; } if ( boost::filesystem::file_size( root ) == 0 ) { out() << "file " + root.native_file_string() + " empty, aborting" << endl; return; } out() << "\t going into namespace [" << ns << "]" << endl; MemoryMappedFile mmf; assert( mmf.map( root.string().c_str() ) ); char * data = (char*)mmf.viewOfs(); int read = 0; int num = 0; while ( read < mmf.length() ) { BSONObj o( data ); conn().insert( ns.c_str() , o ); read += o.objsize(); data += o.objsize(); if ( ! ( ++num % 1000 ) ) out() << "read " << read << "/" << mmf.length() << " bytes so far. " << num << " objects" << endl; } out() << "\t " << num << " objects" << endl; }