Skip to content

Support KEYCLOAK_JDBC_PING2 in custom JGroups stacks by injecting the connection factory - #54540

Open
ahus1 wants to merge 4 commits into
keycloak:mainfrom
ahus1:custom-stack-jdbc-ping2
Open

ahus1 wants to merge 4 commits into
keycloak:mainfrom
ahus1:custom-stack-jdbc-ping2

Conversation

@ahus1

@ahus1 ahus1 commented Nov 2, 2026

Copy link
Copy Markdown
Member

Closes #54539

When a custom stack defined in the XML configuration uses KEYCLOAK_JDBC_PING2, the stack is now wrapped in a configurator that injects the JpaConnectionProviderFactory, as for the built-in jdbc-ping stacks.
The JDBC_PING SQL statements and related properties are extracted into a shared helper and applied as defaults, so values set in the XML take precedence.
Unsupported setups fail at startup: stacks loaded from a stack-file, and stacks with cross-site (RELAY2) settings.

The wrapped stack is registered as <stack>-keycloak, as Infinispan rejects duplicate stack names.
The JGroups address is not pre-registered in the JGROUPS_PING table for custom stacks.

Tests cover a stack that extends tcp, removes FD_SOCK2 and replaces MPING, plus default/override precedence, a stack without the protocol, and the cross-site rejection.

@ahus1 ahus1 self-assigned this Nov 2, 2026
@ahus1
ahus1 requested a review from ruchikajha95 November 2, 2026 12:59
@ahus1
ahus1 marked this pull request as ready for review November 3, 2026 14:10
@ahus1
ahus1 requested review from a team as code owners November 3, 2026 14:10
Copilot AI balanced review requested due to automatic review settings November 3, 2026 14:10

Copilot AI 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.

🟡 Changes recommended

The stateless-mode guard still rejects custom stacks containing KEYCLOAK_JDBC_PING2 before reaching the new injection path, preventing valid JDBC-backed configurations from starting.

1 open issue
What changed in this PR

This PR addresses #54539 by enabling custom XML-defined JGroups stacks to use Keycloak’s database-backed discovery while retaining custom protocol settings.

Changes:

  • Wraps custom stacks to inject the database connection factory and apply shared JDBC defaults without overriding XML values.
  • Rejects unsupported file-based and cross-site configurations using KEYCLOAK_JDBC_PING2.
  • Adds custom-stack tests and changes a test protocol ID to avoid registration conflicts.
File Description
model/​infinispan/​src/​test/​java/​org/​keycloak/​spi/​infinispan/​impl/​embedded/​JGroupsConfiguratorCustomStackTest.java Tests factory injection, property precedence, stack preservation, and cross-site rejection.
model/​infinispan/​src/​test/​java/​org/​keycloak/​jgroups/​protocol/​JdbcPing2Test.java Uses a non-conflicting test protocol ID.
model/​infinispan/​src/​main/​java/​org/​keycloak/​spi/​infinispan/​impl/​embedded/​JGroupsConfigurator.java Adds custom-stack wrapping, shared JDBC defaults, and unsupported-configuration checks.

Review effort: Balanced

@ahus1
ahus1 force-pushed the custom-stack-jdbc-ping2 branch from 6ec7b57 to 775be2a Compare November 3, 2026 16:08
Copilot AI balanced review requested due to automatic review settings November 3, 2026 16:08
@ahus1

ahus1 commented Nov 3, 2026

Copy link
Copy Markdown
Member Author

@ruchikajha95 - I needed to rebase the PR due to a merge conflict to the your PR that I merged earlier. CI is still running.

Copilot AI 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.

🟡 Changes recommended

Transport detection can misclassify SHARED_LOOPBACK_PING and bypass the stateless JDBC discovery guard, while wrapper stack-name collisions can cause valid configurations to fail at startup.

2 open issues
1 resolved since last review

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 3, 2026 18:56

Copilot AI 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.

🔵 Needs a closer look

The generated wrapper stack name can collide with an existing embedded or stack-file name, causing startup to fail with a duplicate-stack error.

No open issues 🎉

2 resolved since last review

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 3, 2026 19:01

Copilot AI 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.

🟢 Approval recommended

No active review issues remain for the custom JGroups stack JDBC discovery support.

No open issues 🎉

Review effort: Balanced

@ahus1

ahus1 commented Nov 4, 2026

Copy link
Copy Markdown
Member Author

CI failing due to #54622, waiting for that PR to be merged.

@ahus1
ahus1 force-pushed the custom-stack-jdbc-ping2 branch from b8f0103 to 89034fe Compare November 4, 2026 08:10
Copilot AI balanced review requested due to automatic review settings November 4, 2026 08:10

Copilot AI 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.

🔵 Needs a closer look

The custom-stack path skips address pre-registration that guards against split brain, while tests never start wrapped channels, leaving clustering safety unresolved pending multi-node startup validation against the pinned runtime.

No open issues 🎉

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 4, 2026 19:06

Copilot AI 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.

🔵 Needs a closer look

Human assessment is needed because the negative test does not catch regressions that exempt a TCP-backed stack named test from the stateless JDBC-discovery requirement.

No open issues 🎉

Review effort: Balanced

@ahus1
ahus1 force-pushed the custom-stack-jdbc-ping2 branch from d0d79e8 to 0b6ec37 Compare November 5, 2026 20:04
Copilot AI balanced review requested due to automatic review settings November 5, 2026 20:04

Copilot AI 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.

🟡 Changes recommended

XML SQL overrides targeting another discovery table leave pre-registration rows in Keycloak’s JGROUPS_PING table that the protocol cannot clean up, causing accumulation across restarts.

1 open issue

Review effort: Balanced

@ruchikajha95 ruchikajha95 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 . Thanks @ahus1

ahus1 and others added 4 commits November 12, 2026 17:32
… connection factory

Closes keycloak#54539

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Alexander Schwartz <alexander.schwartz@ibm.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Alexander Schwartz <alexander.schwartz@gmx.net>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Alexander Schwartz <alexander.schwartz@ibm.com>
…C_PING2

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Alexander Schwartz <alexander.schwartz@ibm.com>
@ahus1
ahus1 force-pushed the custom-stack-jdbc-ping2 branch from 0b6ec37 to be57456 Compare November 12, 2026 16:32
Copilot AI balanced review requested due to automatic review settings November 12, 2026 16:32

Copilot AI 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.

🟢 Approval recommended

The review identifies no active issues in the custom-stack JDBC discovery changes.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

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.

Support KEYCLOAK_JDBC_PING2 in custom JGroups stacks by injecting the connection factory

3 participants