Skip to content

KNOX-3536: JDBCTokenStateService fails on PostgreSQL in HA: duplicate… - #1477

Merged
hanicz merged 1 commit into
apache:masterfrom
hanicz:KNOX-3536
Oct 29, 2026
Merged

hanicz merged 1 commit into
apache:masterfrom
hanicz:KNOX-3536

Conversation

@hanicz

@hanicz hanicz commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

… key on pg_type_typname_nsp_index during concurrent table creation

KNOX-3536 - JDBCTokenStateService fails on PostgreSQL in HA: duplicate key on pg_type_typname_nsp_index during concurrent table creation

What changes were proposed in this pull request?

The Postgres token DDL scripts wrap CREATE TABLE IF NOT EXISTS in pg_advisory_lock / pg_advisory_unlock. JDBCUtils.createTableFromSQL sends the whole script in a single Statement.execute(), and PostgreSQL runs it as one implicit transaction. As a result, the unlock happens before the CREATE TABLE is committed. When several Knox instances start at the same time, another instance can then take the lock, fail to see the uncommitted table, and fail with duplicate key value violates unique constraint "pg_type_typname_nsp_index".

This PR switches both scripts (createKnoxTokenDatabaseTablePostgres.sql, createKnoxTokenMetadataDatabaseTablePostgres.sql) to pg_advisory_xact_lock(12345) and removes the explicit unlock. That lock is released only after the transaction commits.

How was this patch tested?

Tested locally the script on a postgres 16 db running in docker

… key on pg_type_typname_nsp_index during concurrent table creation

@lmccay lmccay left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM
+1

@hanicz
hanicz merged commit fa9e89a into apache:master Oct 29, 2026
2 checks passed
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