Description
MyeongHyeonLee opened DATAJDBC-493 and commented
Thank you.
An update deadlock issue has been fixed. DATAJDBC-488
However, Deadlock issues still exist when Update and Delete are executed in concurrent.
The deletion scenario also deletes the reference data first, as in the previous update.
- Delete References
- Delete Root
So Deadlock can happen.
time 1 | time 2 | result | |
---|---|---|---|
TX1 UPDATE | UPDATE Root | ||
(Acquire Root Table LOCK) | DELETE References | ||
(Waiting TX2 Reference Table LOCK) | DEAD LOCK | ||
WITH | |||
TX2 | |||
TX2 DELETE | DELETE References | ||
(Acquire Reference Table LOCK) | DELETE Root | ||
(Waiting TX1 Root Table LOCK) | DEAD LOCK | ||
WITH | |||
TX1 |
Unlike Update, it does not solve the problem by changing the execution order.
There may be an FK constraint between the Root and the Reference table.
- Delete Root (FK Violation)
- Delete References
In order to solve the deadlock problem, LOCK must be acquired first in the root table.
- UPDATE root SET id = :id WHERE id = :id; (Acquire Root Table LOCK)
- Delete References
- Delete Root
OR
- SELECT 1 FROM root WHERE id = :id FOR UPDATE (Acquire Root Table LOCK)
- Delete References
- Delete Root
Please comment on which solution is right for you.
I wrote failing test for this.
And the two solutions suggested above pass this failing test.
Affects: 2.0 M3 (Neumann)
Referenced from: pull request #195