Skip to content

Commit 038a1e7

Browse files
committed
dur prealloc - this should be better/safer
1 parent 93eec9b commit 038a1e7

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

db/dur_journal.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -266,10 +266,7 @@ namespace mongo {
266266
assert( len % BLKSZ == 0 );
267267

268268
AlignedBuilder b(BLKSZ);
269-
// we don't rezero a journal file upon recycling (see removeOldJournalFile). given that, its contents
270-
// don't matter, the important thing is it is prealloced. so we fill it with a rand # here : if it not
271-
// being zeroed were a problem, we'd want to catch that sooner than later (upon a recycling)
272-
memset((void*)b.buf(), rand(), BLKSZ);
269+
memset((void*)b.buf(), 0, BLKSZ);
273270

274271
ProgressMeter m(len, 3/*secs*/, 10/*hits between time check (once every 6.4MB)*/);
275272

@@ -327,7 +324,17 @@ namespace mongo {
327324
filesystem::path filepath = getJournalDir() / fn;
328325
if( !filesystem::exists(filepath) ) {
329326
// we can recycle this file into this prealloc file location
330-
boost::filesystem::rename(p, filepath);
327+
filesystem::path temppath = getJournalDir() / (fn+".temp");
328+
boost::filesystem::rename(p, temppath);
329+
{
330+
// zero the header
331+
File f;
332+
f.open(temppath.string().c_str(), false, true);
333+
char buf[8192];
334+
memset(buf, 0, 8192);
335+
f.write(0, buf, 8192);
336+
}
337+
boost::filesystem::rename(temppath, filepath);
331338
return;
332339
}
333340
}

0 commit comments

Comments
 (0)