Fix compareAndSwap() in SQLMetadataConnector#7661
Conversation
gianm
left a comment
There was a problem hiding this comment.
Nice catch!!
Do we need similar changes in IndexerSQLMetadataStorageCoordinator's announceHistoricalSegments method? There's a similar kind of CAS going on there.
|
Marking this WIP, while testing just found that Postgres has somewhat different behavior from Derby/MySQL: https://www.postgresql.org/docs/10/transaction-iso.html#XACT-REPEATABLE-READ
So I'll need to add retries for that case for postgres
I'll take a look at that, thanks! |
|
Added handling for Postgres serialization_failure error, removed WIP tag |
| * the calling code will attempt retries. | ||
| */ | ||
| private boolean checkRootCauseForPSQLSerializationFailure( | ||
| Throwable root |
There was a problem hiding this comment.
nit: method argument doesn't seem like it needs to be on a new line... alternatively any reason not to just inline this whole method in the compareAndSwap method?
There was a problem hiding this comment.
With the somewhat non-trivial boolean conditions I felt like it looked nicer as a separate method
Does that code need any fixes ? |
I'm still looking into that, but it can be a separate PR if there are similar issues there. |
* Fix compareAndSwap() in SQLMetadataConnector * Catch serialization_failure and retry for Postgres
* Fix compareAndSwap() in SQLMetadataConnector * Catch serialization_failure and retry for Postgres
* Fix compareAndSwap() in SQLMetadataConnector * Catch serialization_failure and retry for Postgres
* Fix compareAndSwap() in SQLMetadataConnector * Catch serialization_failure and retry for Postgres
This PR fixes SQLMetadataConnector.compareAndSwap() by adding " FOR UPDATE" to the initial read and using REPEATABLE_READ isolation level for the transaction.
This method is used by
druid-basic-securityextension APIs, and the broken CAS method was causing issues where some concurrent update requests (such as assigning roles to a user) failed to take effect.A test is added that concurrently makes 100 role assignment requests and later concurrently removes the 100 roles.