diff options
author | Charlie Swanson <charlie.swanson@mongodb.com> | 2015-11-19 14:21:42 -0500 |
---|---|---|
committer | Charlie Swanson <charlie.swanson@mongodb.com> | 2015-11-19 14:21:42 -0500 |
commit | aaa555f2b4062d4910b991869a13e965409fa2b4 (patch) | |
tree | baca883892dc50f82995a9d9b59f0a0e79b3904c /jstests/mmap_v1 | |
parent | 047f82cdba8d515743fd451b773740276337d01f (diff) | |
download | mongo-aaa555f2b4062d4910b991869a13e965409fa2b4.tar.gz |
SERVER-21543 Lengthen delay before deleting old journal files
Diffstat (limited to 'jstests/mmap_v1')
-rw-r--r-- | jstests/mmap_v1/dur_remove_old_journals.js | 92 |
1 files changed, 48 insertions, 44 deletions
diff --git a/jstests/mmap_v1/dur_remove_old_journals.js b/jstests/mmap_v1/dur_remove_old_journals.js index cd3cee0e7ba..de6f38dfaaa 100644 --- a/jstests/mmap_v1/dur_remove_old_journals.js +++ b/jstests/mmap_v1/dur_remove_old_journals.js @@ -1,60 +1,64 @@ -// this test makes sure that old journal files are removed +/** + * Test that old journal files are eventually deleted. + */ if (db.serverBuildInfo().bits == 32) { - print("skip on 32 bit systems"); -} -else { - // tunables - STRING_SIZE = 1024*1024; - NUM_TO_INSERT = 2.5*1024; - PATH = MongoRunner.dataDir + "/dur_remove_old_journals"; - SYNC_DELAY = 5; // must be a number - - var conn = MongoRunner.runMongod({dbpath: PATH, - journal: "", - smallfiles: "", - syncdelay: SYNC_DELAY}); + print("skip on 32 bit systems"); +} else { + var conn = MongoRunner.runMongod({ + journal: "", + smallfiles: "", + syncdelay: 5, // seconds between fsyncs. + }); db = conn.getDB("test"); - longString = 'x'; - while (longString.length < STRING_SIZE) - longString += longString; + // Returns true if j._0 exists. + function firstJournalFileExists() { + var files = listFiles(conn.dbpath + "/journal"); + for (var i = 0; i < files.length; i++) { + if (files[i].baseName === "j._0") { + return true; + } + } + return false; + } + + // Represents the cummulative total of the number of journal files created. + function getLatestJournalFileNum() { + var files = listFiles(conn.dbpath + "/journal"); + var latest = 0; + files.forEach(function(file) { + if (file.baseName !== "lsn") { + var fileNum = NumberInt(file.baseName[file.baseName.length - 1]); + latest = Math.max(latest, fileNum); + } + }); + return latest; + } + + var stringSize = 1024*1024; + var longString = new Array(stringSize).join("x"); - numInserted = 0; - while (numInserted < NUM_TO_INSERT){ - db.foo.insert({_id: numInserted++, s:longString}); + // Insert some data to create the first journal file. + var numInserted = 0; + while (numInserted < 100) { + db.foo.insert({_id: numInserted++, s: longString}); + } + assert.soon(firstJournalFileExists, "Should have created a journal file"); + // Do writes until the first journal file is deleted, or we give up waiting. + var maxJournalFiles = 10; + while (firstJournalFileExists() && getLatestJournalFileNum() < maxJournalFiles) { + db.foo.insert({_id: numInserted++, s: longString}); if (numInserted % 100 == 0){ - print("numInserted: " + numInserted); + jsTestLog("numInserted: " + numInserted); db.adminCommand({fsync:1}); db.foo.remove({}); db.adminCommand({fsync:1}); } } - sleepSecs = SYNC_DELAY + 15 // long enough for data file flushing and journal keep time - print("\nWaiting " + sleepSecs + " seconds...\n"); - sleep(sleepSecs*1000); - - - files = listFiles(PATH + "/journal") - printjson(files); - - var nfiles = 0; - files.forEach(function (file) { - assert.eq('string', typeof (file.name)); // sanity checking - if (/prealloc/.test(file.name)) { - ; - } - else { - nfiles++; - } - }) - - assert.eq(2, nfiles); // latest journal file and lsn - + assert(!firstJournalFileExists(), "Expected to have deleted the first journal file by now"); MongoRunner.stopMongod(conn); } - -print("*** success ***"); |