summaryrefslogtreecommitdiff
path: root/jstests/noPassthrough/apply_ops_logging.js
blob: 72572b6f803a743cf424713b105fe5de57eb1c49 (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
61
62
63
64
65
66
67
// SERVER-28594 Ensure non-atomic ops are individually logged in applyOps
// and atomic ops are collectively logged in applyOps.
// @tags: [requires_replication]
(function() {
"use strict";

let rst = new ReplSetTest({nodes: 1});
rst.startSet();
rst.initiate();

let primary = rst.getPrimary();
let testDB = primary.getDB("test");
let oplogColl = primary.getDB("local").oplog.rs;
let testCollName = "testColl";
let rerenamedCollName = "rerenamedColl";

testDB.runCommand({drop: testCollName});
testDB.runCommand({drop: rerenamedCollName});
assert.commandWorked(testDB.runCommand({create: testCollName}));
let testColl = testDB[testCollName];

// Ensure applyOps logging produces an oplog entry for each operation in the applyOps call and no
// record of applyOps appears for these operations.
assert.commandWorked(testDB.runCommand({
    applyOps: [
        {
            op: "c",
            ns: "test.$cmd",
            o: {
                renameCollection: "test.testColl",
                to: "test.renamedColl",
                stayTemp: false,
                dropTarget: false
            }
        },
        {
            op: "c",
            ns: "test.$cmd",
            o: {
                renameCollection: "test.renamedColl",
                to: "test." + rerenamedCollName,
                stayTemp: false,
                dropTarget: false
            }
        }
    ]
}));
assert.eq(oplogColl.find({"o.renameCollection": {"$exists": true}}).count(), 2);
assert.eq(oplogColl.find({"o.applyOps": {"$exists": true}}).count(), 0);

// Since atomic applyOps cannot run atomically, this test ensures that applyOps ignores the
// 'allowAtomic' field. We fail to insert a duplicate doc, and ensure that the original doc was
// inserted successfully. Atomic applyOps would fail to insert both documents.
assert.commandWorked(testDB.createCollection(testColl.getName()));
assert.commandWorked(testDB.runCommand({
    applyOps: [
        {op: "i", ns: testColl.getFullName(), o: {_id: 3, a: "augh"}},
        {op: "i", ns: testColl.getFullName(), o: {_id: 4, a: "blah"}}
    ],
    allowAtomic: true,
}));

assert.eq(oplogColl.find({"o.applyOps": {"$exists": true}}).count(), 0);
assert.eq(oplogColl.find({op: "i", ns: testColl.getFullName()}).count(), 2);

rst.stopSet();
})();