Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 7875 #7910

Draft
wants to merge 3 commits into
base: release-13.0
Choose a base branch
from
Draft

Fix 7875 #7910

wants to merge 3 commits into from

Conversation

codeforall
Copy link

Fix Deadlock with transaction recovery is possible during Citus upgrades (#7875)
   
Currently, RecoverWorkerTransactions() creates a new connection for each worker node and then performs transaction recovery by reading and locking the pg_dist_transaction catalog table until the end of the transaction. When RecoverTwoPhaseCommits() calls RecoverWorkerTransactions() for each worker node, the lock acquisition order between pg_dist_authinfo and pg_dist_transaction can reverse on alternate iterations.This reversal can lead to a deadlock if any concurrent process requires locks on these catalog tables—a situation that has surfaced during the Citus upgrade workflow.To resolve this, we now pre-establish all worker node connections upfront.
This change ensures that RecoverWorkerTransactions() operates with a single, consistent distributed catalog table connection, thereby always acquiring locks on pg_dist_authinfo and pg_dist_transaction in the correct order and preventing potential deadlocks during extension updates or similar operations.
The PR also reverts the commit that disabled the relevant test cases,

Copy link

codecov bot commented Feb 24, 2025

Codecov Report

Attention: Patch coverage is 0% with 12 lines in your changes missing coverage. Please review.

Project coverage is 1.22%. Comparing base (c55bc8c) to head (ca8cb7a).
Report is 21 commits behind head on release-13.0.

❌ Your patch check has failed because the patch coverage (0.00%) is below the target coverage (75.00%). You can increase the patch coverage or adjust the target coverage.
❌ Your project check has failed because the head coverage (1.22%) is below the target coverage (87.50%). You can increase the head coverage or adjust the target coverage.

❗ There is a different number of reports uploaded between BASE (c55bc8c) and HEAD (ca8cb7a). Click for more details.

HEAD has 108 uploads less than BASE
Flag BASE (c55bc8c) HEAD (ca8cb7a)
14_regress_check-pytest 1 0
16_regress_check-pytest 1 0
_upgrade 25 0
14_15_upgrade 1 0
15_regress_check-follower-cluster 1 0
16_17_upgrade 1 0
15_17_upgrade 1 0
15_16_upgrade 1 0
14_regress_check-columnar-isolation 1 0
17_regress_check-pytest 1 0
15_regress_check-pytest 1 0
16_regress_check-columnar-isolation 1 0
17_regress_check-follower-cluster 1 0
14_17_upgrade 1 0
14_regress_check-enterprise-isolation-logicalrep-3 1 0
15_regress_check-enterprise-isolation-logicalrep-3 1 0
15_regress_check-columnar-isolation 1 0
16_regress_check-follower-cluster 1 0
15_regress_check-columnar 1 0
16_regress_check-enterprise-isolation-logicalrep-3 1 0
17_regress_check-enterprise-isolation-logicalrep-3 1 0
14_regress_check-follower-cluster 1 0
15_regress_check-split 1 0
17_regress_check-enterprise-failure 1 0
17_regress_check-query-generator 1 0
17_regress_check-columnar-isolation 1 0
15_regress_check-query-generator 1 0
14_regress_check-enterprise-failure 1 0
16_regress_check-split 1 0
16_regress_check-enterprise-failure 1 0
17_regress_check-split 1 0
15_regress_check-enterprise-failure 1 0
16_regress_check-query-generator 1 0
14_regress_check-split 1 0
15_regress_check-enterprise-isolation-logicalrep-2 1 0
16_regress_check-enterprise-isolation-logicalrep-2 1 0
15_regress_check-enterprise 1 0
16_regress_check-columnar 1 0
17_regress_check-columnar 1 0
14_regress_check-vanilla 1 0
17_regress_check-enterprise-isolation 1 0
14_regress_check-enterprise-isolation-logicalrep-1 1 0
17_regress_check-vanilla 1 0
16_regress_check-failure 1 0
17_regress_check-multi-mx 1 0
15_regress_check-multi-mx 1 0
14_regress_check-enterprise-isolation 1 0
14_regress_check-query-generator 1 0
14_regress_check-enterprise-isolation-logicalrep-2 1 0
16_regress_check-operations 1 0
17_regress_check-operations 1 0
15_regress_check-operations 1 0
14_regress_check-operations 1 0
16_regress_check-isolation 1 0
15_regress_check-isolation 1 0
17_regress_check-isolation 1 0
15_regress_check-enterprise-isolation 1 0
14_regress_check-multi 1 0
14_regress_check-isolation 1 0
14_regress_check-multi-mx 1 0
15_cdc_installcheck 1 0
16_regress_check-multi-mx 1 0
16_regress_check-vanilla 1 0
16_cdc_installcheck 1 0
17_regress_check-enterprise 1 0
16_regress_check-multi-1 1 0
15_regress_check-multi-1 1 0
17_cdc_installcheck 1 0
14_regress_check-multi-1 1 0
14_regress_check-enterprise 1 0
14_regress_check-failure 1 0
15_regress_check-vanilla 1 0
17_regress_check-enterprise-isolation-logicalrep-1 1 0
15_regress_check-failure 1 0
16_regress_check-enterprise 1 0
17_regress_check-failure 1 0
15_regress_check-enterprise-isolation-logicalrep-1 1 0
16_regress_check-enterprise-isolation 1 0
16_regress_check-enterprise-isolation-logicalrep-1 1 0
14_regress_check-columnar 1 0
15_regress_check-multi 1 0
16_regress_check-multi 1 0
17_regress_check-multi 1 0
14_16_upgrade 1 0
Additional details and impacted files
@@               Coverage Diff                @@
##           release-13.0   #7910       +/-   ##
================================================
- Coverage         89.48%   1.22%   -88.26%     
================================================
  Files               276     276               
  Lines             60063   59391      -672     
  Branches           7524    7412      -112     
================================================
- Hits              53747     729    -53018     
- Misses             4166   58581    +54415     
+ Partials           2150      81     -2069     

…des (citusdata#7875)

Currently, RecoverWorkerTransactions() creates a new connection for each worker
node and then performs transaction recovery by reading and locking the
pg_dist_transaction catalog table until the end of the transaction.
When RecoverTwoPhaseCommits() calls RecoverWorkerTransactions() for each worker
node, the lock acquisition order between pg_dist_authinfo and
pg_dist_transaction can reverse on alternate iterations.
This reversal can lead to a deadlock if any concurrent process requires locks
on these catalog tables—a situation that has surfaced during the
Citus upgrade workflow.

To resolve this, we now pre-establish all worker node connections upfront.
This change ensures that RecoverWorkerTransactions() operates with a single,
consistent distributed catalog table connection, thereby always acquiring locks
on pg_dist_authinfo and pg_dist_transaction in the correct order and preventing
potential deadlocks during extension updates or similar operations.
Prepared transactions on the local node are initiated and managed by a
remote worker in the cluster. As such, we now only call
RecoverWorkerTransactions for remote nodes, ensuring that transaction
recovery is handled by the appropriate node.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant