-
Notifications
You must be signed in to change notification settings - Fork 157
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
Deadlock during concurrent updates on Derby #2420
Comments
Previously this was flagged as a db2-only test, which helped contribute to us missing this issue. Additionally, this test was written to highlight a potential issue but didn't yet take into account our solution which is to return a 409 for one of the updates (in the case of a conflict). The updated test will retry on a tight loop, ensuring that we can continue to make progress in the face of contentious PUT requests to the same resource. Signed-off-by: Lee Surprenant <lmsurpre@us.ibm.com>
Previously this was flagged as a db2-only test, which helped contribute to us missing this issue. Additionally, this test was written to highlight a potential issue but didn't yet take into account our solution which is to return a 409 for one of the updates (in the case of a conflict). The updated test will retry on a tight loop, ensuring that we can continue to make progress in the face of contentious PUT requests to the same resource. Signed-off-by: Lee Surprenant <lmsurpre@us.ibm.com>
Previously this was flagged as a db2-only test, which helped contribute to us missing this issue. Additionally, this test was written to highlight a potential issue but didn't yet take into account our solution which is to return a 409 for one of the updates (in the case of a conflict). The updated test will retry on a tight loop, ensuring that we can continue to make progress in the face of contentious PUT requests to the same resource. Signed-off-by: Lee Surprenant <lmsurpre@us.ibm.com>
Signed-off-by: Lee Surprenant <lmsurpre@us.ibm.com>
Signed-off-by: Lee Surprenant <lmsurpre@us.ibm.com>
I updated our existing ConcurrentUpdateTest to retry in the case of a 409 Conflict response. Specifically, the test forks 12 threads (easy to change) and asks each one to update the same resource in parallel. Because each thread will retry (in a tight loop) upon failure, this shows that one thread should always win (i.e. it continues to make progress despite the contention), that we avoid a deadlock in such cases, and that no updates are lost. |
The check to catch the version conflict was a relatively simple fix. Cleaned things up a bit because for this implementation there's no need to support an asserted version id (which might not be the latest version id - useful for logical replication). However the fix did expose a deadlock scenario for Derby caused by the default isolation level being TRANSACTION_REPEATABLE_READ. This resulted in shared locks lingering on rows which were selected when reading the current version of the resource earlier in the transaction. In Derby, these locks are not compatible with the exclusive lock requested by the UPDATE xx_logical_resources statement. The resulting deadlock graph looks something like this:
The solution is to set the isolation level for Derby datasources in openliberty:
As part of the effort to uncover the deadlock, the stored procedure implementations were simplified by removing an update on xx_logical_resources when the resource was new. The new solution allocates the resource_id early and uses it to set the xx_logical_resources.current_resource_id column before the actual resource row is created. This should be particularly helpful for PostgreSQL, because it avoids creating a tombstone which then needs to be vacuumed.
Originally posted by @punktilious in #2405 (comment)
The text was updated successfully, but these errors were encountered: