diff options
author | Cheahuychou Mao <mao.cheahuychou@gmail.com> | 2022-05-18 20:25:45 +0000 |
---|---|---|
committer | Cheahuychou Mao <mao.cheahuychou@gmail.com> | 2022-05-18 22:22:33 +0000 |
commit | 79e48dd8b0010e454abd7a7c32bbb97e1714a5fb (patch) | |
tree | 1a35adab90dfe253c2c0b6e8c6852d58ad7625f8 | |
parent | 8035d1b6c19437528e6e58717283636d56dd962e (diff) | |
download | mongo-79e48dd8b0010e454abd7a7c32bbb97e1714a5fb.tar.gz |
SERVER-66526 Hang upon restart when there is a prepared internal transaction for retryable findAndModify executed with storeFindAndModifyImagesInSideCollection=true to reconstruct
(cherry picked from commit 13a610d118fb039dc6e9ecb72f3d41e3777d2263)
-rw-r--r-- | jstests/sharding/internal_txns/retryable_findAndModify_commit_and_abort_prepared_txns_after_failover_and_restart.js (renamed from jstests/sharding/internal_txns/retryable_findAndModify_commit_and_abort_prepared_txns_after_failover.js) | 62 | ||||
-rw-r--r-- | src/mongo/db/repl/oplog.cpp | 2 |
2 files changed, 57 insertions, 7 deletions
diff --git a/jstests/sharding/internal_txns/retryable_findAndModify_commit_and_abort_prepared_txns_after_failover.js b/jstests/sharding/internal_txns/retryable_findAndModify_commit_and_abort_prepared_txns_after_failover_and_restart.js index b0caef0375b..27cf8aef667 100644 --- a/jstests/sharding/internal_txns/retryable_findAndModify_commit_and_abort_prepared_txns_after_failover.js +++ b/jstests/sharding/internal_txns/retryable_findAndModify_commit_and_abort_prepared_txns_after_failover_and_restart.js @@ -1,8 +1,8 @@ /* * Test that prepared retryable internal transactions with a findAndModify statement can commit and - * abort after failover. + * abort after failover and restart. * - * @tags: [requires_fcv_60, uses_transactions] + * @tags: [requires_fcv_60, uses_transactions, requires_persistence] */ (function() { 'use strict'; @@ -110,7 +110,7 @@ function runTest(st, stepDownShard0PrimaryFunc, testOpts = { enableFindAndModifyImageCollection: true }); - // Test findAnModify without pre/post image when the image collection is enabled. + // Test findAnModify with pre/post image when the image collection is enabled. runTest(st, stepDownShard0PrimaryFunc, { runFindAndModifyWithPreOrPostImage: true, abortTxnAfterFailover: false, @@ -121,7 +121,7 @@ function runTest(st, stepDownShard0PrimaryFunc, testOpts = { abortTxnAfterFailover: true, enableFindAndModifyImageCollection: true }); - // Test findAnModify without pre/post image when the image collection is disabled. + // Test findAnModify with pre/post image when the image collection is disabled. runTest(st, stepDownShard0PrimaryFunc, { runFindAndModifyWithPreOrPostImage: true, abortTxnAfterFailover: false, @@ -157,7 +157,7 @@ function runTest(st, stepDownShard0PrimaryFunc, testOpts = { enableFindAndModifyImageCollection: true }); - // Test findAnModify without pre/post image when the image collection is enabled. + // Test findAnModify with pre/post image when the image collection is enabled. runTest(st, stepDownShard0PrimaryFunc, { runFindAndModifyWithPreOrPostImage: true, abortTxnAfterFailover: false, @@ -168,7 +168,7 @@ function runTest(st, stepDownShard0PrimaryFunc, testOpts = { abortTxnAfterFailover: true, enableFindAndModifyImageCollection: true }); - // Test findAnModify without pre/post image when the image collection is disabled. + // Test findAnModify with pre/post image when the image collection is disabled. runTest(st, stepDownShard0PrimaryFunc, { runFindAndModifyWithPreOrPostImage: true, abortTxnAfterFailover: false, @@ -182,4 +182,54 @@ function runTest(st, stepDownShard0PrimaryFunc, testOpts = { st.stop(); } + +{ + jsTest.log("Test when the old primary restarts"); + const st = new ShardingTest({shards: 1, rs: {nodes: 1}}); + const restartShard0Func = () => { + st.rs0.stopSet(null /* signal */, true /*forRestart */); + st.rs0.startSet({restart: true}); + st.rs0.getPrimary(); + // Wait for replication since it is illegal to run commitTransaction before the prepare + // oplog entry has been majority committed. + st.rs0.awaitReplication(); + }; + + // Test findAnModify without pre/post image. + runTest(st, restartShard0Func, { + runFindAndModifyWithPreOrPostImage: false, + abortTxnAfterFailover: false, + enableFindAndModifyImageCollection: true + }); + runTest(st, restartShard0Func, { + runFindAndModifyWithPreOrPostImage: false, + abortTxnAfterFailover: true, + enableFindAndModifyImageCollection: true + }); + + // Test findAnModify with pre/post image when the image collection is enabled. + runTest(st, restartShard0Func, { + runFindAndModifyWithPreOrPostImage: true, + abortTxnAfterFailover: false, + enableFindAndModifyImageCollection: true + }); + runTest(st, restartShard0Func, { + runFindAndModifyWithPreOrPostImage: true, + abortTxnAfterFailover: true, + enableFindAndModifyImageCollection: true + }); + // Test findAnModify with pre/post image when the image collection is disabled. + runTest(st, restartShard0Func, { + runFindAndModifyWithPreOrPostImage: true, + abortTxnAfterFailover: false, + enableFindAndModifyImageCollection: false + }); + runTest(st, restartShard0Func, { + runFindAndModifyWithPreOrPostImage: true, + abortTxnAfterFailover: true, + enableFindAndModifyImageCollection: false + }); + + st.stop(); +} })(); diff --git a/src/mongo/db/repl/oplog.cpp b/src/mongo/db/repl/oplog.cpp index b684de939ec..e01f917aa15 100644 --- a/src/mongo/db/repl/oplog.cpp +++ b/src/mongo/db/repl/oplog.cpp @@ -292,7 +292,7 @@ void writeToImageCollection(OperationContext* opCtx, UpdateRequest request; request.setNamespaceString(NamespaceString::kConfigImagesNamespace); request.setQuery( - BSON("_id" << imageEntry.get_id().toBSON() << "ts" << BSON("$lt" << imageEntry.getTs()))); + BSON("_id" << imageEntry.get_id().toBSON() << "ts" << BSON("$lte" << imageEntry.getTs()))); request.setUpsert(*upsertConfigImage); request.setUpdateModification( write_ops::UpdateModification::parseFromClassicUpdate(imageEntry.toBSON())); |