diff options
author | A. Jesse Jiryu Davis <jesse@mongodb.com> | 2019-03-29 17:48:58 -0400 |
---|---|---|
committer | A. Jesse Jiryu Davis <jesse@mongodb.com> | 2019-04-08 15:23:52 -0400 |
commit | 4cd74465dc857148e897654d31195226ef665e70 (patch) | |
tree | 372ffcc49e1deaf0981491ed19371e167af5b017 /jstests/replsets/rollover_preserves_active_txns.js | |
parent | 20db20fd8206413361dde31eec67139467429bea (diff) | |
download | mongo-4cd74465dc857148e897654d31195226ef665e70.tar.gz |
SERVER-36494 Test that active txn entries aren't truncated
Add tests for initial sync, recovery, and the inMemory storage engine.
Also, avoid taking a global X lock in replSetReconfig, we only need IX.
Diffstat (limited to 'jstests/replsets/rollover_preserves_active_txns.js')
-rw-r--r-- | jstests/replsets/rollover_preserves_active_txns.js | 53 |
1 files changed, 11 insertions, 42 deletions
diff --git a/jstests/replsets/rollover_preserves_active_txns.js b/jstests/replsets/rollover_preserves_active_txns.js index 8597d1aa3cc..701c77afaa0 100644 --- a/jstests/replsets/rollover_preserves_active_txns.js +++ b/jstests/replsets/rollover_preserves_active_txns.js @@ -1,10 +1,9 @@ /** * 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 a prepared uncommitted transaction is preserved, and all entries - * after it. + * oplog entry that belongs to an active transaction is preserved, and all entries after it. * - * This tests the oldestActiveTransactionTimestamp, which is calculated from the "startTimestamp" + * This tests the oldestActiveTransactionTimestamp, which is calculated from the "startOpTime" * field of documents in the config.transactions collection. * * @tags: [uses_transactions, uses_prepare_transaction] @@ -14,27 +13,24 @@ "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}, - nodes: 2 + nodeOptions: + {syncdelay: 1, setParameter: {logComponentVerbosity: tojson({storage: 1})}}, + nodes: [{}, {rsConfig: {priority: 0, votes: 0}}] }); - replSet.startSet({oplogSize: oplogSizeMB}); + replSet.startSet(PrepareHelpers.replSetStartSetOptions); replSet.initiate(); const primary = replSet.getPrimary(); const secondary = replSet.getSecondary(); const primaryOplog = primary.getDB("local").oplog.rs; - assert.lte(primaryOplog.dataSize(), oplogSizeBytes); + assert.lte(primaryOplog.dataSize(), PrepareHelpers.oplogSizeBytes); const secondaryOplog = secondary.getDB("local").oplog.rs; - assert.lte(secondaryOplog.dataSize(), oplogSizeBytes); + assert.lte(secondaryOplog.dataSize(), PrepareHelpers.oplogSizeBytes); const coll = primary.getDB("test").test; assert.commandWorked(coll.insert({}, {writeConcern: {w: "majority"}})); @@ -68,16 +64,14 @@ jsTestLog("Insert documents until oplog exceeds oplogSize"); // Oplog with prepared txn grows indefinitely - let it reach twice its supposed max size. - while (primaryOplog.dataSize() <= 2 * oplogSizeBytes) { - assert.commandWorked(coll.insert({tenKB: tenKB})); - } + PrepareHelpers.growOplogPastMaxSize(replSet); jsTestLog( `Oplog dataSize = ${primaryOplog.dataSize()}, check the prepare entry still exists`); assert.eq(oplogEntry, primaryOplog.findOne({prepare: true})); assert.soon(() => { - return secondaryOplog.dataSize() > oplogSizeBytes; + return secondaryOplog.dataSize() > PrepareHelpers.oplogSizeBytes; }); assert.eq(oplogEntry, secondaryOplog.findOne({prepare: true})); @@ -91,32 +85,7 @@ throw new Error(`Unrecognized value for commitOrAbort: ${commitOrAbort}`); } - 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); - } + PrepareHelpers.awaitOplogTruncation(replSet); replSet.stopSet(); } |