__declspec(noinline) void makeChunkWritableOld(size_t chunkno) { scoped_lock lk(mapViewMutex); if( writable.get(chunkno) ) return; size_t loc = chunkno * MemoryMappedFile::ChunkSize; void *Loc = (void*) loc; size_t ofs; MongoMMF *mmf = privateViews.find( (void *) (loc), ofs ); MemoryMappedFile *f = (MemoryMappedFile*) mmf; assert(f); size_t len = MemoryMappedFile::ChunkSize; assert( mmf->getView() <= Loc ); if( ofs + len > f->length() ) { // at the very end of the map len = (size_t) (f->length() - ofs); } else { ; } // todo: check this goes away on remap DWORD old; bool ok = VirtualProtect(Loc, len, PAGE_WRITECOPY, &old); if( !ok ) { DWORD e = GetLastError(); log() << "VirtualProtect failed " << Loc << ' ' << len << ' ' << errnoWithDescription(e) << endl; assert(false); } writable.set(chunkno); }
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; }