8000 Make the emulated "on conflict" upserts race-free on SQL Server and Oracle by ahus1 · Pull Request #54825 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content

Make the emulated "on conflict" upserts race-free on SQL Server and Oracle - #54825

Draft
ahus1 wants to merge 1 commit into
keycloak:release/26.8from
ahus1:is-54240-backport-26.8
Draft

ahus1 wants to merge 1 commit into
keycloak:release/26.8from
ahus1:is-54240-backport-26.8

Conversation

@ahus1
@ahus1 ahus1 commented Nov 6, 2026
Copy link
Copy Markdown
Member
  • Lock the MERGE target of the emulated "on conflict" upsert on SQL Server

Without a lock hint, two concurrent upserts of the same new key could
both take "when not matched", and one failed with a primary key
violation (2627). Add HOLDLOCK to the MERGE target.

  • Make the emulated "on conflict" upserts race-free on Oracle

MERGE reads the target with a consistent read, so a concurrent insert of
the same key made it fail with ORA-00001. Render "do nothing" as an
INSERT with the IGNORE_ROW_ON_DUPKEY_INDEX hint, and replace the
conditional "do update ... where expired" upserts of single-use objects
and revoked tokens with "delete if expired, then insert do nothing".

(cherry picked from commit f80eb3b)

…racle

* Lock the MERGE target of the emulated "on conflict" upsert on SQL Server

Without a lock hint, two concurrent upserts of the same new key could
both take "when not matched", and one failed with a primary key
violation (2627). Add HOLDLOCK to the MERGE target.

* Make the emulated "on conflict" upserts race-free on Oracle

MERGE reads the target with a consistent read, so a concurrent insert of
the same key made it fail with ORA-00001. Render "do nothing" as an
INSERT with the IGNORE_ROW_ON_DUPKEY_INDEX hint, and replace the
conditional "do update ... where expired" upserts of single-use objects
and revoked tokens with "delete if expired, then insert do nothing".

(cherry picked from commit f80eb3b)

Signed-off-by: Semih702 <semih702do@gmail.com>
Signed-off-by: Alexander Schwartz <alexander.schwartz@ibm.com>
Co-authored-by: Alexander Schwartz <alexander.schwartz@ibm.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

0