summaryrefslogtreecommitdiff
path: root/jstests
diff options
context:
space:
mode:
authorLouis Williams <louis.williams@mongodb.com>2018-02-05 11:26:04 -0500
committerLouis Williams <louis.williams@mongodb.com>2018-02-12 10:42:48 -0500
commit4b2f7438ec3494cdf5f4f996bc1ac955a0698f40 (patch)
tree89e81377db85bc90f55b2029e258a04ce721a753 /jstests
parentb7a81ef8a47b6f375d014c15382646947a8f8db4 (diff)
downloadmongo-4b2f7438ec3494cdf5f4f996bc1ac955a0698f40.tar.gz
SERVER-28594 non-atomic applyOps should log each operation individually
(cherry picked from commit 975804ed16ed446e32e7e73643188c9276686311)
Diffstat (limited to 'jstests')
-rw-r--r--jstests/noPassthrough/non_atomic_apply_ops_logging.js62
-rw-r--r--jstests/replsets/libs/apply_ops_concurrent_non_atomic.js9
2 files changed, 65 insertions, 6 deletions
diff --git a/jstests/noPassthrough/non_atomic_apply_ops_logging.js b/jstests/noPassthrough/non_atomic_apply_ops_logging.js
new file mode 100644
index 00000000000..f93e9d38189
--- /dev/null
+++ b/jstests/noPassthrough/non_atomic_apply_ops_logging.js
@@ -0,0 +1,62 @@
+// SERVER-28594 Ensure non-atomic ops are individually logged in applyOps
+// and atomic ops are collectively logged in applyOps.
+(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 atomic apply ops logging only produces one oplog entry
+ // per call to apply ops and does not log individual operations
+ // separately.
+ assert.commandWorked(testDB.runCommand({
+ applyOps: [
+ {op: "i", ns: testColl.getFullName(), o: {_id: 1, a: "foo"}},
+ {op: "i", ns: testColl.getFullName(), o: {_id: 2, a: "bar"}}
+ ]
+ }));
+ assert.eq(oplogColl.find({"o.applyOps": {"$exists": true}}).count(), 1);
+ assert.eq(oplogColl.find({"op": "i"}).count(), 0);
+ // Ensure non-atomic apply ops logging produces an oplog entry for
+ // each operation in the apply ops 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(), 1);
+ rst.stopSet();
+})();
diff --git a/jstests/replsets/libs/apply_ops_concurrent_non_atomic.js b/jstests/replsets/libs/apply_ops_concurrent_non_atomic.js
index 7e36cfa6677..5e170378de2 100644
--- a/jstests/replsets/libs/apply_ops_concurrent_non_atomic.js
+++ b/jstests/replsets/libs/apply_ops_concurrent_non_atomic.js
@@ -127,14 +127,11 @@ var ApplyOpsConcurrentNonAtomicTest = function(options) {
/**
* Returns number of insert operations reported by serverStatus.
- * Depending on the server version, applyOps may increment either 'opcounters' or
- * 'opcountersRepl':
- * since 3.6: 'opcounters.insert'
- * 3.4 and older: 'opcountersRepl.insert'
+ * In 3.4 'opcountersRepl', not 'opcounters' was previously the correct field. Now non-atomic
+ * ops are now replicated as they are applied and are counted toward the global op counter.
*/
function getInsertOpCount(serverStatus) {
- return (serverStatus.version.substr(0, 3) === "3.4") ? serverStatus.opcountersRepl.insert
- : serverStatus.opcounters.insert;
+ return serverStatus.opcounters.insert;
}
/**