Skip to content

Commit c2b809b

Browse files
committed
better repair mongodump
1 parent 095948e commit c2b809b

File tree

1 file changed

+29
-9
lines changed

1 file changed

+29
-9
lines changed

tools/dump.cpp

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ class Dump : public Tool {
150150
return _repair( dbname );
151151
}
152152

153-
DiskLoc _repairExtent( Database* db , string ns, bool forward , DiskLoc eLoc ){
153+
DiskLoc _repairExtent( Database* db , string ns, bool forward , DiskLoc eLoc , Writer& w ){
154154
LogIndentLevel lil;
155155

156156
if ( eLoc.getOfs() <= 0 ){
@@ -176,16 +176,17 @@ class Dump : public Tool {
176176
error() << "offset is 0 for record which should be impossible" << endl;
177177
break;
178178
}
179-
log() << loc << endl;
179+
log(1) << loc << endl;
180180
Record* rec = loc.rec();
181-
log() << loc.obj() << endl;
181+
log(1) << loc.obj() << endl;
182+
w( loc.obj() );
182183
loc = forward ? rec->getNext( loc ) : rec->getPrev( loc );
183184
}
184185
return forward ? e->xnext : e->xprev;
185186

186187
}
187188

188-
void _repair( Database* db , string ns ){
189+
void _repair( Database* db , string ns , path outfile ){
189190
NamespaceDetails * nsd = nsdetails( ns.c_str() );
190191
log() << "nrecords: " << nsd->stats.nrecords
191192
<< " datasize: " << nsd->stats.datasize
@@ -201,53 +202,72 @@ class Dump : public Tool {
201202
log() << " ERROR fisrtExtent is not valid" << endl;
202203
return;
203204
}
205+
206+
outfile /= ( ns.substr( ns.find( "." ) + 1 ) + ".bson" );
207+
log() << "writing to: " << outfile.string() << endl;
208+
209+
ofstream out;
210+
out.open( outfile.string().c_str() , ios_base::out | ios_base::binary );
211+
212+
ProgressMeter m( nsd->stats.nrecords * 2 );
204213

214+
Writer w( out , &m );
215+
205216
try {
206217
log() << "forward extent pass" << endl;
207218
LogIndentLevel lil;
208219
DiskLoc eLoc = nsd->firstExtent;
209220
while ( ! eLoc.isNull() ){
210221
log() << "extent loc: " << eLoc << endl;
211-
eLoc = _repairExtent( db , ns , true , eLoc );
222+
eLoc = _repairExtent( db , ns , true , eLoc , w );
212223
}
213224
}
214225
catch ( DBException& e ){
215226
error() << "forward extent pass failed:" << e.toString() << endl;
216227
}
217-
228+
218229
try {
219230
log() << "backwards extent pass" << endl;
220231
LogIndentLevel lil;
221232
DiskLoc eLoc = nsd->lastExtent;
222233
while ( ! eLoc.isNull() ){
223234
log() << "extent loc: " << eLoc << endl;
224-
eLoc = _repairExtent( db , ns , false , eLoc );
235+
eLoc = _repairExtent( db , ns , false , eLoc , w );
225236
}
226237
}
227238
catch ( DBException& e ){
228239
error() << "ERROR: backwards extent pass failed:" << e.toString() << endl;
229240
}
230241

242+
out.close();
243+
244+
log() << "\t\t " << m.done() << " objects" << endl;
231245
}
232246

233-
int _repair( string dbname ){
247+
int _repair( string dbname ) {
234248
dblock lk;
235249
Client::Context cx( dbname );
236250
Database * db = cx.db();
237251

238252
list<string> namespaces;
239253
db->namespaceIndex.getNamespaces( namespaces );
240254

255+
path root = getParam( "out" );
256+
root /= dbname;
257+
create_directories( root );
258+
241259
for ( list<string>::iterator i=namespaces.begin(); i!=namespaces.end(); ++i ){
242260
LogIndentLevel lil;
243261
string ns = *i;
244262
if ( str::endsWith( ns , ".system.namespaces" ) )
245263
continue;
264+
if ( str::contains( ns , ".tmp.mr." ) )
265+
continue;
246266
log() << "trying to recover: " << ns << endl;
247267

248268
LogIndentLevel lil2;
249269
try {
250-
_repair( db , ns );
270+
_repair( db , ns , root );
251271
}
252272
catch ( DBException& e ){
253273
log() << "ERROR recovering: " << ns << " " << e.toString() << endl;

0 commit comments

Comments
 (0)