summaryrefslogtreecommitdiff
path: root/jstests/replsets/rollover_preserves_active_txns.js
diff options
context:
space:
mode:
authorA. Jesse Jiryu Davis <jesse@mongodb.com>2019-04-08 14:02:36 -0400
committerA. Jesse Jiryu Davis <jesse@mongodb.com>2019-04-08 14:19:08 -0400
commit02a87ee5b1942d24e1d7a20502c79d36218929fe (patch)
tree68219f29d940a1eae531e4cedde40e87aab57389 /jstests/replsets/rollover_preserves_active_txns.js
parent2db32e10f3e1e5aedb80703104fae838acfcf696 (diff)
downloadmongo-02a87ee5b1942d24e1d7a20502c79d36218929fe.tar.gz
Revert "SERVER-36494 Test that active txn entries aren't truncated"
This reverts commit f8f872e029ba3b1f32d8499c912756d48dc1a03b.
Diffstat (limited to 'jstests/replsets/rollover_preserves_active_txns.js')
-rw-r--r--jstests/replsets/rollover_preserves_active_txns.js53
1 files changed, 42 insertions, 11 deletions
diff --git a/jstests/replsets/rollover_preserves_active_txns.js b/jstests/replsets/rollover_preserves_active_txns.js
index 701c77afaa0..8597d1aa3cc 100644
--- a/jstests/replsets/rollover_preserves_active_txns.js
+++ b/jstests/replsets/rollover_preserves_active_txns.js
@@ -1,9 +1,10 @@
/**
* When a primary's oplog size exceeds the configured maximum, it must truncate the oplog only up to
* the oldest active transaction timestamp at the time of the last stable checkpoint. The first
- * oplog entry that belongs to an active transaction is preserved, and all entries after it.
+ * oplog entry that belongs to a prepared uncommitted transaction is preserved, and all entries
+ * after it.
*
- * This tests the oldestActiveTransactionTimestamp, which is calculated from the "startOpTime"
+ * This tests the oldestActiveTransactionTimestamp, which is calculated from the "startTimestamp"
* field of documents in the config.transactions collection.
*
* @tags: [uses_transactions, uses_prepare_transaction]
@@ -13,24 +14,27 @@
"use strict";
load("jstests/core/txns/libs/prepare_helpers.js");
+ const oplogSizeMB = 1;
+ const oplogSizeBytes = oplogSizeMB * 1024 * 1024;
+ const tenKB = new Array(10 * 1024).join("a");
+
// A new replica set for both the commit and abort tests to ensure the same clean state.
function doTest(commitOrAbort) {
const replSet = new ReplSetTest({
// Oplog can be truncated each "sync" cycle. Increase its frequency to once per second.
- nodeOptions:
- {syncdelay: 1, setParameter: {logComponentVerbosity: tojson({storage: 1})}},
- nodes: [{}, {rsConfig: {priority: 0, votes: 0}}]
+ nodeOptions: {syncdelay: 1},
+ nodes: 2
});
- replSet.startSet(PrepareHelpers.replSetStartSetOptions);
+ replSet.startSet({oplogSize: oplogSizeMB});
replSet.initiate();
const primary = replSet.getPrimary();
const secondary = replSet.getSecondary();
const primaryOplog = primary.getDB("local").oplog.rs;
- assert.lte(primaryOplog.dataSize(), PrepareHelpers.oplogSizeBytes);
+ assert.lte(primaryOplog.dataSize(), oplogSizeBytes);
const secondaryOplog = secondary.getDB("local").oplog.rs;
- assert.lte(secondaryOplog.dataSize(), PrepareHelpers.oplogSizeBytes);
+ assert.lte(secondaryOplog.dataSize(), oplogSizeBytes);
const coll = primary.getDB("test").test;
assert.commandWorked(coll.insert({}, {writeConcern: {w: "majority"}}));
@@ -64,14 +68,16 @@
jsTestLog("Insert documents until oplog exceeds oplogSize");
// Oplog with prepared txn grows indefinitely - let it reach twice its supposed max size.
- PrepareHelpers.growOplogPastMaxSize(replSet);
+ while (primaryOplog.dataSize() <= 2 * oplogSizeBytes) {
+ assert.commandWorked(coll.insert({tenKB: tenKB}));
+ }
jsTestLog(
`Oplog dataSize = ${primaryOplog.dataSize()}, check the prepare entry still exists`);
assert.eq(oplogEntry, primaryOplog.findOne({prepare: true}));
assert.soon(() => {
- return secondaryOplog.dataSize() > PrepareHelpers.oplogSizeBytes;
+ return secondaryOplog.dataSize() > oplogSizeBytes;
});
assert.eq(oplogEntry, secondaryOplog.findOne({prepare: true}));
@@ -85,7 +91,32 @@
throw new Error(`Unrecognized value for commitOrAbort: ${commitOrAbort}`);
}
- PrepareHelpers.awaitOplogTruncation(replSet);
+ jsTestLog("Add writes after transaction finished to trigger oplog reclamation");
+
+ // Old entries are reclaimed when oplog size reaches new milestone. With a 1MB oplog,
+ // milestones are every 0.1 MB (see WiredTigerRecordStore::OplogStones::OplogStones) so
+ // write about 0.2 MB to be certain.
+ for (var i = 0; i < 200; i++) {
+ assert.commandWorked(coll.insert({tenKB: tenKB}));
+ }
+
+ jsTestLog("Waiting for oplog to shrink to 1MB");
+
+ for (let [nodeName, oplog] of[["primary", primaryOplog], ["secondary", secondaryOplog]]) {
+ assert.soon(function() {
+ const dataSize = oplog.dataSize();
+ const prepareEntryRemoved = (oplog.findOne({prepare: true}) === null);
+ print(
+ `${nodeName} oplog dataSize: ${dataSize}, prepare entry removed: ${prepareEntryRemoved}`);
+ // The oplog milestone system allows the oplog to grow to 110% its max size.
+ if (dataSize < 1.1 * oplogSizeBytes && prepareEntryRemoved) {
+ return true;
+ }
+
+ assert.commandWorked(coll.insert({tenKB: tenKB}, {writeConcern: {w: "majority"}}));
+ return false;
+ }, `waiting for ${nodeName} oplog reclamation`, ReplSetTest.kDefaultTimeoutMS, 1000);
+ }
replSet.stopSet();
}