-
Notifications
You must be signed in to change notification settings - Fork 502
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
Debug deadlock while applying DB migrations #4588
Comments
What I'm going to propose might be an overkill : |
Yes, this is exactly the purpose of #4587. There is no other way to prevent deadlocks if ingestion is running along db migations. |
Upon releasing v2.22.0, it appears that non-ingesting instances are trying to write to the read-only database. The error during deployment via deployinator was:
Is it possible that the PR at #4587 is triggering that? The workaround was to run the Restart job after running the Install job, as it seems that restarting the service does not attempt to apply any migrations. |
this is actually a pre-existing issue #4580 which was fixed by #4664 |
What version are you using?
2.20.0
What did you do?
Apply
58_add_index_by_id_optimization.sql
migration file while ingestion is running on another ingesting instance.What did you expect to see?
No error.
What did you see instead?
Deadlock error:
There are two things that are important to remember: 1. the migrations are run in a db transaction and 2. because we have multiple ingesting instance, ingestion is running along db migrations (also in a DB transaction). This is the chain of events I think that leads to deadlock:
CREATE INDEX
query in the migration file acquiresShareLock
onhistory_operation_claimable_balances
(this lock is going to be released at the end of transaction).INSERT
a row intohistory_operation_liquidity_pools
and by doing this acquiresRowExclusiveLock
(it conflicts withShareLock
and is also released at the end of transaction).CREATE INDEX
onhistory_operation_liquidity_pools
is executed, againShareLock
acquire attempt but onhistory_operation_liquidity_pools
table and needs to wait until ingestion commits because there’s already a conflicting lock on this table.INSERT
a new row intohistory_operation_claimable_balances
but waits because in step 1 aShareLock
was acquired.I created a simple local repro.
session 1:
session 2:
(the queries within txs are run one after another in two sessions: S1, S2, S1, S2)
The text was updated successfully, but these errors were encountered: