summaryrefslogtreecommitdiff
path: root/jstests/noPassthrough/step_down_during_drop_database.js
blob: 51a21afce76b5415142eea277cb5a7582365fa7a (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
48
49
50
51
52
53
54
55
56
57
58
59
60
/**
 * Tests that performing a stepdown on the primary during a dropDatabase command doesn't have any
 * negative effects when the new primary runs the same dropDatabase command while the old primary
 * is still in the midst of dropping the database.
 *
 * @tags: [requires_replication]
 */
(function() {
    "use strict";

    load("jstests/libs/check_log.js");

    const dbName = "test";
    const collName = "coll";

    const replSet = new ReplSetTest({nodes: 2});
    replSet.startSet();
    replSet.initiate();

    let primary = replSet.getPrimary();
    let testDB = primary.getDB(dbName);

    const size = 5;
    jsTest.log("Creating " + size + " test documents.");
    var bulk = testDB.getCollection(collName).initializeUnorderedBulkOp();
    for (var i = 0; i < size; ++i) {
        bulk.insert({i: i});
    }
    assert.writeOK(bulk.execute());
    replSet.awaitReplication();

    const failpoint = "dropDatabaseHangAfterAllCollectionsDrop";
    assert.commandWorked(primary.adminCommand({configureFailPoint: failpoint, mode: "alwaysOn"}));

    // Run the dropDatabase command and stepdown the primary while it is running.
    const awaitShell = startParallelShell(() => {
        db.dropDatabase();
    }, testDB.getMongo().port);

    // Ensure the dropDatabase command has begun before stepping down.
    checkLog.contains(primary,
                      "dropDatabase - fail point dropDatabaseHangAfterAllCollectionsDrop " +
                          "enabled. Blocking until fail point is disabled.");

    assert.commandWorked(testDB.adminCommand({replSetStepDown: 60, force: true}));
    replSet.waitForState(primary, ReplSetTest.State.SECONDARY);

    assert.commandWorked(primary.adminCommand({configureFailPoint: failpoint, mode: "off"}));
    awaitShell();

    primary = replSet.getPrimary();
    testDB = primary.getDB(dbName);

    // Run dropDatabase on the new primary. The secondary (formerly the primary) should be able to
    // drop the database too.
    testDB.dropDatabase();
    replSet.awaitReplication();

    replSet.stopSet();
})();