forked from yugabyte/yugabyte-db
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[yugabyte#13222] YSQL: Ensure that the list of aborted sub-txns is no…
…t spuriously removed by asynchronous heartbeats Summary: 4fb1676 added logic that enabled transactions to ignore conflicting intents of aborted sub-txns. This was done by asynchronously sending the aborted sub-txn list to the transactions coordinator using the existing heartbeats. The aborted sub-txns list is then used by transaction participants during conflicting resolution. 85ac8d8, which came later, ensured that YSQL synchronously updates the list of aborted sub-txns on the transaction status record of a status tablet when some sub-txn is rolled back. This was to eliminate any window where a transaction might face a conflict error when another transaction's aborted intents. But the second commit introduces the following buggy line in PendingReplicationFinished() that causes the aborted sub-txns list to disappear in the next asynchronous heartbeat from YSQL to the status tablet: `aborted_ = data.state.aborted();`. The second commit removed the aborted sub-txns list from the asynchronous heartbeats. And due to the above buggy line, the empty list replaces the aborted sub-txn list on the status record in the next heartbeat. The implication of this is: other transactions are not able to ignore conflicting intents that are part of aborted sub-txns. The two tests introduced in 4fb1676 are moved to the isolation_regress test suite: (1) testIgnoresIntentOfRolledBackSavepointCrossTxn (2) testIgnoresLockOnlyConflictOfCommittedTxn The bug introduced by 85ac8d8 is tested now by an extra case in testIgnoresIntentOfRolledBackSavepointCrossTxn: a sleep is introduced before the second transaction attempts to insert the same row. Without the fix, this case fails since the sleep is enough for an asynchronous heartbeat to clear the aborted sub-txn list and cause the second transation to face a conflict error. Test Plan: ./yb_build.sh --java-test org.yb.pgsql.TestPgIsolationRegress#isolationRegress ./yb_build.sh --java-test org.yb.pgsql.TestPgIsolationRegress#withDelayedTxnApply Reviewers: rsami Subscribers: yql Differential Revision: https://phabricator.dev.yugabyte.com/D18226
- Loading branch information
Showing
7 changed files
with
169 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
...y-conflict-of-committed-txn-is-ignored-even-when-modification-conflict-is-rolled-back.out
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
Parsed test spec with 2 sessions | ||
|
||
starting permutation: s1_select s2_select s1_savepoint_a s1_update_k_1 s1_rollback_to_a s1_lock_k_1 s1_update_k_3 s1_commit s2_update_k_1 s2_commit s1_select | ||
step s1_select: SELECT * FROM t; | ||
k v | ||
|
||
5 0 | ||
1 0 | ||
6 0 | ||
7 0 | ||
9 0 | ||
10 0 | ||
4 0 | ||
2 0 | ||
8 0 | ||
3 0 | ||
step s2_select: SELECT * FROM t; | ||
k v | ||
|
||
5 0 | ||
1 0 | ||
6 0 | ||
7 0 | ||
9 0 | ||
10 0 | ||
4 0 | ||
2 0 | ||
8 0 | ||
3 0 | ||
step s1_savepoint_a: SAVEPOINT a; | ||
step s1_update_k_1: UPDATE t SET v=1 WHERE k=1; | ||
step s1_rollback_to_a: ROLLBACK TO a; | ||
step s1_lock_k_1: SELECT * FROM t WHERE k=1 FOR UPDATE; | ||
k v | ||
|
||
1 0 | ||
step s1_update_k_3: UPDATE t SET v=1 WHERE k=3; | ||
step s1_commit: COMMIT; | ||
step s2_update_k_1: UPDATE t SET v=2 WHERE k=1; | ||
step s2_commit: COMMIT; | ||
step s1_select: SELECT * FROM t; | ||
k v | ||
|
||
5 0 | ||
1 2 | ||
6 0 | ||
7 0 | ||
9 0 | ||
10 0 | ||
4 0 | ||
2 0 | ||
8 0 | ||
3 1 |
33 changes: 33 additions & 0 deletions
33
...postgres/src/test/isolation/expected/ignore-intent-of-rolled-back-savepoint-cross-txn.out
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
Parsed test spec with 2 sessions | ||
|
||
starting permutation: s1_insert_1_1 s1_savepoint_a s1_insert_2_1 s1_rollback_to_a s2_insert_2_2 s1_commit s2_commit s1_select | ||
step s1_insert_1_1: INSERT INTO t VALUES (1, 1); | ||
step s1_savepoint_a: SAVEPOINT a; | ||
step s1_insert_2_1: INSERT INTO t VALUES (2, 1); | ||
step s1_rollback_to_a: ROLLBACK TO a; | ||
step s2_insert_2_2: INSERT INTO t VALUES (2, 2); | ||
step s1_commit: COMMIT; | ||
step s2_commit: COMMIT; | ||
step s1_select: SELECT * FROM t; | ||
key v | ||
|
||
1 1 | ||
2 2 | ||
|
||
starting permutation: s1_insert_1_1 s1_savepoint_a s1_insert_2_1 s1_rollback_to_a s1_sleep s2_insert_2_2 s1_commit s2_commit s1_select | ||
step s1_insert_1_1: INSERT INTO t VALUES (1, 1); | ||
step s1_savepoint_a: SAVEPOINT a; | ||
step s1_insert_2_1: INSERT INTO t VALUES (2, 1); | ||
step s1_rollback_to_a: ROLLBACK TO a; | ||
step s1_sleep: SELECT pg_sleep(2); | ||
pg_sleep | ||
|
||
|
||
step s2_insert_2_2: INSERT INTO t VALUES (2, 2); | ||
step s1_commit: COMMIT; | ||
step s2_commit: COMMIT; | ||
step s1_select: SELECT * FROM t; | ||
key v | ||
|
||
1 1 | ||
2 2 |
51 changes: 51 additions & 0 deletions
51
...-conflict-of-committed-txn-is-ignored-even-when-modification-conflict-is-rolled-back.spec
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# This tests ensures the following guarantee: | ||
# | ||
# 1. Txn 1 registers a savepoint and modifies a row | ||
# 2. Txn 1 rolls back to the savepoint, undoing the modification | ||
# 3. Txn 1 then locks the same row | ||
# 4. Txn 1 commits but is yet to apply the intents on the txn participant. | ||
# 5. Another transaction tries to modify the same row. This new transaction sees 2 conflicts - a | ||
# conflict with the modification from Txn 1 and a conflict with the lock-only intent from Txn 1. | ||
# The conflict with the modification should be ignored since it is part of an aborted sub-txn. | ||
# The conflict with the lock-only intent should also be ignored since the Txn 1 has committed | ||
# and no longer holds the lock. | ||
# | ||
# This scenario is only tested with "org.yb.pgsql.TestPgIsolationRegress#withDelayedTxnApply" which | ||
# uses TEST_inject_sleep_before_applying_intents_ms to induce a delay before applying intents. This | ||
# is needed for step (4) above. Without this, the lock-only intent would be removed and the second | ||
# transaction wouldn't see it (and we want to test the fact that the second transaction should | ||
# ignore it after seeing it in intents db because it is a lock-only intent). | ||
# | ||
# This test was introduced due to a review comment in 4fb1676a785319fa35e2d75241a870e3115f1637. The | ||
# comment was due to the following issue in the work in progress code: a modification intent that | ||
# was part of an aborted sub-txn was causing a non-aborted lock-only intent of an aborted txn to | ||
# conflict with other transactions. | ||
|
||
setup | ||
{ | ||
CREATE TABLE t (k INT PRIMARY KEY, v INT); | ||
INSERT INTO t SELECT generate_series(1, 10), 0; | ||
} | ||
|
||
teardown | ||
{ | ||
DROP TABLE t; | ||
} | ||
|
||
session "s1" | ||
setup { BEGIN TRANSACTION ISOLATION LEVEL REPEATABLE READ; } | ||
step "s1_select" { SELECT * FROM t; } | ||
step "s1_savepoint_a" { SAVEPOINT a; } | ||
step "s1_update_k_1" { UPDATE t SET v=1 WHERE k=1; } | ||
step "s1_rollback_to_a" { ROLLBACK TO a; } | ||
step "s1_lock_k_1" { SELECT * FROM t WHERE k=1 FOR UPDATE; } | ||
step "s1_update_k_3" { UPDATE t SET v=1 WHERE k=3; } | ||
step "s1_commit" { COMMIT; } | ||
|
||
session "s2" | ||
setup { BEGIN TRANSACTION ISOLATION LEVEL REPEATABLE READ; } | ||
step "s2_select" { SELECT * FROM t; } | ||
step "s2_update_k_1" { UPDATE t SET v=2 WHERE k=1; } | ||
step "s2_commit" { COMMIT; } | ||
|
||
permutation "s1_select" "s2_select" "s1_savepoint_a" "s1_update_k_1" "s1_rollback_to_a" "s1_lock_k_1" "s1_update_k_3" "s1_commit" "s2_update_k_1" "s2_commit" "s1_select" |
27 changes: 27 additions & 0 deletions
27
src/postgres/src/test/isolation/specs/ignore-intent-of-rolled-back-savepoint-cross-txn.spec
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
setup | ||
{ | ||
CREATE TABLE t (key INT PRIMARY KEY, v INT); | ||
} | ||
|
||
teardown | ||
{ | ||
DROP TABLE t; | ||
} | ||
|
||
session "s1" | ||
setup { BEGIN; } | ||
step "s1_insert_1_1" { INSERT INTO t VALUES (1, 1); } | ||
step "s1_savepoint_a" { SAVEPOINT a; } | ||
step "s1_insert_2_1" { INSERT INTO t VALUES (2, 1); } | ||
step "s1_rollback_to_a" { ROLLBACK TO a; } | ||
step "s1_commit" { COMMIT; } | ||
step "s1_select" { SELECT * FROM t; } | ||
step "s1_sleep" { SELECT pg_sleep(2); } | ||
|
||
session "s2" | ||
setup { BEGIN; } | ||
step "s2_insert_2_2" { INSERT INTO t VALUES (2, 2); } | ||
step "s2_commit" { COMMIT; } | ||
|
||
permutation "s1_insert_1_1" "s1_savepoint_a" "s1_insert_2_1" "s1_rollback_to_a" "s2_insert_2_2" "s1_commit" "s2_commit" "s1_select" | ||
permutation "s1_insert_1_1" "s1_savepoint_a" "s1_insert_2_1" "s1_rollback_to_a" "s1_sleep" "s2_insert_2_2" "s1_commit" "s2_commit" "s1_select" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters