question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Keycloak unable to start using legacy JPA storage with CockroachDB

See original GitHub issue

Describe the bug

When using CockroachDB with the legacy JPA storage, Keycloak fails to start with the following error:

2022-02-16 14:00:54,681 ERROR [org.keycloak.connections.jpa.updater.liquibase.LiquibaseJpaUpdaterProvider] (ServerService Thread Pool -- 58) Error has occurred while updating the database: liquibase.exception.LiquibaseException: liquibase.exception.MigrationFailedException: Migration failed for change set META-INF/jpa-changelog-1.3.0.xml::1.3.0::bburke@redhat.com:
     Reason: liquibase.exception.DatabaseException: ERROR: relation "user_required_action" (127): unimplemented: primary key dropped without subsequent addition of new primary key in same transaction
  Hint: You have attempted to use a feature that is not yet implemented.
See: https://go.crdb.dev/issue-v/48026/v21.2 [Failed SQL: (0) ALTER TABLE public.USER_REQUIRED_ACTION DROP CONSTRAINT CONSTRAINT_2]

This happens because CockroachDB doesn’t allow a primary key to be dropped without adding a new primary key in the same transaction. Liquibase commits changes to the schema one by one, so all changesets that use the dropPrimaryKey change are incompatible with CockroachDB.

Version

17.0.0

Expected behavior

Keycloak should be able to start using CockroachDB

Actual behavior

When using CockroachDB the server fails to start

How to Reproduce?

Run KeycloakServer with the legacy JPA providers using a configuration that connects to a CockroachDB. It uses the Postgres driver so the config is very similar to that of Postgres. Simply adjust the connection URL with the correct host/port and it should work.

If done right, Keycloak will attempt to process the legacy changelogs and it will fail once it finds a changeset that attempts to drop a primary key.

Anything else?

No response

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:32 (16 by maintainers)

github_iconTop GitHub Comments

1reaction
pedroigorcommented, May 24, 2022

@xgp @sguilhen Does it make sense to disable JTA? We have some databases that only work when JTA is disabled but this is usually because they are lacking JTA support.

Not sure if it applies here but I think is worth trying it out. To disable JTA, you should set the transaction-xa-enabled option to false as well as make sure the driver is also not XA.

1reaction
sguilhencommented, May 24, 2022

Hi @xgp , thanks for the info and for the work you’ve put into this. If I’m not mistaken, the actual JPA transaction is already wrapped as a KeycloakTransaction and is enlisted here:

https://github.com/keycloak/keycloak/blob/main/model/jpa/src/main/java/org/keycloak/connections/jpa/DefaultJpaConnectionProviderFactory.java#L104

Perhaps you can work with this JpaKeycloakTransaction that wraps the actual JPA transaction to add the retry logic?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Keycloak 19.0.0 released
Keycloak is an open source identity and access management solution.
Read more >
Clarify `transaction-xa-enabled` and add `transaction-jta ...
Description The use of transaction-xa-enabled is misleading, ... Keycloak unable to start using legacy JPA storage with CockroachDB #10430.
Read more >
keycloak postgres 14 | The Search Engine You Control
Run KeycloakServer with the legacy JPA providers using a configuration that connects to a CockroachDB. It uses the Postgres driver so the config...
Read more >
Migrate Your Database to CockroachDB
Unimplemented features. Differences from other databases. If you are migrating from a PostgreSQL database, use the CockroachDB MOLT (Migrate Off Legacy ...
Read more >
2018-January.txt - Jboss List Archives
Result is that each application which use Keycloak's adapter throws "Didn't find publicKey for ... LockAcquisitionException: could not execute > statement ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found