summaryrefslogtreecommitdiff
path: root/jstests/replsets/drop_oplog.js
blob: 2ba8dc44c7216fbaccc59b5cee367a3b9632468a (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
// Test that dropping the replset oplog, the local database, and the admin database are all
// prohibited in a replset.

(function() {
    "use strict";
    let rt = new ReplSetTest({name: "drop_oplog", nodes: 1, oplogSize: 30});

    let nodes = rt.startSet();
    rt.initiate();
    let master = rt.getPrimary();
    let localDB = master.getDB('local');

    let threw = false;

    let ret = assert.commandFailed(localDB.runCommand({drop: 'oplog.rs'}));
    assert.eq('can\'t drop live oplog while replicating', ret.errmsg);

    let dropOutput = localDB.dropDatabase();
    assert.eq(dropOutput.ok, 0);
    assert.eq(dropOutput.errmsg, "Cannot drop 'local' database while replication is active");

    let adminDB = master.getDB('admin');
    dropOutput = adminDB.dropDatabase();
    assert.eq(dropOutput.ok, 0);
    assert.eq(dropOutput.errmsg, "Dropping the 'admin' database is prohibited.");

    let renameOutput = localDB.oplog.rs.renameCollection("poison");
    assert.eq(renameOutput.ok, 0);
    assert.eq(renameOutput.errmsg, "can't rename live oplog while replicating");

    assert.writeOK(localDB.foo.insert({a: 1}));
    renameOutput = localDB.foo.renameCollection("oplog.rs");
    assert.eq(renameOutput.ok, 0);
    assert.eq(renameOutput.errmsg, "can't rename to live oplog while replicating");
    rt.stopSet();
}());