summaryrefslogtreecommitdiff
path: root/jstests/replsets/maintenance_non-blocking.js
blob: 4606bcc19857be8d3f496225beac80b864d55735 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// This test ensures that the replSetMaintenance command will not block, nor block-on, a db write
doTest = function() {
    "use strict";
    var replTest = new ReplSetTest({name: 'testSet', nodes: 2});
    var nodes = replTest.startSet();
    replTest.initiate();

    var m = replTest.getPrimary();
    var mColl = m.getDB("test").maint;
    var s = replTest.getSecondary();
    var sDB = s.getDB("test");
    var sColl = sDB.maint;

    var status = assert.commandWorked(sDB.adminCommand("replSetGetStatus"));
    printjson(status);

    print("******* fsyncLock'n secondary ************* ");
    s.getDB("admin").fsyncLock();

    // save some records
    var len = 100;
    for (var i = 0; i < len; ++i) {
        assert.writeOK(mColl.save({a: i}));
    }

    print("******* replSetMaintenance called on secondary ************* ");
    assert.commandWorked(sDB.adminCommand("replSetMaintenance"));

    var ismaster = assert.commandWorked(sColl.runCommand("ismaster"));
    assert.eq(false, ismaster.ismaster);
    assert.eq(false, ismaster.secondary);

    print("******* writing to primary ************* ");
    assert.writeOK(mColl.save({_id: -1}));
    printjson(sDB.currentOp());
    assert.neq(null, mColl.findOne());

    var ismaster = assert.commandWorked(sColl.runCommand("ismaster"));
    assert.eq(false, ismaster.ismaster);
    assert.eq(false, ismaster.secondary);

    print("******* fsyncUnlock'n secondary ************* ");
    sDB.fsyncUnlock();
};

doTest();
print("SUCCESS");