Skip to content

[core] Ensuring JDBC connection is not stale before using it#7470

Open
junmuz wants to merge 1 commit intoapache:masterfrom
junmuz:jdbc_conn_validation
Open

[core] Ensuring JDBC connection is not stale before using it#7470
junmuz wants to merge 1 commit intoapache:masterfrom
junmuz:jdbc_conn_validation

Conversation

@junmuz
Copy link
Contributor

@junmuz junmuz commented Mar 18, 2026

Purpose

This change ensure connection is valid before it is used for locking or cataloging purposes. Changes made include

  1. paimon-common/.../client/ClientPool.java
  • Added a reconnect(C client) hook in ClientPoolImpl that subclasses can override
  • Called it in run() before executing the action — the reassignment to client ensures the valid connection is what goes back into the deque via addFirst
  1. paimon-core/.../jdbc/JdbcClientPool.java
  • Stored connectionSupplier as a field for creating fresh connections
  • Overrode reconnect() to validate via isClosed() and isValid(5), replacing stale connections
  • Added closeQuietly() helper for safe cleanup of dead connections
  1. paimon-core/.../jdbc/JdbcClientPoolTest.java (new)
  • testValidConnectionIsReused — a healthy connection is returned as-is from the pool (same object identity)
  • testClosedConnectionIsReplaced — a closed connection triggers creation of a fresh one
  • testReplacedConnectionIsReturnedToPool — the fresh replacement goes back into the pool and is reused on subsequent calls
  • testActionIsExecutedOnValidConnection — after replacing a stale connection, the action can execute real SQL successfully

Issue: 7474

Tests

There are new tests added that will ensure the change works as expected

API and Format

N/A

Documentation

No

Generative AI tooling

Generated-by: Claude with opus-4.6

@junmuz junmuz force-pushed the jdbc_conn_validation branch from 2f2cd5c to e66b7ee Compare March 18, 2026 14:25
@junmuz junmuz marked this pull request as ready for review March 18, 2026 16:02
@junmuz junmuz force-pushed the jdbc_conn_validation branch from e66b7ee to 9a5e2ce Compare March 18, 2026 17:46
@junmuz
Copy link
Contributor Author

junmuz commented Mar 18, 2026

@JingsongLi can you review the PR? The details are mentioned in the issue and there are test cases for covering the scenario.

@junmuz junmuz changed the title Ensuring JDBC connection is not stale before using it [core] Ensuring JDBC connection is not stale before using it Mar 19, 2026
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.

1 participant