-
Notifications
You must be signed in to change notification settings - Fork 5.6k
/
Copy pathapply_ops_dropDatabase.js
64 lines (51 loc) · 2.24 KB
/
apply_ops_dropDatabase.js
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
61
62
63
64
/**
* Ensures that the dropDatabase op can only be run if it's the single entry in an applyOps context.
* Exercises that the operation can run even if it has to await replication of the intermediate
* collection drops.
*
* @tags: [
* requires_replication,
* # dropDatabase can work in conjunction with other operations in 5.0.
* requires_fcv_53
* ]
*/
import {ReplSetTest} from "jstests/libs/replsettest.js";
const rst = new ReplSetTest({nodes: 2});
rst.startSet();
rst.initiate();
const dbName = "dbDrop";
const collName = "coll";
const cmdNss = dbName + ".$cmd";
const primaryDB = rst.getPrimary().getDB(dbName);
primaryDB.createCollection(collName);
const dropDatabaseOp = {
op: "c",
ns: cmdNss,
o: {dropDatabase: 1}
};
// Verify that dropDatabase is only supported if it's the only op entry.
assert.commandFailedWithCode(
primaryDB.adminCommand(
{applyOps: [{op: "c", ns: cmdNss, o: {create: "collection"}}, dropDatabaseOp]}),
6275900);
assert.contains(dbName, rst.getPrimary().getDBNames());
assert.sameMembers(primaryDB.getCollectionNames(), [collName]);
// TODO(SERVER-94154): Remove version check here.
const fcvDoc = primaryDB.adminCommand({getParameter: 1, featureCompatibilityVersion: 1});
if (MongoRunner.compareBinVersions(fcvDoc.featureCompatibilityVersion.version, "8.1") >= 0) {
// Verify that dropDatabase is not supported inside nested applyOps.
const createApplyOpsOplogEntry = (ops) => ({op: "c", ns: "admin.$cmd", o: {applyOps: ops}});
assert.commandFailedWithCode(
primaryDB.adminCommand({applyOps: [createApplyOpsOplogEntry([dropDatabaseOp])]}), 9585500);
assert.commandFailedWithCode(
primaryDB.adminCommand(
{applyOps: [createApplyOpsOplogEntry([createApplyOpsOplogEntry([dropDatabaseOp])])]}),
9585500);
assert.contains(dbName, rst.getPrimary().getDBNames());
assert.sameMembers(primaryDB.getCollectionNames(), [collName]);
}
// Run the dropDatabase op on a database with an existing collection so that we can exercise
// dropDatabase cleanly awaiting replication of the collection drop internally.
assert.commandWorked(primaryDB.adminCommand({applyOps: [dropDatabaseOp]}));
assert.eq(rst.getPrimary().getDBNames().indexOf(dbName), -1);
rst.stopSet();