Repository navigation
GH-11558: DefaultLockRepository: ON CONFLICT DO NOTHING on PostgreSQL - #11559
Open
Adrastopoulos wants to merge 1 commit into
Open
Adrastopoulos wants to merge 1 commit into
Adrastopoulos wants to merge 1 commit into
Conversation
…HING` on PostgreSQL Fixes: spring-projects#11558 On PostgreSQL, every `acquire()` that loses the race for an existing lock fails its `INSERT` on `INT_LOCK_PK`, and the server logs `duplicate key value violates unique constraint` each time. A `LockRegistryLeaderInitiator` candidate does that about once a second. * Append `ON CONFLICT DO NOTHING` to the default insert query on PostgreSQL, as `JdbcMetadataStore` already does for its `putIfAbsent()` query * Leave a query set via `setInsertQuery()` as is, so the documented `getInsertQuery() + " ON CONFLICT DO NOTHING"` does not get the clause twice * Document the new default * Add `PostgresLockRepositoryTests` for a contended `acquire()` Signed-off-by: Gabriel Hall <gabriel.hall@cox.net>
artembilan
requested changes
Oct 19, 2026
artembilan
left a comment
Member
There was a problem hiding this comment.
No complains.
Will be merged next week.
Thank you!
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #11558
afterPropertiesSet()reads the database vendor the wayJdbcMetadataStoredoes, and appendsON CONFLICT DO NOTHINGto the default insert query on PostgreSQL. A query set viasetInsertQuery()is used as is, so the documentedgetInsertQuery() + " ON CONFLICT DO NOTHING"doesn't get the clause twice.acquire()already treats 0 inserted rows as not acquired.PostgresLockRepositoryTestschecks that a contendedacquire()returnsfalseand that the server logs noint_lock_pkviolation; it fails without the change.A database-agnostic alternative is the conditional insert that
JdbcMetadataStoreuses forputIfAbsent()(INSERT ... SELECT ... HAVING COUNT(*)=0), with no vendor check. It changes the default SQL on every database and the parameters of a custom insert query, so it seems to fit a major version better. Happy to switch to it if you prefer.