summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJack Mulrow <jack.mulrow@mongodb.com>2021-12-22 03:31:32 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-12-22 03:55:47 +0000
commit1701a682db7a8548755d7fa8d50b8d712c17dadf (patch)
treebac1b0020ddf368fc4d415bd03f502f279c68db0
parent43cf0229ed3b2c91ae7357991a480b3fc806677c (diff)
downloadmongo-1701a682db7a8548755d7fa8d50b8d712c17dadf.tar.gz
SERVER-61870 Retry loading oplog entries on CappedPositionLost in retryable_internal_transaction_test.js
-rw-r--r--jstests/sharding/libs/retryable_internal_transaction_test.js30
1 files changed, 28 insertions, 2 deletions
diff --git a/jstests/sharding/libs/retryable_internal_transaction_test.js b/jstests/sharding/libs/retryable_internal_transaction_test.js
index f60257cc722..54658f7d52a 100644
--- a/jstests/sharding/libs/retryable_internal_transaction_test.js
+++ b/jstests/sharding/libs/retryable_internal_transaction_test.js
@@ -5,12 +5,38 @@
load('jstests/sharding/libs/sharded_transactions_helpers.js');
+function getOplogEntriesForTxnWithRetries(rs, lsid, txnNumber) {
+ let oplogEntries;
+ assert.soon(
+ () => {
+ try {
+ oplogEntries = getOplogEntriesForTxn(rs, lsid, txnNumber);
+ return true;
+ } catch (e) {
+ // This read from the oplog can fail with CappedPositionLost if the oplog is
+ // concurrently truncated, but the test should only need the oplog entries
+ // from a recent transaction, which shouldn't be truncated because of the
+ // increased oplog size, so it should be safe to retry on this error.
+ if (e.code !== ErrorCodes.CappedPositionLost) {
+ throw e;
+ }
+ print("Retrying loading oplog entries on CappedPositionLost error: " + tojson(e));
+ }
+ },
+ () => {
+ return "Failed to get oplog entries for transaction, lsid: " + tojson(lsid) +
+ ", txnNumber: " + tojson(txnNumber) +
+ ", latest oplog entries: " + tojson(oplogEntries);
+ });
+ return oplogEntries;
+}
+
function RetryableInternalTransactionTest() {
// Set a large oplogSize since this test runs a find command to get the oplog entries for
// every transaction that it runs including large transactions and with the default oplogSize,
// oplog reading done by the find command may not be able to keep up with the oplog truncation,
// causing the command to fail with CappedPositionLost.
- const st = new ShardingTest({shards: 1, rs: {nodes: 2, oplogSize: 1024}});
+ const st = new ShardingTest({shards: 1, rs: {nodes: 2, oplogSize: 256}});
const kTestMode = {kNonRecovery: 1, kRestart: 2, kFailover: 3, kRollback: 4};
const kOplogEntryLocation = {kFirst: 1, kMiddle: 2, kLast: 3};
@@ -31,7 +57,7 @@ function RetryableInternalTransactionTest() {
function getTransactionState(lsid, txnNumber) {
return {
- oplogEntries: getOplogEntriesForTxn(st.rs0, lsid, txnNumber),
+ oplogEntries: getOplogEntriesForTxnWithRetries(st.rs0, lsid, txnNumber),
txnEntries: getTxnEntriesForSession(st.rs0, lsid),
imageEntries: getImageEntriesForTxn(st.rs0, lsid, txnNumber)
};