diff options
Diffstat (limited to 'jstests/replsets/fsync_lock_read_secondaries.js')
-rw-r--r-- | jstests/replsets/fsync_lock_read_secondaries.js | 83 |
1 files changed, 42 insertions, 41 deletions
diff --git a/jstests/replsets/fsync_lock_read_secondaries.js b/jstests/replsets/fsync_lock_read_secondaries.js index b8f8c0aa149..8b9127c8c43 100644 --- a/jstests/replsets/fsync_lock_read_secondaries.js +++ b/jstests/replsets/fsync_lock_read_secondaries.js @@ -1,5 +1,5 @@ /* @file : jstests/fsync_lock_read_secondaries.js - * + * * SERVER 4243 : If there is a pending write due to an fsync lock, all reads are blocked * * This test validates part of SERVER-4243 ticket. Allow reading on secondaries with fsyncLock @@ -22,52 +22,53 @@ * witness as an increase in the count of documents stored on the secondary. */ (function() { -"use strict"; -// Load utility methods for replica set tests -load("jstests/replsets/rslib.js"); + "use strict"; + // Load utility methods for replica set tests + load("jstests/replsets/rslib.js"); -var replTest = new ReplSetTest({name: 'testSet', nodes: 2, oplogSize: 5}); -// Start each mongod in the replica set. Returns a list of nodes -var nodes = replTest.startSet(); -// This will wait for initiation -replTest.initiate(); -var master = replTest.getPrimary(); + var replTest = new ReplSetTest({name: 'testSet', nodes: 2, oplogSize: 5}); + // Start each mongod in the replica set. Returns a list of nodes + var nodes = replTest.startSet(); + // This will wait for initiation + replTest.initiate(); + var master = replTest.getPrimary(); -var ret = master.getDB("admin").fsyncLock(); -if (!ret.ok) { - assert.commandFailedWithCode(ret, ErrorCodes.CommandNotSupported); - jsTestLog("Storage Engine does not support fsyncLock, so bailing"); - return; -} -master.getDB("admin").fsyncUnlock(); + var ret = master.getDB("admin").fsyncLock(); + if (!ret.ok) { + assert.commandFailedWithCode(ret, ErrorCodes.CommandNotSupported); + jsTestLog("Storage Engine does not support fsyncLock, so bailing"); + return; + } + master.getDB("admin").fsyncUnlock(); -var docNum = 100; -for(var i=0; i<docNum; i++) { - master.getDB("foo").bar.save({a: i}); -} -waitForAllMembers(master.getDB("foo")); -replTest.awaitReplication(); + var docNum = 100; + for (var i = 0; i < docNum; i++) { + master.getDB("foo").bar.save({a: i}); + } + waitForAllMembers(master.getDB("foo")); + replTest.awaitReplication(); -// Calling getPrimary also makes available the liveNodes structure, which looks like this: -// liveNodes = {master: masterNode, slaves: [slave1, slave2] } -var slaves = replTest.liveNodes.slaves; -slaves[0].setSlaveOk(); + // Calling getPrimary also makes available the liveNodes structure, which looks like this: + // liveNodes = {master: masterNode, slaves: [slave1, slave2] } + var slaves = replTest.liveNodes.slaves; + slaves[0].setSlaveOk(); -assert.commandWorked(slaves[0].getDB("admin").runCommand({fsync:1, lock: 1})); -var docNum = 1000; -for (var i=0; i<docNum; i++) { - master.getDB("foo").bar.save({a: i}); -} -// Issue a read query on the secondary while holding the fsync lock. -// This is what we are testing. Previously this would block. After the fix -// this should work just fine. -var slave0count = slaves[0].getDB("foo").bar.count(); -assert.eq(slave0count, 100, "Doc count in fsync lock wrong. Expected (=100), found " + slave0count); -assert(slaves[0].getDB("admin").fsyncUnlock().ok); + assert.commandWorked(slaves[0].getDB("admin").runCommand({fsync: 1, lock: 1})); + var docNum = 1000; + for (var i = 0; i < docNum; i++) { + master.getDB("foo").bar.save({a: i}); + } + // Issue a read query on the secondary while holding the fsync lock. + // This is what we are testing. Previously this would block. After the fix + // this should work just fine. + var slave0count = slaves[0].getDB("foo").bar.count(); + assert.eq( + slave0count, 100, "Doc count in fsync lock wrong. Expected (=100), found " + slave0count); + assert(slaves[0].getDB("admin").fsyncUnlock().ok); -// The secondary should have equal or more documents than what it had before. -assert.soon(function() { + // The secondary should have equal or more documents than what it had before. + assert.soon(function() { return slaves[0].getDB("foo").bar.count() > 100; }, "count of documents stored on the secondary did not increase"); -replTest.stopSet(); + replTest.stopSet(); }()); |