summaryrefslogtreecommitdiff
path: root/jstests/replsets/create_drop_database_different_casing.js
blob: 954450248b099ca41a9b699a145ce7ee5a56f3be (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
/**
 * Ensures that the drop database oplog entry gets sent to the secondaries prior to dropping the
 * in memory state of the database in the primary during the 'dropDatabase' command.
 * Dropping the in memory state of the database before sending the drop database oplog entry to the
 * secondaries first can result in a situation where the secondaries crash during replication.
 * The secondaries would crash given this scenario:
 *     - At time 10: Primary drops database "A"'s in memory state.
 *     - At time 15: Primary creates database "a" and sends the create database oplog entries to the
 *                   secondaries.
 *     - At time 20: Secondaries apply create database oplog entry and crash because database "A"
 *                   still exists in-memory for them.
 *     - At time 25: Primary sends database "A"'s drop oplog entry to secondaries (already crashed).
 *
 * @tags: [requires_replication]
 */
(function() {
'use strict';

const rst = new ReplSetTest({nodes: [{}, {rsConfig: {priority: 0}}]});
rst.startSet();
rst.initiate();

const dbNameUpper = "A";
const dbNameLower = "a";

const primary = rst.getPrimary();

let upperDB = primary.getDB(dbNameUpper);
assert.commandWorked(upperDB.createCollection("test"));

assert.commandWorked(upperDB.adminCommand(
    {configureFailPoint: 'dropDatabaseHangBeforeInMemoryDrop', mode: "alwaysOn"}));
let awaitDropUpper = startParallelShell(() => {
    db.getSiblingDB("A").dropDatabase();
}, primary.port);

checkLog.contains(primary, "dropDatabase - fail point dropDatabaseHangBeforeInMemoryDrop enabled.");

let lowerDB = primary.getDB(dbNameLower);

// The oplog entry to the secondaries to drop database "A" was sent, but the primary has not yet
// dropped "A" as it's hanging on the 'dropDatabaseHangBeforeInMemoryDrop' fail point.
assert.commandFailedWithCode(lowerDB.createCollection("test"), ErrorCodes.DatabaseDifferCase);

rst.awaitReplication();
assert.commandWorked(
    lowerDB.adminCommand({configureFailPoint: 'dropDatabaseHangBeforeInMemoryDrop', mode: "off"}));

checkLog.contains(primary, "dropDatabase " + dbNameUpper + " - finished");
assert.commandWorked(lowerDB.createCollection("test"));

awaitDropUpper();

rst.stopSet();
})();