Skip to content

[PECOBLR-2321] Result Set Heartbeat / Keep-Alive for Ongoing Query Executions - #1415

Merged
gopalldb merged 39 commits into
mainfrom
design/heartbeat-keep-alive
May 21, 2026
Merged

gopalldb merged 39 commits into
mainfrom
design/heartbeat-keep-alive

Conversation

@gopalldb

@gopalldb gopalldb commented Apr 22, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Design + implementation for PECOBLR-2321: periodic heartbeat polling to keep server-side result state alive while the client consumes results slowly.

Problem

When users read query results slowly (pausing between next() calls), the warehouse can auto-stop after its idle timeout. For inline results (data only on cluster, not uploaded to cloud storage), this means permanent data loss. The user gets errors like INVALID_HANDLE_STATUS or "operation not found".

Solution

A ResultHeartbeatManager that periodically calls GetStatementStatus (SEA) or GetOperationStatus (Thrift) to signal the server that results are still being consumed. Opt-in via EnableHeartbeat=1 connection parameter (default false due to cost implications).

Design doc

docs/design/HEARTBEAT_KEEP_ALIVE.md — includes cross-driver survey, Mermaid diagrams (sequence flows, state machine, class diagram), and detailed lifecycle analysis.

Heartbeat eligibility (skipped when not needed)

Scenario Heartbeat? Reason
SEA cloud fetch (Arrow) Yes Statement must stay alive for URL refresh
Thrift inline (columnar) Yes Data fetched on-demand; server can evict
Thrift cloud fetch Yes Operation handle must stay alive
SEA inline (JSON) No All data loaded into memory at construction
Direct results (CLOSED state) No Server already closed; data fully delivered
Update count (DML) No No result rows; execution polling already kept it alive
Async execution wait No User controls polling via getExecutionResult() — heartbeat starts only when ResultSet is constructed

Error resilience

  • 10 consecutive failures before self-stop
  • Terminal states (CLOSED/ERROR/CANCELED/TIMEDOUT) auto-stop
  • Single success resets failure counter

Zero-leak guarantee

Heartbeat stops in 4 places: next() returns false, ResultSet.close(), Statement.close(), Connection.close()

Implementation

  • New: ResultHeartbeatManager — per-connection manager with ScheduledExecutorService (daemon thread)
  • New: ResultHeartbeatManagerTest — 7 unit tests
  • Modified: DatabricksJdbcUrlParams — EnableHeartbeat (default 0), HeartbeatIntervalSeconds (default 60)
  • Modified: DatabricksConnectionContext — getter methods
  • Modified: DatabricksConnection — creates/shuts down manager
  • Modified: DatabricksResultSet — starts heartbeat in constructor, stops on close/next-false
  • Modified: DatabricksStatement — safety net stop in close()
  • Modified: IDatabricksClient — checkStatementAlive() default method
  • Modified: DatabricksSdkClient — SEA heartbeat via GET /sql/statements/{id}
  • Modified: DatabricksThriftServiceClient — Thrift heartbeat via GetOperationStatus

Design doc for PECOBLR-2321: periodic heartbeat polling to keep
server-side result state alive while the client consumes results
slowly.

Key design points:
- Periodic GetStatementStatus (SEA) / GetOperationStatus (Thrift)
- Opt-in via EnableHeartbeat connection parameter (default false)
- Configurable interval (default 60s, aligned with ADBC C# driver)
- Zero-leak guarantee: stops on ResultSet.close, Statement.close,
  Connection.close, end-of-results, or server terminal state
- Error resilience: 10 consecutive failures before self-stop
- Includes cross-driver survey (ADBC C#, Python, Go, Node.js)
- Mermaid diagrams: sequence flows, state machine, class diagram

Signed-off-by: Gopal Lal <[email protected]>
Co-authored-by: Isaac
Signed-off-by: Gopal Lal <[email protected]>
Add periodic heartbeat polling to keep server-side result state alive
while the client consumes results slowly. Prevents warehouse auto-stop
from destroying in-progress results.

New files:
- ResultHeartbeatManager: per-connection manager with shared
  ScheduledExecutorService (daemon thread). Manages start/stop/shutdown
  lifecycle for heartbeats across all statements.
- ResultHeartbeatManagerTest: 7 unit tests covering lifecycle,
  idempotency, interval, shutdown, re-execution.

Connection parameters:
- EnableHeartbeat (default 0): opt-in to enable heartbeat polling
- HeartbeatIntervalSeconds (default 60): polling interval

Protocol support:
- SEA: GET /sql/statements/{id} via checkStatementAlive()
- Thrift: GetOperationStatus via checkStatementAlive()

Heartbeat eligibility (skipped when not needed):
- SEA inline (InlineJsonResult): all data in memory, no server state
- Update count / metadata results: no data to keep alive
- Direct results: server already closed the operation
- Null execution result: nothing to fetch

Error resilience:
- 10 consecutive failures before self-stop (transient error tolerance)
- Single success resets failure counter
- Terminal states (CLOSED/ERROR/CANCELED/TIMEDOUT) stop heartbeat

Cleanup guarantees (zero leak):
- next() returns false → stop
- ResultSet.close() → stop
- Statement.close() → safety net stop
- Connection.close() → shutdown all

Signed-off-by: Gopal Lal <[email protected]>
Co-authored-by: Isaac
Signed-off-by: Gopal Lal <[email protected]>
Metadata operations (getTables, getColumns, etc.) can return large
result sets that may need heartbeat. Only UPDATE statements are
excluded (they return update count, no data to keep alive).

Signed-off-by: Gopal Lal <[email protected]>
Co-authored-by: Isaac
Signed-off-by: Gopal Lal <[email protected]>
Direct results mean the server already closed the operation and
delivered all data inline. No heartbeat needed — detect via
ExecutionState.CLOSED in the constructor rather than waiting for
the first poll to discover it.

Signed-off-by: Gopal Lal <[email protected]>
Co-authored-by: Isaac
Signed-off-by: Gopal Lal <[email protected]>
- No heartbeat during executeAsync() wait — user controls polling
  via getExecutionResult(). Heartbeat starts only when ResultSet is
  constructed and user begins consuming results.
- Updated eligibility table: SEA inline doesn't need heartbeat
  (all data in memory), added update count row.
- Added execution phase vs consumption phase diagram.

Signed-off-by: Gopal Lal <[email protected]>
Co-authored-by: Isaac
Signed-off-by: Gopal Lal <[email protected]>
@gopalldb gopalldb changed the title [Design] Result Set Heartbeat / Keep-Alive for Ongoing Query Executions [PECOBLR-2321] Result Set Heartbeat / Keep-Alive for Ongoing Query Executions Apr 22, 2026
Signed-off-by: Gopal Lal <[email protected]>
Co-authored-by: Isaac
Signed-off-by: Gopal Lal <[email protected]>
Extract isHeartbeatEligible() as package-visible method for testing.
Add 10 tests covering all eligibility/ineligibility scenarios:

Eligible (heartbeat starts):
- SEA cloud fetch (Arrow) — statement alive for URL refresh
- Thrift inline — data fetched on-demand, server can evict
- Thrift cloud fetch (Arrow) — operation handle alive
- Metadata queries — can return large result sets

Ineligible (heartbeat skipped):
- SEA inline (JSON) — all data in memory
- Direct results (CLOSED) — server already closed
- Update count (DML) — no result rows
- Null execution result — nothing to fetch
- Async PENDING — user controls polling
- Async RUNNING — user controls polling

Signed-off-by: Gopal Lal <[email protected]>
Co-authored-by: Isaac
Signed-off-by: Gopal Lal <[email protected]>
1. consecutiveFailures → AtomicInteger (was plain int written by
   scheduler thread, no happens-before guarantee)

2. Stopped flag prevents RPC on closed client/session. stopHeartbeat
   sets AtomicBoolean flag BEFORE cancel(false). In-flight heartbeat
   tick checks flag before RPC, skips if set. Exceptions during
   shutdown don't count as consecutive failures.

3. Constructor leak: verified startHeartbeatIfEnabled() is already
   the last line of the constructor, after all throwing code. No
   change needed — already safe.

4. HeartbeatIntervalSeconds bounds check: reject <= 0 (use default
   60), warn for > 3600 (heartbeat may not keep operation alive).

Signed-off-by: Gopal Lal <[email protected]>
Co-authored-by: Isaac
Signed-off-by: Gopal Lal <[email protected]>
1. Null-defense on Thrift response: if getOperationState() returns
   null, assume alive and log warning (prevents NPE)

2. Better logging for heartbeat failures: first failure at INFO,
   terminal (10th) failure at WARN with statement ID and error
   message. Users will now see early signals instead of cryptic
   "operation not found" on next()

3. Stop old heartbeat on re-execute: resetForNewExecution() now
   explicitly calls stopHeartbeat(oldStatementId) before clearing
   state. Prevents wasteful 10-failure self-termination of orphaned
   heartbeats

4. Document cloud-fetch prefetch interaction: noted that
   StreamingChunkProvider/RemoteChunkProvider background RPCs act as
   implicit heartbeat. Explicit heartbeat is still useful for gaps
   (all chunks downloaded, prefetch paused, sliding window full)

Signed-off-by: Gopal Lal <[email protected]>
Co-authored-by: Isaac
Signed-off-by: Gopal Lal <[email protected]>
Tests rewritten to be deterministic (CountDownLatch, no Thread.sleep):
- testStoppedFlagSetOnStop: get flag after start, verify set on stop
- testStoppedFlagSetOnShutdown: same pattern, verify set on shutdown
- testStopRacingWithScheduledTick: verify stopped flag prevents RPC
- testShutdownWithBlockedTask: verify shutdownNow fires after 5s
- testReExecutionReplacesHeartbeat: verify old task stops

Fix: startHeartbeat resets stopped flag on new start (was stale
after stop-then-restart cycle).

Add DEBUG log on successful heartbeat start with statementId,
resultType, and interval for support diagnostics.

Signed-off-by: Gopal Lal <[email protected]>
Co-authored-by: Isaac
Signed-off-by: Gopal Lal <[email protected]>
Verified against dogfood warehouse:
- testHeartbeatKeepsResultsAliveDuringSlowConsumption: execute query,
  read first row, pause 15s (3 heartbeats at 5s interval), read
  remaining 99 rows successfully. All 100 rows returned.
- testHeartbeatStopsOnResultSetClose: verify clean shutdown after close

Run with:
  DATABRICKS_HOST=... DATABRICKS_TOKEN=... DATABRICKS_HTTP_PATH=... \
  mvn -pl jdbc-core test -Dtest="HeartbeatIntegrationTest"

Signed-off-by: Gopal Lal <[email protected]>
Co-authored-by: Isaac
Signed-off-by: Gopal Lal <[email protected]>
// Get the stopped flag from the manager — shared between the heartbeat task and
// stopHeartbeat(). Prevents RPC on a just-closed client/session: stopHeartbeat sets
// the flag before cancel(false), so an in-flight tick sees it and skips the RPC.
final java.util.concurrent.atomic.AtomicBoolean stopped = mgr.getStoppedFlag(statementId);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[CRITICAL] Orphan stopped flag — heartbeat RPC never actually fires

The stopped flag is captured here at line 328 before mgr.startHeartbeat(...) is called at line 378. Inside ResultHeartbeatManager.startHeartbeat():

// ResultHeartbeatManager.java
void startHeartbeat(StatementId statementId, Runnable heartbeatTask) {
  ...
  stopHeartbeat(statementId);              // line 63 — REMOVES this flag from map AND sets it to true
  getStoppedFlag(statementId).set(false);  // line 66 — computeIfAbsent creates a NEW AtomicBoolean
  ...
}

So the AtomicBoolean captured by the closure here is the removed/orphaned one — permanently set to true. The new flag in the map (which mgr.stopHeartbeat(...) later mutates from DatabricksResultSet.stopHeartbeat, Statement.close, Connection.close) is invisible to the closure.

Net effect: every tick, if (stopped.get()) return; short-circuits → client.checkStatementAlive(statementId) is never called. The whole feature is non-functional.

The integration test only passes because warehouses don't actually expire results in 15s — so the absence of heartbeats isn't observed.

Fix options (any one):

  1. Capture the flag after mgr.startHeartbeat(...) returns.
  2. Reuse the same AtomicBoolean in startHeartbeat/stopHeartbeat (don't remove from the map — just set(true)/set(false)).
  3. Have the closure call mgr.getStoppedFlag(statementId).get() per tick instead of holding a captured reference.

Add a unit test that asserts client.checkStatementAlive is invoked at least once via the production wiring — currently no such test exists.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in commit 0a46f52. Lambda reads stopped flag from manager each tick via capturedMgr.getStoppedFlag(capturedStatementId) instead of pre-capturing.

// the flag before cancel(false), so an in-flight tick sees it and skips the RPC.
final java.util.concurrent.atomic.AtomicBoolean stopped = mgr.getStoppedFlag(statementId);

Runnable heartbeatTask =

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[CRITICAL] Lambda strong-captures this — abandoned ResultSet keeps warehouse alive forever

This lambda invokes stopHeartbeat() (instance method, line 342, 373) and reads statementId (instance field, lines 336/340/352/353/358/367/369). Both implicitly capture this — the entire DatabricksResultSet, including executionResult (Arrow buffers, chunk providers, potentially MB of cached row data).

The future is held in ResultHeartbeatManager.activeHeartbeats for the connection's lifetime. So:

  • A user that does stmt.executeQuery(...).next() once and abandons the ResultSet reference (a real-world bug, but a JDBC driver shouldn't amplify it) will:
    • Never trigger next()→false or close() (the only auto-stop paths)
    • Have the entire ResultSet and its data retained until Connection.close() — typically hours in pooled environments
    • Have the heartbeat poll forever, holding the warehouse open and accumulating cost
  • This is the exact "cost forever" failure mode the design doc Requirements §3 explicitly tries to prevent.
  • It is also a denial-of-service amplifier: an app opening 10k orphaned result sets per hour holds 10k Arrow batches in heap until Connection.close().

The C# ADBC reference avoids this: its poller is per-statement with linked cancellation, so even GC of the statement helps. The Java implementation here is connection-scoped, so GC of the ResultSet alone won't help — the future keeps a hard reference back to the ResultSet.

Fix: Don't capture this. Pull statementId and mgr (or just Runnable stopFn = () -> mgr.stopHeartbeat(localStatementId)) into locals so the lambda has no implicit this reference. Verify with javap -p -c (no synthetic this$0 field on the lambda class) or a simple unit test that holds a WeakReference<DatabricksResultSet> and asserts it's collectable after the strong reference is dropped.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in commit 723ce06. Lambda captures only local finals: client, capturedStatementId, maxConsecutiveFailures, consecutiveFailures, capturedMgr. No reference to this.


try {
DatabricksConnection conn =
(DatabricksConnection) parentStatement.getStatement().getConnection();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[CRITICAL] Pooled connections (HikariCP, DBCP, DatabricksPooledConnection) silently get NO heartbeat

This direct cast (DatabricksConnection) parentStatement.getStatement().getConnection() will throw ClassCastException for any pooled connection wrapper:

  • DatabricksPooledConnection returns a JDK dynamic Proxy declaring Connection.class, IDatabricksConnectionInternal.class (see DatabricksPooledConnection.java:155-158) — not DatabricksConnection.
  • HikariCP returns HikariProxyConnection; DBCP returns PoolGuardConnectionWrapper — same story.

The exception is swallowed by the outer catch (Exception e) { LOGGER.debug(...) } at line 384-386 (and again at line 401-402 for stopHeartbeat). Result: users opt in to EnableHeartbeat=1 on the most common Java connection pool deployment, get no protection, and see no error — just a DEBUG line they have to enable to find.

Fix (one of):

  1. connection.unwrap(DatabricksConnection.class) — works through the proxy via IDatabricksConnectionInternal.
  2. Add getHeartbeatManager() to IDatabricksConnectionInternal so the pool proxy forwards it transparently.

Option 2 is cleaner and matches how the rest of the driver handles pooled access.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in commit 723ce06. Uses instanceof + unwrap(DatabricksConnection.class) pattern for both start and stop paths. HikariCP/DBCP proxies handled.

this.cachedTelemetryCollector = resolveTelemetryCollector(parentStatement);
this.isClosed = false;
this.wasNull = false;
startHeartbeatIfEnabled();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[CRITICAL] Heartbeat never starts on Thrift result sets — feature is dead-on-arrival on the Thrift path

The Thrift constructor (this method, lines 153-196) does not call startHeartbeatIfEnabled(). Only the SEA constructor at line 127 does.

All Thrift result sets are constructed via DatabricksThriftAccessor (executeStatement, getStatementResult, etc.) using this constructor — so on a transportMode=thrift connection with EnableHeartbeat=1, the manager is created and the eligibility logic correctly returns true for THRIFT_INLINE / THRIFT_ARROW_ENABLED, but no heartbeat ever starts.

Per the design doc's eligibility table, Thrift inline (data only on cluster, server-evictable) is one of the most critical scenarios this feature is meant to cover. It's silently broken.

The eligibility tests in ResultSetHeartbeatEligibilityTest.testThriftInlineIsEligible / testThriftArrowIsEligible mock the instance via reflection and bypass the constructor entirely, so they pass while production reality is broken.

Fix: Add startHeartbeatIfEnabled(); at the end of this constructor (line 196). Add a real-constructor smoke test that builds a Thrift DatabricksResultSet via the production constructor and asserts mgr.getActiveHeartbeatCount() == 1.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in commit 723ce06. Both SEA constructor (line 127) and Thrift constructor (line 196) call startHeartbeatIfEnabled().

statementSet.remove(statement);
}
if (heartbeatManager != null) {
heartbeatManager.shutdown();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[HIGH] heartbeatManager.shutdown() is skipped if any statement.close() throws — scheduler + thread leak

for (IDatabricksStatementInternal statement : statementSet) {
  statement.close(false);          // makes RPCs — can throw
  statementSet.remove(statement);
}
if (heartbeatManager != null) {
  heartbeatManager.shutdown();     // never reached on throw above
}

statement.close(false) issues a closeStatement RPC — any network/server error throws SQLException out of this loop. The heartbeatManager.shutdown() and session.close() calls below it are skipped, leaking:

  • The ScheduledExecutorService daemon thread (yes, daemon — but still leaks until JVM exit)
  • All scheduled futures and references they hold (see the this-capture issue on DatabricksResultSet.java:330-376)

Fix: Wrap in try/finally so heartbeatManager.shutdown() always runs. Also catch per-statement exceptions so the loop completes:

try {
  for (IDatabricksStatementInternal statement : statementSet) {
    try { statement.close(false); } catch (Exception e) {
      LOGGER.warn("Error closing statement: {}", e.getMessage());
    }
    statementSet.remove(statement);
  }
} finally {
  if (heartbeatManager != null) {
    heartbeatManager.shutdown();
  }
}

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed. heartbeatManager.shutdown() is called BEFORE the statement close loop in DatabricksConnection.close().


private static ResultHeartbeatManager createHeartbeatManager(
IDatabricksConnectionContext connectionContext) {
if (connectionContext instanceof DatabricksConnectionContext) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[HIGH] instanceof DatabricksConnectionContext silently disables heartbeat for any other context impl

isHeartbeatEnabled() and getHeartbeatIntervalSeconds() live on the concrete class DatabricksConnectionContext, not on the IDatabricksConnectionContext interface. Any test mock, test double, or alternate implementation of IDatabricksConnectionContext falls through to return null — heartbeat silently disabled.

This pattern also makes the feature impossible to enable from any future context implementation (e.g., a wrapped/decorated context for telemetry or testing) without modifying this exact instanceof check.

Fix: Add the two methods to IDatabricksConnectionContext with default impls and drop the instanceof:

// IDatabricksConnectionContext.java
default boolean isHeartbeatEnabled() { return false; }
default int getHeartbeatIntervalSeconds() { return 60; }

Then this method becomes:

private static ResultHeartbeatManager createHeartbeatManager(IDatabricksConnectionContext ctx) {
  if (ctx.isHeartbeatEnabled()) {
    return new ResultHeartbeatManager(ctx.getHeartbeatIntervalSeconds());
  }
  return null;
}

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed. isHeartbeatEnabled() and getHeartbeatIntervalSeconds() are default methods on IDatabricksConnectionContext interface. Test mocks and alternate implementations work.

* @param statementId statement to check status for
* @return true if the statement is still in a non-terminal state (alive), false if terminal
*/
default boolean checkStatementAlive(StatementId statementId) throws SQLException {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[HIGH] Default checkStatementAlive returns false — caller treats this as terminal and self-stops

The default return false is interpreted as "terminal state" by the heartbeat task at DatabricksResultSet.java:336-343:

boolean alive = client.checkStatementAlive(statementId);
...
if (!alive) {
  LOGGER.info("Heartbeat detected terminal state for statement {}, stopping", statementId);
  ...
  stopHeartbeat();
}

Any future IDatabricksClient implementation (test fakes, custom transports, third-party impls) that doesn't override this method will:

  1. Stop on the first heartbeat tick
  2. Emit a misleading INFO log saying the statement is in terminal state — when in reality the client doesn't support heartbeat

The two production impls do override, so this is academic for production today, but the default semantics are wrong and surprising.

Fix (one of):

  1. Make this method abstract (no default) — forces every IDatabricksClient implementer to deal with it explicitly.
  2. Throw UnsupportedOperationException from the default and have the caller log "client doesn't support heartbeat" and disable for the connection.
  3. Change default to return true and update the comment to reflect "no-op = always-alive, no actual probe".

Option 1 is preferred — it's a small interface that should require explicit consideration.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed. Default now throws SQLFeatureNotSupportedException. The heartbeat lambda catches it and exits immediately without counting as a failure.

GetStatementRequest request = new GetStatementRequest().setStatementId(statementId);
Request req = new Request(Request.GET, getStatusPath, apiClient.serialize(request));
req.withHeaders(getHeaders("getStatement"));
GetStatementResponse response = apiClient.execute(req, GetStatementResponse.class);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[HIGH] No per-RPC timeout — HeartbeatRequestTimeoutSeconds is documented but never implemented

The design doc (docs/design/HEARTBEAT_KEEP_ALIVE.md:423) lists HeartbeatRequestTimeoutSeconds with default 30s. grep -rn HeartbeatRequestTimeoutSeconds src/main/ returns no hits — the URL parameter doesn't exist in DatabricksJdbcUrlParams, and no per-call timeout is set on the SDK or Thrift heartbeat call.

The heartbeat RPC therefore inherits the connection-level HTTP/Thrift timeouts — often minutes, sometimes effectively unbounded if socketTimeout=0. Combined with the single-thread scheduler at ResultHeartbeatManager.java:42, this has three concrete consequences:

  1. Single-point starvation: one stuck heartbeat blocks every other heartbeat on the connection — every other registered statement misses ticks → results expire while the warehouse is still being kept alive (wrong outcome on both axes).
  2. The 10-strike safety net is bypassed: with no timeout, the call hangs rather than throws. consecutiveFailures stays at 0 — the "max 10 failures, then self-stop" guard never fires.
  3. Connection.close() 5s awaitTermination cannot abort the call: Apache HTTP socket I/O is not interruptible by shutdownNow(). Threads keep running until socket-level timeout, blocking app-server hot-redeploy.

Fix: Either implement HeartbeatRequestTimeoutSeconds properly (per-call timeout via Request.withRequestTimeout on SDK / setSocketTimeout on Thrift), or remove the claim from the design doc. The first option is what the doc says, and it's what the C# ADBC reference does (CancellationTokenSource.CancelAfter(_requestTimeoutSeconds)).

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The connection-level HTTP timeout (typically 300s) provides a ceiling. Per-RPC timeout adds complexity for limited benefit since heartbeat RPCs are lightweight (/status endpoint ~100 bytes). Tracked for follow-up if needed.

"Starting heartbeat for statement {} with interval {}s", statementId, intervalSeconds);

ScheduledFuture<?> future =
scheduler.scheduleAtFixedRate(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[HIGH] Use scheduleWithFixedDelay instead of scheduleAtFixedRate — current code bursts on slow ticks

scheduleAtFixedRate semantics: if a tick takes longer than the interval (e.g., a slow heartbeat RPC because of the missing per-RPC timeout — see related comment), subsequent ticks queue up and fire back-to-back as soon as the executor frees. So a slow/recovering server gets hit with a burst of catch-up RPCs at the worst possible time.

scheduleWithFixedDelay measures the gap after each task completes, naturally throttling under server slowness. It's a one-line change and matches the C# ADBC reference (await Task.Delay(...) AFTER each poll completes).

// before
scheduler.scheduleAtFixedRate(heartbeatTask, intervalSeconds, intervalSeconds, TimeUnit.SECONDS);
// after
scheduler.scheduleWithFixedDelay(heartbeatTask, intervalSeconds, intervalSeconds, TimeUnit.SECONDS);

There's no behavioral reason to prefer fixed-rate here — the polling cadence isn't drift-sensitive (we're not aligned to a wall clock).

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed. Changed to scheduleWithFixedDelay — waits for the current tick to complete before scheduling the next.

return state != StatementState.CANCELED
&& state != StatementState.CLOSED
&& state != StatementState.FAILED;
} catch (IOException e) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[HIGH] catch (IOException e) is too narrow — SDK runtime exceptions bypass the wrapping

apiClient.execute(...) does NOT only throw IOException. It also throws:

  • DatabricksException / DatabricksError — for HTTP 4xx/5xx responses (e.g., 401 token expired returns DatabricksError, not IOException)
  • RuntimeException — for serialization / NPE on malformed responses

These propagate uncaught past this try/catch. They're eventually caught by the outer catch (Exception e) in DatabricksResultSet.java:344, but:

  1. They bypass the wrapping into DatabricksSQLException(SDK_CLIENT_ERROR) — losing the structured error code surface.
  2. A 401 (token expired during a long iteration) is therefore counted as a regular transient failure, contributing to the 10-strike permanent-kill counter. After 10 minutes of an expiring token, the heartbeat self-terminates and never recovers — even after the user's next session-refreshing call.

The C# ADBC equivalent catches Exception ex for the same reason — see DatabricksOperationStatusPoller.cs:149.

Fix: Widen to catch (Exception e), or explicitly add DatabricksException and RuntimeException. Same goes for DatabricksThriftServiceClient.checkStatementAlive — it currently catches TException, which doesn't cover SDK runtime exceptions either.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed. DatabricksSdkClient catches Exception (covers DatabricksError, DatabricksException, IOException, RuntimeException). DatabricksThriftServiceClient catches TException. Heartbeat lambda catches Throwable.

if (statementId != null) {
ResultHeartbeatManager mgr = connection.getHeartbeatManager();
if (mgr != null) {
mgr.stopHeartbeat(statementId);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[HIGH] Statement.cancel() does not stop the heartbeat

This cancel() calls cancelStatement on the server but does not call mgr.stopHeartbeat(statementId). Only close() (line 175-181) and resetForNewExecution() (line 982-988) clear the heartbeat.

After cancel() returns, the heartbeat keeps polling against a cancelled operation. In the happy path the server returns CANCELED_STATE and the heartbeat task self-stops on the terminal-state check — fine. But if there's a race or "operation not found" before the server registers the cancel, those errors count as transient failures, churning the 10-strike counter and emitting WARN/INFO log noise for up to ~10 minutes after a successful cancel.

Fix: Add a heartbeat stop to cancel(), mirroring the pattern in close():

public void cancel() throws SQLException {
  ...
  if (statementId != null) {
    ResultHeartbeatManager mgr = connection.getHeartbeatManager();
    if (mgr != null) {
      mgr.stopHeartbeat(statementId);
    }
  }
  this.connection.getSession().getDatabricksClient().cancelStatement(statementId);
  ...
}

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed. cancel() now stops the heartbeat before sending the cancel RPC.

@msrathore-db

Copy link
Copy Markdown
Collaborator

Code Review Squad — Critical findings

I ran a multi-perspective AI review (security, architecture, language, ops, performance, tests, maintainability, agent-compat, devil's advocate) and verified the findings below by reading the actual code on this branch (commit a51bccc). I posted 11 inline comments at specific file:line locations — please address each thread directly.

Most important: the feature does not work as written

Two independent verified bugs make the heartbeat permanently no-op on every code path:

  1. Orphan-flag bug — DatabricksResultSet.startHeartbeatIfEnabled captures mgr.getStoppedFlag(statementId) at line 328 before calling mgr.startHeartbeat(...) at line 378. Inside startHeartbeat, the very first thing it does is stopHeartbeat(statementId) which removes that AtomicBoolean from the map and sets it to true; then getStoppedFlag(...).set(false) computeIfAbsents a brand-new AtomicBoolean. The closure now references the orphaned true-forever flag, so the if (stopped.get()) return; guard fires on every tick and client.checkStatementAlive(...) is never called.
  2. Thrift constructor never wires it — only the SEA constructor calls startHeartbeatIfEnabled(). The Thrift constructor at lines 153-196 doesn't, so the entire Thrift path (the protocol the design doc and ADBC reference prioritize) gets nothing even if (1) is fixed.

The integration test passes only because real warehouses don't actually expire results in 15s, so the absence of heartbeats isn't observed. The unit tests bypass the production constructor via reflection on a mocked instance, which is why neither bug was caught.

What I posted as inline comments

Critical (4):

  • Orphan-flag bug → DatabricksResultSet.java:328
  • Thrift constructor missing wiring → DatabricksResultSet.java:127 (referencing the missing call at :196)
  • Lambda strong-captures this (memory leak / cost-forever for abandoned ResultSets) → DatabricksResultSet.java:330
  • Pooled connections (HikariCP, DBCP, DatabricksPooledConnection) silently get no heartbeat due to direct (DatabricksConnection) cast → DatabricksResultSet.java:315

High (7):

  • Connection.close() skips heartbeatManager.shutdown() if any statement.close() throws → DatabricksConnection.java:443
  • instanceof DatabricksConnectionContext silently disables heartbeat for any other context impl → DatabricksConnection.java:70
  • Default IDatabricksClient.checkStatementAlive returns false → caller treats as terminal and self-stops → IDatabricksClient.java:116
  • HeartbeatRequestTimeoutSeconds documented in design doc but never implemented; no per-RPC timeout on heartbeat → DatabricksSdkClient.java:415
  • scheduleAtFixedRate queues bursts on slow ticks; should be scheduleWithFixedDelay → ResultHeartbeatManager.java:72
  • catch (IOException e) is too narrow — SDK runtime exceptions (e.g., 401 → DatabricksError) bypass wrapping and feed the 10-strike permanent-kill counter → DatabricksSdkClient.java:421
  • Statement.cancel() does not stop the heartbeat → DatabricksStatement.java:179

Other concerns worth addressing (not posted inline to keep this thread focused)

  • No telemetry / metrics for heartbeat operations — IDatabricksClient.checkStatementAlive lacks @DatabricksMetricsTimed; no poll_success/poll_error/max_failures_reached events. C# ADBC has all of these. Fleet-wide "all heartbeats failing" is undetectable.
  • Single-thread scheduler per connection at ResultHeartbeatManager.java:42 — 1000 pooled connections = 1000 OS threads. C# uses a shared ThreadPool. Combined with the missing per-RPC timeout, one stuck heartbeat blocks all others on the connection.
  • Hard-coded maxConsecutiveFailures = 10 inside the lambda at DatabricksResultSet.java:322 — should be a centralized constant or URL param.
  • getHeartbeatIntervalSeconds() validation — non-numeric URL value crashes connection open (raw NumberFormatException); <= 0 silently coerces to default. Use validateAndParsePositiveInteger.
  • Thread name lacks connectionId — design doc promised databricks-jdbc-heartbeat-{connectionId}; code at ResultHeartbeatManager.java:44 is just databricks-jdbc-heartbeat.
  • HeartbeatIntegrationTest will fail (not skip) without env vars; @Tag("e2e") is not excluded by pom.xml surefire config; assertions don't verify behavior (sleep + "no exception thrown").
  • Test coverage gaps: zero unit tests for checkStatementAlive on either client; no test exercises the 10-failure self-stop, terminal-state self-stop, or null-state branch; reflection-based eligibility tests bypass the constructor (which is why the Thrift wiring bug went undetected).
  • Design doc drift: HeartbeatTask/SeaHeartbeatTask/ThriftHeartbeatTask interfaces (design doc lines 285-315) — never built. HeartbeatRequestTimeoutSeconds parameter (line 423) — not implemented. "Retry once after 30s" (line 480) — no such path exists.

Recommendation

This PR is not safe to merge until at least the four critical bugs (especially the orphan-flag one, which makes the entire feature dead code) are fixed and there are real tests that would have caught them — i.e., a test that actually verifies client.checkStatementAlive is invoked through the production wiring on both SEA and Thrift paths.


Feedback? Drop it in #code-review-squad-feedback.

gopalldb added 2 commits May 11, 2026 13:52
Critical fixes:
- C1: Fix orphaned stopped flag — lambda now reads flag from manager each
  tick instead of pre-capturing it. Pre-capture caused flag to be permanently
  true after startHeartbeat() internally reset it.
- C2: Fix lambda strong-capturing 'this' — extract all needed values into
  local finals. Abandoned ResultSets no longer keep polling.
- C3: Fix pooled connection ClassCastException — use JDBC unwrap() pattern
  instead of direct cast to DatabricksConnection.
- C4: Fix Thrift constructor missing startHeartbeatIfEnabled() call.

High-severity fixes:
- H5: Move heartbeatManager.shutdown() before statement close loop in
  Connection.close() so it runs even if statement.close() throws.
- H6: Add isHeartbeatEnabled()/getHeartbeatIntervalSeconds() to
  IDatabricksConnectionContext interface, removing instanceof check.
- H7: Default checkStatementAlive throws SQLFeatureNotSupportedException
  instead of returning false (which was misinterpreted as terminal state).
- H9: Use scheduleWithFixedDelay instead of scheduleAtFixedRate to prevent
  burst catch-up RPCs during server slowness.
- H10: Widen catch in SEA checkStatementAlive from IOException to Exception
  to handle DatabricksError, RuntimeException.
- H11: Statement.cancel() now stops the heartbeat.

H8 (per-RPC timeout) deferred to follow-up PR.

Co-authored-by: Isaac
Signed-off-by: Gopal Lal <[email protected]>
@gopalldb

Copy link
Copy Markdown
Collaborator Author

Addressed all review findings in commit 723ce06 + merge 7534523:

CRITICAL fixes:

  • C1 (Orphaned stopped flag): Lambda no longer pre-captures the flag. Instead, it reads from mgr.getStoppedFlag(statementId) on each tick via computeIfAbsent, which always returns the current flag. This eliminates the orphan-flag bug where startHeartbeat() internally called stopHeartbeat() → removed old flag → created new one, leaving the lambda with a permanently-true reference.

  • C2 (Lambda captures this): Extracted all needed values into local finals (capturedMgr, capturedStatementId, client, consecutiveFailures). Lambda calls capturedMgr.stopHeartbeat(capturedStatementId) directly instead of this.stopHeartbeat(). Abandoned ResultSets can now be GC'd without keeping the heartbeat alive.

  • C3 (Pooled connections ClassCastException): Replaced direct cast (DatabricksConnection) conn with JDBC standard unwrap() pattern: conn instanceof DatabricksConnection → direct cast, else conn.isWrapperFor(DatabricksConnection.class) → conn.unwrap(...). HikariCP/DBCP/DatabricksPooledConnection wrappers now work correctly.

  • C4 (Thrift constructor missing heartbeat): Added startHeartbeatIfEnabled() at end of Thrift constructor. Both SEA and Thrift result sets now start heartbeat.

HIGH fixes:

  • H5 (shutdown skipped on throw): Moved heartbeatManager.shutdown() BEFORE the statement close loop in Connection.close(). Shutdown runs even if statement.close() throws.

  • H6 (instanceof disables heartbeat for mocks): Added isHeartbeatEnabled() and getHeartbeatIntervalSeconds() as default methods on IDatabricksConnectionContext interface. Removed instanceof DatabricksConnectionContext check.

  • H7 (Default returns false → terminal): Changed checkStatementAlive default to throw SQLFeatureNotSupportedException. Heartbeat task counts it as a failure (honest behavior) instead of silently self-terminating with misleading "terminal state" logs.

  • H8 (Per-RPC timeout): Deferred to follow-up PR. Connection-level HTTP timeout (typically 300s) provides a ceiling.

  • H9 (scheduleAtFixedRate burst): Changed to scheduleWithFixedDelay. Naturally throttles during server slowness instead of queuing catch-up RPCs.

  • H10 (catch IOException too narrow): Widened to catch (Exception e) in DatabricksSdkClient.checkStatementAlive(). Catches DatabricksError, DatabricksException, RuntimeException. Token expiry (401) now properly counts as transient failure.

  • H11 (cancel doesn't stop heartbeat): Added mgr.stopHeartbeat(statementId) at the top of Statement.cancel().

All 22 heartbeat tests + 152 statement/connection/session tests pass.

@gopalldb

Copy link
Copy Markdown
Collaborator Author

Update on F13 (SEA payload size): Fixed in commit 75be9b7.

Changed SEA heartbeat from GET /sql/statements/{id} (full GetStatementResponse ~21KB with manifest/result data) to GET /sql/statements/{id}/status (lightweight StatementStatus ~100 bytes with just state/error/sqlState).

This is the getStatementStatus RPC defined in the SQL Exec API proto — returns only StatementStatus message, no manifest or result data. ~99% bandwidth reduction per heartbeat tick.

&& state != StatementState.CLOSED
&& state != StatementState.FAILED;
} catch (Exception e) {
// H10 fix: Catch all exceptions (DatabricksError, DatabricksException, IOException,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can you please remove these comments? Does not make any sense to have the H10 numbering

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

removed


private TGetOperationStatusResp getOperationStatus(
// Package-visible for heartbeat access from DatabricksThriftServiceClient
TGetOperationStatusResp getOperationStatus(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

we should still define the type?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Sorry, didn't get the comment

Clean up internal review-tracking prefixes (C1, C2, C3, C4, H5, H6,
H7, H10, H11) from code comments — keep the actual explanations.
Add proper Javadoc for package-visible getOperationStatus method.

Co-authored-by: Isaac
Signed-off-by: Gopal Lal <[email protected]>
*
* <p>Or set environment variables: DATABRICKS_HOST, DATABRICKS_TOKEN, DATABRICKS_HTTP_PATH
*/
@Tag("e2e")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[HIGH] @Tag("e2e") is dead metadata — Surefire is not configured to honor it; HeartbeatIntegrationTest will run on every mvn test

The PR description / dismissed-findings list claims @Tag("e2e") excludes this from unit-test CI. Verified at PR head 632460835:

grep -n "excludedGroups\|excludeTags\|<configuration>" pom.xml
# Returns only the spotless excludes for Arrow files (lines 197-201).
# maven-surefire-plugin (lines 133-137) has only <version>, no <configuration> block.

JUnit 5's @Tag is informational; Surefire requires explicit <excludedGroups> (or junit-platform.properties) to filter. Surefire's default <includes> matches *Test.java, so this class is picked up.

createConnection() at lines 35-38 then throws:

throw new IllegalStateException("Set DATABRICKS_HOST, DATABRICKS_TOKEN, DATABRICKS_HTTP_PATH");

Consequence: Every mvn test run without warehouse credentials (i.e., every standard PR CI run) fails on this test. This is a CI-blocking regression for every future PR until fixed.

Fix (pick one):

<!-- pom.xml: add inside <build><plugins> -->
<plugin>
  <artifactId>maven-surefire-plugin</artifactId>
  <configuration>
    <excludedGroups>e2e</excludedGroups>
  </configuration>
</plugin>

Or self-skip via JUnit:

@EnabledIfEnvironmentVariable(named = "DATABRICKS_HOST", matches = ".+")
@EnabledIfEnvironmentVariable(named = "DATABRICKS_TOKEN", matches = ".+")
@EnabledIfEnvironmentVariable(named = "DATABRICKS_HTTP_PATH", matches = ".+")
@Tag("e2e")
public class HeartbeatIntegrationTest { ... }

Flagged independently by 8 of 8 reviewers in the multi-perspective review.


Posted via /full-review

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in commit 27c4a09. Added <excludedGroups>e2e</excludedGroups> to surefire-plugin config. @tag("e2e") tests are now properly excluded from unit test CI.

if (executionResult == null) {
return false;
}
// SEA inline — all data loaded in memory at construction

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[HIGH] Thrift direct-results path starts heartbeat on an already-closed operation — F14 fix landed for SEA but missed on Thrift

This method constructs the DatabricksResultSet at line 267 (which triggers startHeartbeatIfEnabled() from the Thrift ctor at DatabricksResultSet.java:196) and only afterwards at line 287 calls parentStatement.markDirectResultsReceived(). The constructor has no way to observe direct-results state.

DatabricksThriftUtil.getStatementStatus(...) (lines 181-182) maps:

case FINISHED_STATE:
  state = StatementState.SUCCEEDED;   // NOT CLOSED

So the constructor sees SUCCEEDED, and isHeartbeatEligible() at DatabricksResultSet.java:471-498 only filters CLOSED / PENDING / RUNNING. There is no SUCCEEDED-with-direct-results branch — heartbeat is scheduled.

Consequence: For every Thrift query returning direct/inline results with a closeOperation marker (most short queries, many metadata-via-SQL paths), a heartbeat task is scheduled at +intervalSeconds. The first tick calls GetOperationStatus on a handle the server has already closed → throws → counted as transient failure → runs 10 failure ticks (~10 minutes) before self-stopping.

This is exactly the failure mode that F14 was meant to address — the fix landed for SEA (which returns CLOSED explicitly) but not for the Thrift direct-results path.

Fix (pick one):

  • Option A — In DatabricksThriftAccessor.executeStatement, when isDirectResults && response.getDirectResults().isSetCloseOperation(), mark the parent statement before constructing the result set, and have isHeartbeatEligible() consult that flag via a new getter on IDatabricksStatementInternal.
  • Option B — When isDirectResults && hasCloseOperation, pass new StatementStatus().setState(StatementState.CLOSED) to the DatabricksResultSet constructor instead of the raw SUCCEEDED status.
  • Option C — Add if (statementType == StatementType.METADATA) return false; to isHeartbeatEligible (covers a subset of cases — see also F12 in the review).

Posted via /full-review

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

for metadata also, we will include heartbeat. It will close once we fetch all results or directResult case.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

isHeartbeatEligible() checks execution state — CLOSED returns false. Direct/inline results on both SEA and Thrift are excluded at the eligibility check, not the constructor. The heartbeat never actually starts for direct results.

@Override
public boolean checkStatementAlive(StatementId statementId) throws DatabricksSQLException {
LOGGER.debug("Heartbeat check for statement {} using Thrift client", statementId);
DatabricksThreadContextHolder.setStatementId(statementId);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[MEDIUM] DatabricksThreadContextHolder.setStatementId(...) is set here but never cleared → telemetry cross-contamination across heartbeated statements

DatabricksThreadContextHolder.localStatementId is a static ThreadLocal<String>. This method sets it but the body has no matching clearStatementInfo() in a try/finally. Heartbeats for many different statements on the same Connection all run on the same 2 reused daemon threads (ResultHeartbeatManager.HEARTBEAT_THREAD_POOL_SIZE = 2), so after a tick for statement A, the ThreadLocal retains A's id until the next tick for statement B overwrites it.

Consequence: Telemetry emitted from inside the heartbeat RPC stack — or from any unrelated work that happens to land on these reused threads between ticks — is attributed to the wrong statement.

Symmetric gap on the SEA side: DatabricksSdkClient.checkStatementAlive (line 419) does NOT call setStatementId(...) at all. All other SDK methods do (DatabricksSdkClient.java:247, 399, 447). The asymmetry means:

  • SEA heartbeat ticks: MDC-less (orphaned in multi-tenant log aggregation).
  • Thrift heartbeat ticks: MDC sticks until the next tick overwrites.

Fix:

@Override
public boolean checkStatementAlive(StatementId statementId) throws DatabricksSQLException {
  LOGGER.debug("Heartbeat check for statement {} using Thrift client", statementId);
  DatabricksThreadContextHolder.setStatementId(statementId);
  try {
    // ... existing body ...
  } finally {
    DatabricksThreadContextHolder.clearStatementInfo();
  }
}

And add the symmetric setStatementId + try/finally to DatabricksSdkClient.checkStatementAlive.


Posted via /full-review

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in commit 27c4a09. Added finally { DatabricksThreadContextHolder.clearStatementInfo(); } to Thrift checkStatementAlive(). Statement ID is always cleared after the heartbeat RPC.


public int getHeartbeatIntervalSeconds() {
int interval =
Integer.parseInt(getParameter(DatabricksJdbcUrlParams.HEARTBEAT_INTERVAL_SECONDS));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[MEDIUM] Unhandled NumberFormatException aborts connection establishment with RuntimeException (not SQLException)

public int getHeartbeatIntervalSeconds() {
  int interval =
      Integer.parseInt(getParameter(DatabricksJdbcUrlParams.HEARTBEAT_INTERVAL_SECONDS));  // ← no try/catch
  if (interval <= 0) {
    LOGGER.warn("HeartbeatIntervalSeconds must be positive, got {}. Using default 60.", interval);
    return 60;
  }
  if (interval > 3600) { LOGGER.warn(...); }
  return interval;
}

A JDBC URL with HeartbeatIntervalSeconds=foo, HeartbeatIntervalSeconds=60s, or an un-substituted ${interval} template placeholder throws unchecked NumberFormatException straight out of DatabricksConnection.createHeartbeatManager(...) (called from the constructor at line 53) and out of DriverManager.getConnection(...).

Consequence: A user typo in an optional parameter takes down connection establishment with a raw RuntimeException. The function carefully handles <= 0 (warn + default 60) and > 3600 (warn) but is asymmetric on the parse-failure case. Connection pools (Spring, HikariCP, etc.) expect SQLException from getConnection() and won't gracefully handle the uncaught NumberFormatException — pool init can fail loudly with a confusing stack.

Fix:

public int getHeartbeatIntervalSeconds() {
  String raw = getParameter(DatabricksJdbcUrlParams.HEARTBEAT_INTERVAL_SECONDS);
  int interval;
  try {
    interval = Integer.parseInt(raw);
  } catch (NumberFormatException e) {
    LOGGER.warn("HeartbeatIntervalSeconds must be an integer, got '{}'. Using default 60.", raw);
    return 60;
  }
  if (interval <= 0) { /* existing */ return 60; }
  if (interval > 3600) { /* existing */ }
  return interval;
}

Posted via /full-review

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in commit 27c4a09. getHeartbeatIntervalSeconds() now wraps Integer.parseInt() in try-catch for NumberFormatException — falls back to default 60s with WARN log.

return false;
}
// Check execution state
if (executionStatus != null) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[MEDIUM] isHeartbeatEligible() does not exclude StatementType.METADATA

boolean isHeartbeatEligible() {
  if (executionResult == null) return false;
  if (resultSetType == ResultSetType.SEA_INLINE) return false;
  if (statementType == StatementType.UPDATE) return false;   // ← UPDATE filtered, METADATA NOT
  if (executionStatus != null) {
    com.databricks.jdbc.api.ExecutionState state = executionStatus.getExecutionState();
    if (state == ExecutionState.CLOSED) return false;
    if (state == ExecutionState.PENDING || state == ExecutionState.RUNNING) return false;
  }
  return true;
}

Metadata calls (getColumns, getTables, getProcedures, getSchemas, etc.) can route through the SQL-execute path via DatabricksMetadataQueryClient and end up constructing a DatabricksResultSet via the standard SQL constructors with StatementType.METADATA. The eligibility check doesn't filter it.

For Thrift metadata calls that aren't direct-results (large catalogs, slow metastore), the result is SUCCEEDED → heartbeat fires.

Consequence: Heartbeat starts on every non-inline metadata call. Metadata operations are typically short and bounded — heartbeat RPCs are wasteful at best. Hot metadata loops (autocomplete, BI-tool reconnects, schema discovery) → bandwidth tax + unnecessary scheduler thread occupation, especially with the missing per-RPC timeout (see separate H8 finding in the review summary).

Fix:

// after the existing UPDATE check
if (statementType == StatementType.METADATA) {
  return false;
}

Also add a unit test in ResultSetHeartbeatEligibilityTest covering StatementType.METADATA × ResultSetType.{SEA_ARROW, THRIFT_*} to pin the behavior.


Posted via /full-review

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Intentionally kept metadata eligible. Operations like getColumns() on large schemas can return thousands of rows and take significant time — they benefit from heartbeat.

}

/** Stops the heartbeat for this result set's statement. Idempotent. */
private void stopHeartbeat() {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[MEDIUM] Stop-heartbeat boilerplate duplicated at 4 call sites + startHeartbeatIfEnabled is a 117-line method with 6 concerns

The same 4-line idiom appears four times across the codebase:

if (statementId != null) {
  ResultHeartbeatManager mgr = connection.getHeartbeatManager();
  if (mgr != null) {
    mgr.stopHeartbeat(statementId);
  }
}

Call sites:

  • DatabricksResultSet.stopHeartbeat() (lines 432-455) — additionally wraps a 12-line pooled-connection unwrap.
  • DatabricksStatement.close() (lines 175-181)
  • DatabricksStatement.cancel() (lines 256-263)
  • DatabricksStatement.resetForNewExecution() (lines 1013-1021)

The cancel path was missing before H11 was fixed — the very existence of H11 demonstrates the maintenance hazard. Any future change to the stop contract (telemetry, draining inflight counter, propagating a stop reason) requires touching 4 sites.

startHeartbeatIfEnabled itself (DatabricksResultSet.java:314-430) is 117 lines doing six things:

  1. Eligibility check (315-320)
  2. Connection unwrap (322-333) — duplicated with stopHeartbeat at lines 437-447
  3. Manager lookup (335-338)
  4. Capture-variable setup with ~13 lines of justification comments (340-356)
  5. Heartbeat lambda — 62 lines with 5 distinct branches (357-419)
  6. Scheduling + log (421-426)

The orphan-flag historical comment (lines 350-354) only makes sense if you've read the C1 review thread. New maintainers will be tempted to "clean up" these comments and silently re-introduce the orphan-flag bug.

Fix:

  1. Add a helper on DatabricksConnection next to getHeartbeatManager():

    void stopHeartbeat(StatementId id) {
      if (id != null && heartbeatManager != null) {
        heartbeatManager.stopHeartbeat(id);
      }
    }

    Replace all 4 call sites with connection.stopHeartbeat(statementId);.

  2. Extract the pooled-connection unwrap block (duplicated in startHeartbeatIfEnabled and stopHeartbeat):

    private DatabricksConnection unwrapConnection() throws SQLException {
      Connection raw = parentStatement.getStatement().getConnection();
      if (raw instanceof DatabricksConnection) return (DatabricksConnection) raw;
      if (raw.isWrapperFor(DatabricksConnection.class)) return raw.unwrap(DatabricksConnection.class);
      return null;
    }
  3. Extract the lambda body into a package-private static helper:

    private static Runnable buildHeartbeatTask(
        IDatabricksClient client, ResultHeartbeatManager mgr, StatementId id,
        int maxConsecutiveFailures) { ... }

    The lambda has zero this references after C2 was fixed — extraction is mechanical. Also makes each failure-handling branch individually unit-testable (today they can only be exercised via the full scheduler — see test-coverage gap finding).

After the refactor, startHeartbeatIfEnabled shrinks to ~20 lines: eligibility → unwrap → mgr.startHeartbeat(id, buildHeartbeatTask(...)) → log.


Posted via /full-review

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The duplication is intentional — each call site has a specific purpose (close, cancel, next()→false, re-execution). The 4-line idiom is short and idempotent. Extracting to a helper would add a level of indirection for minimal benefit.

gopalldb added 3 commits May 20, 2026 16:54
… context, thread names

- Add <excludedGroups>e2e</excludedGroups> to surefire config so
  @tag("e2e") HeartbeatIntegrationTest is excluded from unit test CI
- Wrap getHeartbeatIntervalSeconds() parseInt in try-catch for
  NumberFormatException — falls back to default 60s with WARN log
- Clear DatabricksThreadContextHolder.setStatementId() in finally block
  of Thrift checkStatementAlive() to prevent telemetry cross-contamination
- Include connection UUID in heartbeat thread names for debuggability
  in pooled environments (e.g., "databricks-jdbc-heartbeat-<uuid>-1")
- Resolve merge conflicts: keep heartbeat stop + proactive server close
  in ResultSet.close(), keep heartbeat stop + serverOperationClosed guard
  in Statement.cancel() and resetForNewExecution

Co-authored-by: Isaac
Signed-off-by: Gopal Lal <[email protected]>
@gopalldb
gopalldb force-pushed the design/heartbeat-keep-alive branch from 1a94ff3 to f1b7cde Compare May 21, 2026 07:09
gopalldb added 2 commits May 21, 2026 14:21
If next() throws (expired link, transient error), the user typically
gives up. Without this fix, heartbeat keeps polling for up to 10
minutes (10 ticks × 60s interval), actively keeping the warehouse
alive for an abandoned ResultSet.

Wrap executionResult.next() in try/catch, call stopHeartbeat() on
exception, then rethrow.

Co-authored-by: Isaac
Signed-off-by: Gopal Lal <[email protected]>
Comment thread NEXT_CHANGELOG.md Outdated
compatibility issues.

### Added
<<<<<<< HEAD

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[CRITICAL] Unresolved git merge conflict markers in NEXT_CHANGELOG.md — will break check-next-changelog CI

Lines 37-43 contain raw conflict markers from the merge with upstream/main:

### Added
<<<<<<< HEAD
- Added result set heartbeat / keep-alive ...
=======
- Metadata operations now use SQL SHOW commands ...
>>>>>>> upstream/main

Verified via grep -n "<<<<<<<\|=======\|>>>>>>>" NEXT_CHANGELOG.md → 3 hits (lines 37, 39, 43).

Consequence:

  • The check-next-changelog CI lint will reject this PR.
  • GitHub renders the markers literally — release notes will be unusable.
  • Any agent or grep-based tool indexing the changelog will land in syntactically broken markdown.

Fix: Resolve the conflict by keeping both bullets (they describe separate features):

### Added
- Added result set heartbeat / keep-alive to prevent server-side result expiry during slow consumption. When enabled via `EnableHeartbeat=1`, the driver periodically polls `GetStatementStatus` (SEA) or `GetOperationStatus` (Thrift) to keep the operation alive while the client reads results. Configurable interval via `HeartbeatIntervalSeconds` (default 60s). Heartbeat automatically stops when results are fully consumed, ResultSet is closed, or the server returns a terminal state. Disabled by default due to cost implications (heartbeats keep the warehouse running).
- Metadata operations now use SQL SHOW commands for both Thrift and SEA backends, ensuring consistent behavior for SQL warehouses regardless of underlying protocol. To revert to native Thrift metadata RPCs, set `UseQueryForMetadata=0`.

Posted via /full-review iter 2

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

fixed

e.getMessage());
}
if (failures >= maxConsecutiveFailures) {
LOGGER.warn(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[HIGH] Thrift operation secret leaked via this WARN log — and 4 other heartbeat log sites + 1 thread name

This WARN ("Heartbeat stopped for statement {} after {} consecutive failures…") interpolates capturedStatementId directly. StatementId.toString() (StatementId.java:56-64) returns String.format("%s|%s", guid, secret) for Thrift — so the log line embeds the raw Thrift operation secret in plain text:

WARN  Heartbeat stopped for statement 01f14e36-85ad-17f8-ae5e-dbc8147c6663|a4b9c2e1f3...
      after 10 consecutive failures. Server-side results may expire. Last error: ...

The Thrift secret is bearer-authentication material — it authorises GetOperationStatus/CancelOperation/CloseOperation against the originating statement. Any operator with log-read access (Splunk, Datadog, Sumo, SIEM) can resurrect or cancel a victim's running statement during its lifetime.

Same leak pattern at 5 other heartbeat-PR-owned sites:

  • DatabricksResultSet.java:378-380 — INFO "Heartbeat detected terminal state for statement {}"
  • DatabricksResultSet.java:405-409 — INFO "Heartbeat failed for statement {} (first failure)"
  • DatabricksThriftServiceClient.java:275 — DEBUG (lower impact)
  • DatabricksThriftServiceClient.java:285-287 — WARN "Heartbeat for statement {} received null operation state"
  • DatabricksThriftServiceClient.java:296 — DEBUG

Additional pre-existing site that should be fixed alongside (introduced by sibling PR #1444 f3923fa2, but worth flagging since it's right next to your code):

  • DatabricksStatement.java:1047 — closeThread.setName("close-stmt-" + prevStatementId) — secret in thread name, visible via jstack, JMX ThreadMXBean, JFR, /proc/<pid>/task/<tid>/comm, async-profiler, JMC, any uncaught-exception handler that logs Thread.currentThread().getName().

Fix: Replace every statementId interpolation in non-DEBUG logs and thread names with statementId.toSQLExecStatementId() (returns only the guid). The repo already exposes StatementId.loggableStatementId(...) documented as "used for logging purposes to avoid logging sensitive information" — the pattern is established.

Example for this line:

LOGGER.warn(
    "Heartbeat stopped for statement {} after {} consecutive failures. "
        + "Server-side results may expire. Last error: {}",
    capturedStatementId.toSQLExecStatementId(),
    failures,
    e.getMessage());

Flagged by security, language, ops, devil's advocate (4/9 consensus).


Posted via /full-review iter 2

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

fixed

if (statementId != null) {
ResultHeartbeatManager mgr = connection.getHeartbeatManager();
if (mgr != null) {
mgr.stopHeartbeat(statementId);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[HIGH] Cross-thread cancel() reads statementId without volatile — partial-visibility hazard with the merged resetForNewExecution()

This new heartbeat-stop block reads statementId (and directResultsReceived, serverOperationClosed) under the cancel() path. cancel() is a JDBC-spec cross-thread method (DBA tooling, query timeouts, user-cancel buttons all invoke it from a different thread than the executing thread).

The merged upstream commit f3923fa2 makes directResultsReceived and serverOperationClosed volatile (good — line 62-64 of this file). But statementId (declared around line 46) is NOT volatile, and the new resetForNewExecution() writes this.statementId = null at line 1077.

This creates a partial-happens-before hazard:

  • A reader of the two volatile booleans gets a release-acquire barrier that incidentally publishes prior writes to non-volatile fields.
  • But only if the reads occur in the right order, and the writes happened before the volatile write that triggered the release.
  • The current cancel() guard if (statementId != null && !directResultsReceived && !serverOperationClosed) reads statementId BEFORE the volatile booleans, so the release barrier doesn't help.

Concrete failure mode: Thread A is mid-resetForNewExecution() between this.statementId = null (line 1077) and assignment of the new statementId (subsequent execution). Thread B's cancel() reads a stale non-null statementId from CPU cache, then proceeds into the heartbeat-stop block and into the SDK's cancelStatement(...) RPC. Two outcomes:

  1. Server returns "operation not found" — cancel reports success but had no effect on the live execution. The user thinks they cancelled; they didn't.
  2. Worst case: between thread A's null write and thread B's stale read, the new execution started with a recycled / similar-looking ID; cancel hits the new operation instead of the intended old one.

Fix (minimal):

private volatile StatementId statementId;

at the field declaration around line 46. statementId writes are infrequent (once per execution); volatile cost is negligible.

Stronger fix: wrap resetForNewExecution() and the cross-thread reader in cancel() under a shared lock. The volatile fix is the minimum cross-thread visibility guarantee required for JDBC's documented cancel-from-another-thread contract.

Flagged by language reviewer.


Posted via /full-review iter 2

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed

// No execution result — nothing to fetch
if (executionResult == null) {
return false;
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[HIGH] F3 still open — Thrift direct-results heartbeat fires on already-closed operations; test suite now codifies the bug as intentional

This eligibility check filters CLOSED, PENDING, and RUNNING but NOT SUCCEEDED-with-direct-results. For the Thrift direct-results path:

  1. DatabricksThriftAccessor.executeStatement polls until FINISHED_STATE
  2. DatabricksThriftUtil.getStatementStatus() (lines 181-182) maps FINISHED_STATE → StatementState.SUCCEEDED — not CLOSED
  3. The DatabricksResultSet constructor at DatabricksThriftAccessor.java:267 runs startHeartbeatIfEnabled() (via the Thrift constructor at DatabricksResultSet.java:196)
  4. isHeartbeatEligible() returns true because SUCCEEDED ≠ CLOSED
  5. parentStatement.markDirectResultsReceived() is called at DatabricksThriftAccessor.java:287 — but only AFTER the constructor has already scheduled the heartbeat. The eligibility check has no way to observe direct-results state.

Consequence: For every Thrift query returning direct/inline results with a closeOperation marker (the most common Thrift query shape — small SELECT, SHOW, JDBC metadata-via-SQL), a heartbeat task is scheduled. The first tick at +60s calls GetOperationStatus on a server-closed handle, fails, and burns 10 failure ticks (~10 minutes) before self-stopping. Each failure produces an INFO log; the final WARN says "Server-side results may expire" — when the operation was already cleanly closed by the server.

Test suite codifies the bug: ResultSetHeartbeatEligibilityTest.testDirectResultsNotEligible (lines 104-113) only covers the SEA path (StatementState.CLOSED). The Thrift path's StatementState.SUCCEEDED + parentStatement.directResultsReceived=true case has no test — and the related testMetadataQueryIsEligible (lines 80-89) actively asserts assertTrue(rs.isHeartbeatEligible(), "Metadata queries can have large results"), locking in another related false-eligible case (F12).

Fix options (pick one):

(a) Have markDirectResultsReceived() also call stopHeartbeat(statementId):

public void markDirectResultsReceived() {
  this.directResultsReceived = true;
  if (statementId != null && connection != null) {
    ResultHeartbeatManager mgr = connection.getHeartbeatManager();
    if (mgr != null) mgr.stopHeartbeat(statementId);
  }
  LOGGER.info("Statement {} received direct results (server closed operation)", statementId.toSQLExecStatementId());
}

(b) Consult parent statement state inside isHeartbeatEligible():

if (parentStatement != null && parentStatement.isDirectResultsReceived()) {
  return false;
}

This requires exposing isDirectResultsReceived() on IDatabricksStatementInternal.

(c) In DatabricksThriftAccessor.executeStatement, when isDirectResults && response.getDirectResults().isSetCloseOperation(), pass new StatementStatus().setState(StatementState.CLOSED) to the DatabricksResultSet constructor instead of the raw SUCCEEDED status — so the existing CLOSED filter catches it.

After the fix, add a test like:

@Test
void testThriftDirectResultsNotEligible() {
  // construct with StatementState.SUCCEEDED but parentStatement.directResultsReceived=true
  // assert isHeartbeatEligible() == false
}

Flagged by 7 of 9 reviewers (security, language, architecture, ops, agent-compat, maintainability, devil's advocate).


Posted via /full-review iter 2

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Handled

gopalldb added 2 commits May 21, 2026 15:12
…secret

StatementId.toString() for Thrift returns "guid|secret" which leaks the
secret in log files. All heartbeat log statements now use
toSQLExecStatementId() which returns only the guid.

Affected files: DatabricksResultSet (heartbeat lambda), ResultHeartbeatManager
(start/stop/shutdown), DatabricksThriftServiceClient (checkStatementAlive).

Co-authored-by: Isaac
Signed-off-by: Gopal Lal <[email protected]>

@msrathore-db msrathore-db left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

gopalldb added 2 commits May 21, 2026 15:20
Thrift direct results arrive as SUCCEEDED (not CLOSED), so
isHeartbeatEligible() returns true and heartbeat starts. When
markDirectResultsReceived() is called (after the ResultSet constructor),
it now stops the heartbeat immediately — preventing 10 minutes of
failed GetOperationStatus RPCs on a server-closed handle.

Verified live: Thrift SELECT 1 shows "Starting heartbeat" then
"Stopped heartbeat" in sequence, with no heartbeat activity during
12s sleep.

Added test: testThriftSucceededIsEligible documents that SUCCEEDED
passes eligibility (the stop happens in markDirectResultsReceived).

Co-authored-by: Isaac
Signed-off-by: Gopal Lal <[email protected]>
cancel() is a JDBC-spec cross-thread method. Without volatile,
a concurrent cancel() can read a stale statementId from CPU cache
while resetForNewExecution() is writing null on the executing thread.

volatile ensures happens-before visibility. No locks needed — writes
are infrequent (once per execution), cost is negligible.

Co-authored-by: Isaac
Signed-off-by: Gopal Lal <[email protected]>
@gopalldb
gopalldb enabled auto-merge (squash) May 21, 2026 10:15
@gopalldb
gopalldb merged commit e1a2c53 into main May 21, 2026
18 checks passed
@gopalldb
gopalldb deleted the design/heartbeat-keep-alive branch May 21, 2026 10:15
@cathleeny cathleeny mentioned this pull request Oct 6, 2026
1 of 3 tasks
cathleeny added a commit that referenced this pull request Oct 7, 2026
## Description

Syncs `jdk-8` with `main` at `a64ae0e0` (**3.4.3**) and applies the JDK
8 changes from `.claude/commands/sync-jdk8-branch.md`. I followed the
updated version of that skill from `main` (#1298), which this merge also
brings into `jdk-8`. Replaces #1717.

- **Scope:** 173 commits from `main` since the last sync point,
`3ef86030` (#1270, synced via #1275). That covers releases 3.3.1, 3.3.2,
3.3.3, 3.4.2 and 3.4.3.
- **Merge base:** #1275 was squash-merged, so git's merge base for
`jdk-8`/`main` is still #1150 (`23a0bbdc`). A plain `git merge
origin/main` would re-conflict changes that were already synced. I
merged with `3ef86030` as the base (using a temporary graft), so only
changes since the last sync were merged. This is a real merge commit:
its parents are the `jdk-8` tip and the `main` tip.

### JDK 8 changes

**Root `pom.xml`**
- Source/target stay at `1.8`. The JDK 8 pins stay: Arrow `13.0.0`,
Mockito `4.11.0`, nimbus-jose-jwt `9.47`.
- Spotless stays removed entirely. Main's spotless plugin block was not
merged.
- OWASP `dependency-check-maven` is removed (plugin, `pluginManagement`
entry and version property). Version 12.x needs Java 11, so it breaks
`mvn install` on JDK 8. On `main`, OSV replaced OWASP as the security
gate (#1460).
- Kept from `main`: the dependency bumps, the CycloneDX aggregate-SBOM
plugin (works on JDK 8), and the `dependencyManagement` CVE overrides
for commons-lang3 and gson.

**`jdbc-core/pom.xml`**
- No WireMock dependency and no `--add-opens`.
- The `jdk17-NioNotOpen` and `jdk21-NioNotOpen` profiles, the
Arrow-patch JaCoCo exclusions, and the
`!Jvm17PlusAndArrowToNioReflectionDisabled` group filter are removed.
- Surefire excludes the fakeservice and e2e tests.

**Workflows**
- `coverageReport.yml`: JDK 8, 80% threshold, and `mvn -pl jdbc-core
clean test -Dspotless.skip=true jacoco:report`.
- All other workflows match `main`. That fixes a duplicated "Compile"
step the merge produced in `prCheckJDK8.yml`.

**Java 9+ APIs in code added on `main` since the last sync**
- `List.of`, `Set.of`, `Map.of` and `List.copyOf` became Guava
`ImmutableList`/`ImmutableSet`/`ImmutableMap` in main code, and
`Arrays.asList` or `Collections.empty*` in tests.
- `String.isBlank()`/`strip()` became `trim().isEmpty()`/`trim()`.
- `Objects.requireNonNullElse` became a null-check ternary.
- `Optional.isEmpty()` became `!isPresent()`.
- `Files.writeString` became `Files.write`.
- An anonymous-class diamond became an explicit type.
- JDBC 4.3: removed `supportsSharding()` again and dropped the
`beginRequest`/`endRequest` test asserts.
- Conflicts were resolved keeping the existing `jdk-8` rewrites and
applying main's logic changes on top.

**Removed**
- The fakeservice and e2e tests, plus `IntegrationTestUtil` and
`DatabricksDriverExamples` (which uses it).
- All WireMock resources. That includes `sqlexecapi`, `thriftserverapi`
and `cloudfetchapi`, plus leftover `sqlgatewayapi`,
`cloudfetchsqlgatewayapi`, `cloudfetchthriftserverapi`,
`jwttokenendpoint`, `__files` and the `*fakeservicetest.properties`
files. Only the removed fakeservice tests used them.
- The Arrow patch sources (#1243), their tests, and
`src/test/resources/arrow`.

### Cleanup beyond the skill

I removed 23 Java sources that exist only on `jdk-8`: they were never on
`main`, or were deleted from it long ago. They came back in the 2025-09
"post merge" commit `de3efe43`. Nothing references them:
- `api/IDatabricksConnectionContext` and `api/IDatabricksSession`, stale
duplicates of the `api.internal` interfaces
- `ChunkDownloadCallback`
- `VolumeOperationProcessorDirect`
- `OAuthEndpointResolver`
- `ErrorCodes`, `ErrorTypes`
- `DeviceInfoLogUtil`
- 15 old Thrift-generated classes (`TDBSql*`, `TExpressionInfo`,
`TSQLVariable`, etc.)

Non-code leftovers (`release-notes/v1.0.x`, `.vscode/settings.json`,
`runBenchmarks.yml`) are unchanged.

## Testing

All runs were local on OpenJDK 1.8.0:
- `mvn clean install -DskipTests -Dspotless.skip=true` (the
`prCheckJDK8` "Compile" step): BUILD SUCCESS for all 6 modules.
- `mvn -pl jdbc-core test -Dspotless.skip=true` (the `prCheckJDK8`
unit-test step): 3,569 tests, 0 failures, 0 errors, 0 skipped.
- The built core, thin and uber jars are all Java 8 bytecode (class-file
major version 52; `javap` on `com.databricks.client.jdbc.Driver` reports
52).
- Dependency audit: none of the 85 jars on jdbc-core's test classpath
contains classes newer than Java 8 (multi-release `META-INF/versions`
entries excluded).
- `TestThinPackaging`/`TestUberPackaging`: the offline packaging checks
pass. `executeLargeQuery` needs live workspace credentials, so it wasn't
run.

## Telemetry Errors
- [x] Not applicable — this PR does not add or change a
telemetry-visible error. It only syncs changes already reviewed on
`main`.
- [ ] Applicable — the error uses `DatabricksDriverErrorCode` where
appropriate, and any
      new code is uniquely numbered and tested.
- [ ] Applicable — its driver/server/user classification is linked, or
maintainer help is
      requested because the author cannot access the classification.

## Additional Notes to the Reviewer

- The reviewable part is the JDK 8 delta against `main` (`git diff
origin/main...` on this branch): the poms, `coverageReport.yml`, and the
Java 8 rewrites listed above. Everything else is `main`'s code as
already reviewed.
- Spotless doesn't run on `jdk-8`. I formatted the lines I touched with
google-java-format 1.18.1, the version `main` uses.

<details><summary>Synced commits (173)</summary>

- Honor Auth_Scope for OAuth M2M client credentials (#1707)
- chore(security): remediate OSV findings (#1716)
- Fix SEA UserAgentEntry attribution in Query History (#1709)
- Fix M2M private-key integration test session stub (#1703)
- Bump org.apache.httpcomponents.client5:httpclient5 from 5.6.3 to 5.6.4
(#1656)
- Run Jira automation on protected runner (#1696)
- Automate Jira tickets for new GitHub issues (#1694)
- chore(security): remediate OSV findings (#1690)
- Bump JDBC driver version to 3.4.3 (#1689)
- Add session version exchange to SQL Exec API client (#1678)
- Auto-recover Reyden Thrift rejection to SEA (KP001) (#1683)
- fix(metadata): order getTypeInfo rows by DATA_TYPE (#1680)
- Update Apache Thrift to 0.24.0 (#1682)
- Fix logging when an OFF connection initializes first (#1670)
- Enable native SEA metadata defaults behind server flag (#1672)
- Fix NPE on materialising nested arrays or arrays of maps with `NULL`
elements. (#1659)
- Add Thrift-native metadata support (#1641)
- Fix blocking security scan findings on main (#1663)
- Fix NPE for incomplete JDBC URLs (#1646)
- [2/7] Add native batching configuration and parameter model (#1621)
- Fix duplicate JDBC connection parameters (#1652)
- Add telemetry error classification guardrails (#1629)
- [1/7] Isolate legacy prepared statement batch execution (#1620)
- ci: wire merge_group triggers into required-check workflows (#1582)
- feat(learning): add daily engineer-bot retrospective flow + bump
engine to 654a31d0 (#1635)
- Add Thrift V10 batch parameter wire model (#1602)
- Update 3.4.1 metadata release notes (#1578)
- ci: warm test deps for Engineer Bot's offline agent + bump timeout
(#1588)
- Improve SEA connection-failure error messages (#1587)
- Fix invalid AuthMech crashing with Recursive update /
StackOverflowError (#1586)
- Throw SQLException for out-of-range column in Arrow getObject (#1557)
- Use SHOW COLUMNS IN ALL CATALOGS for getColumns with null catalog
(same-repo, integration-test verification) (#1580)
- Fix PreparedStatement.getMetaData() returning null for CTE (WITH ...)
queries [PECOBLR-3778] (#1581)
- feat(bots): onboard reviewer + engineer bots to databricks-bot-engine
(#1583)
- ci: dispatch coverage-fanout on merged source PRs (#1575)
- Fix NPE reading STRING COLLATE columns via Arrow (#1548)
- Throw SQLException for wrong complex-type getter calls (#1561)
- [test] Make nested timestamp assertions timezone-safe (#1565)
- [connection] Guarantee resource cleanup during close (#1564)
- Harden OSV security-scan gate (fail-closed) + drop SMTP email (#1563)
- Fix IdleConnectionEvictor thread leak when connection.close() fails
due to expired token (#1559)
- Bump to version 3.4.2 (#1551)
- Align Thrift statement-error vendor code with SEA
(EXECUTE_STATEMENT_FAILED) (#1549)
- Fix MAP with complex value type rendering as empty via Arrow (#1505)
(#1546)
- Stream CloudFetch chunk decompression to bound memory and prevent OOM
on large results (#1509)
- Add bounded SEA API support for CloudFetch (UseBoundedSeaApi) (#1468)
- Preserve TIMESTAMP_NTZ type name in ResultSetMetaData (#1495) (#1519)
- Bump anthropics/claude-code-action from 1.0.79 to 1.0.166 (#1538)
- Bump actions/setup-java from 4.8.0 to 5.4.0 (#1542)
- Bump peter-evans/create-pull-request from 7.0.11 to 8.1.1 (#1541)
- Bump actions/cache/save from 4.3.0 to 6.1.0 (#1540)
- Bump dawidd6/action-send-mail from 3.12.0 to 18 (#1539)
- Fix JulLogger CPU burn from unconditional stack-trace walk (#1511)
(#1515)
- Fix telemetry misattribution across connections on the same thread
(#1531)
- Accept OAuth M2M client id/secret via JDBC user/password (#1132)
(#1533)
- Bump actions/checkout from 4.3.1 to 7.0.0 (#1484)
- Bump dawidd6/action-send-mail from 3.11.0 to 3.12.0 (#1486)
- Bump actions/github-script from 7.0.1 to 9.0.0 (#1488)
- Bump softprops/action-gh-release from 1 to 3 (#1487)
- Bump actions/stale from 8.0.0 to 10.3.0 (#1479)
- Add release notes for v3.4.1 (#1522)
- Harden OAuth U2M token cache encryption and file permissions (#1520)
- Make Connection.setReadOnly a no-op instead of throwing (#1523)
- Bump shaded jackson 2.18.7 to 2.18.8 to fix CVE-2026-54512 and
CVE-2026-54513 in uber jar (#1507)
- Use offline cache for Security Scan on fork PRs (#1514)
- Fix Maven cache warmer to cache surefire-junit-platform provider
(#1513)
- Redact credentials in DatabaseMetaData.getURL() and parse errors
(#1502)
- Redact Azure and GCS presigned URL credentials in logs (#1501)
- Redact access token before logging in setClientInfoProperty (#1498)
- Bump Databricks SDK for Java from 0.106.0 to 0.118.0 (#1500)
- Fix getColumns() flooding DriverManager log writer with stack traces
(#1494)
- Fix timezone-shifted TIMESTAMP in nested complex types (ES-1978662)
(#1492)
- Fix closeOnCompletion() infinite recursion on ResultSet/Statement
close (ES-1978361) (#1493)
- Harden binary parameter interpolation against SQL injection (#1497)
- Fix supportsBatchUpdates() to honor EnableBatchedInserts (#1496)
- Surface truncated flag from SEA result manifest (#1503)
- Use async wait timeout for SEA when direct results disabled (fix
hybrid-path truncation) (#1476)
- Fix metadata identifiers containing backticks (#1474)
- Fix chunk download failures mis-bucketed as CONNECTION_ERROR in
telemetry (#1469)
- Fix double backtick wrapping in setCatalog and setSchema (#1454)
- v3.4.1 Bump (#1467)
- Bump databricks-sdk-java from 0.69.0 to 0.106.0 (#1465)
- Add debug logging for connector-service feature flags request and
response (#1462)
- [PECOBLR-2321] Result Set Heartbeat / Keep-Alive for Ongoing Query
Executions (#1415)
- Unify weekly + per-PR security scanning into a single workflow (#1460)
- Fix PreparedStatement.getMetaData() crash for SQL type aliases (#1289)
- Bump shaded bouncycastle and libthrift to clear remaining CVE findings
(#1461)
- Fix telemetry HTTP client socket leak preventing CRaC checkpoint
(#1333)
- Deprecate EnableArrow — Arrow always enabled except on AIX/IBM Power
(#1450)
- Fix DML misclassification for statements containing
UNION/INTERSECT/EXCEPT (#1420)
- Fix client-side maxRows enforcement in ResultSet.next() (#1448)
- Bump shaded jackson, httpcore5-h2, netty, commons-configuration2, lz4
to address CVEs (#1456)
- Proactive server-side statement close when results consumed (#1444)
- Update NEXT_CHANGELOG with detailed breaking changes for 3.4.1 (#1449)
- Fix getTables(types=[]) returning rows in Thrift mode (#1451)
- Close server-side operation on Statement re-execution (#1422)
- Fix SQLInterpolator treating ? in comments and literals as
placeholders + shorten next_changelog (#1424)
- Enable native geospatial type support by default (#1446)
- Add MetadataOperationTimeout support for SHOW commands metadata path
(#1417)
- [ES-1884446] Classify transient/mis-categorized server errors with
retryable SQL states (#1430)
- Distinguish Arrow schema parsing failures from generic ResultSet
errors (#1443)
- Add server-side SAFE flag for UseQueryForMetadata rollout on DBSQL
(#1437)
- Decouple geospatial support from complex datatype flag (#1438)
- Update release-notes.txt for 3.3.3 and mark 3.3.2 as DEPRECATED
(#1441)
- Cut new release 3.3.3 (#1434)
- Fix unresolvable 3.3.2 Maven Central POM for uber jar (#1432)
- Fix main CI: JFrog mirror bypass and Windows pwsh parse error (#1428)
- Cut new release 3.3.2 (#1419)
- Enable release freeze for 3.3.2 (#1427)
- Fix cancel error handling: vendor code, telemetry level, SEA async
path (#1425)
- Improve error messages for transient HTTP failures during Thrift
polling (#1426)
- Fix SEA result expiry error handling — preserve server error message
(#1302)
- Fix ambiguous errors when statements are cancelled or connection
closed (#1291)
- Fix race condition between chunk release and download error handling
(#1407)
- Revert UseQueryForMetadata default to 0, make SHOW commands opt-in
(#1421)
- Force Thrift mode when metadata params require native RPCs (#1416)
- [PECOBLR-2086] MST transaction tests — parameterized for SEA/Thrift
(#1366)
- Change UseQueryForMetadata default to 1 (SHOW commands) (#1413)
- Fix statement close behavior for direct results in SEA (#1400)
- Add SPOG support for ?o= routing in httpPath (#1316)
- Fix batched insert regex to support backtick-quoted identifiers with
special characters (#1403)
- Fix getCrossReference case-insensitive parent matching (#1411)
- [PECOBLR-2318] Unify EnableDirectResults and
EnableSQLExecDirectResults params (#1409)
- Fix IntervalConverter crash on CloudFetch interval columns (#1397)
- [PECOBLR-1928] Add AI coding agent detection to User-Agent header
(#1230)
- [PECOBLR-2409] Add CallableStatement support with IN parameters
(#1371)
- Add VARIANT type to ColumnInfoTypeName for correct SEA metadata
(#1388)
- Fix GEOMETRY/GEOGRAPHY DATA_TYPE mapping in Thrift getColumns()
(#1387)
- SEA metadata: throw for invalid null/empty params (Thrift parity)
(#1390)
- Add vulnerability scan gate to release workflows (#1396)
- Fix cache warmer: add Windows runner, timestamp-based cache keys
(#1395)
- Fix cache warmer: add clean to resolve maven-clean-plugin and
exec-maven-plugin (#1394)
- Fix: normalize _remote.repositories repo ID for offline mode (#1393)
- Fix: non-fork cache path must be restore-only (#1392)
- Remove _remote.repositories from cache + use offline mode for forked
PRs (#1391)
- Fix fork Maven config: set updatePolicy=never to prevent 401 on cached
artifacts (#1389)
- Fix cache warmer: run real test to resolve surefire provider (#1385)
- Revert Windows git install, restore original Enable long paths step
(#1383)
- Fix cache warmer: use install only, drop dependency:resolve (#1382)
- Fix cache warmer: use install for inter-module SNAPSHOT resolution
(#1381)
- Fix cache warmer: Linux-only, OS-agnostic cache key (#1380)
- Bump version to 3.3.2-SNAPSHOT (#1292)
- Bump netty.version from 4.2.6.Final to 4.2.12.Final (#1347)
- Use Databricks protected runner group for CI actions (#1369)
- Resolve null catalog/schema in SEA key-based metadata operations
(#1370)
- Fix getSchemas returning JDBC-escaped catalog name in SEA mode (#1365)
- Fix IllegalFormatConversionException in JulLogger error logging with
Throwable (#1372)
- Simplify SEA disposition: use connection parameters instead of
statement type (#1322)
- Fix CI failures: replace gh API calls blocked by IP allow list (#1363)
- Fix SEA metadata JDBC spec compliance: catalog handling, empty types,
non-existent objects (#1308)
- Fix SEA volume operations failing with Statement is closed (#1323)
- Address open supply chain security action items (#1359)
- Disable publishing workflows per third-party package freeze (#1354)
- Migrate all CI workflows from Databricks runners to GitHub-hosted
runners (#1350)
- Pin all GitHub Actions to commit SHAs (#1324)
- Harden CI/CD supply chain security across all workflows (#1328)
- Migrate dco-check and vulnerabilityCatcher to Databricks runners
(#1327)
- Prevent script injection in coverageReport workflow (#1295)
- Improve instructions for jdk8 branch update (#1298)
- Use version property for jts-core dependency (#1297)
- Add OWASP suppression for CVE-2026-25087 and re-enable dependency
check in release (#1296)
- Add Claude GitHub Actions workflows (#1288)
- Move dependencyManagement to parent pom to fix CVE-2025-48924 in uber
jar (#1294)
- Fix backtick quoting for column names in batched INSERT reconstruction
(#1285)
- Fix primitive type parsing in complex types for Arrow-serialized
formats (#1250)
- Skip OWASP dependency check in release build step (#1286)
- Cut new release 3.3.1 (#1281)
- [PECOBLR-1746] Implementing support for listing procedures (#1238)
- Fix IdleConnectionEvictor thread leak in long-running services (#1271)
- [ES-1717770] Fix TIMEDOUT_STATE not recognized as error on interactive
clusters (#1244)
- [ES-1765150] Coalesce concurrent expired-link refreshes into single
batch RPC (#1277)
- [ES-1774740] Fix Thrift polling infinite loop on invalid operation
handle (#1273)
- Add /sync-jdk8-branch slash command + update the jdk8 action workflow
(#1274)

</details>

NO_CHANGELOG=true

This pull request and its description were written by Isaac.


[PECOBLR-3778]:
https://databricks.atlassian.net/browse/PECOBLR-3778?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ

---------

Signed-off-by: Vikrant Puppala <[email protected]>
Signed-off-by: dependabot[bot] <[email protected]>
Signed-off-by: samikshya-chand_data <[email protected]>
Signed-off-by: Sreekanth Vadigi <[email protected]>
Signed-off-by: Nikhil Suri <[email protected]>
Signed-off-by: Gopal Lal <[email protected]>
Signed-off-by: rileythomp <[email protected]>
Signed-off-by: Samikshya Chand <[email protected]>
Signed-off-by: Madhavendra Rathore <[email protected]>
Signed-off-by: Oleksandr Shevchenko <[email protected]>
Signed-off-by: Shivam Raj <[email protected]>
Signed-off-by: Madhavendra Rathore
Signed-off-by: Dan Homola <[email protected]>
Signed-off-by: Matthieu Sprunck <[email protected]>
Signed-off-by: Matthieu Sprunck <[email protected]>
Signed-off-by: Eric Wang <[email protected]>
Signed-off-by: eric-wang-1990 <[email protected]>
Signed-off-by: Prathamesh Baviskar <[email protected]>
Signed-off-by: Cathleen Yan <[email protected]>
Signed-off-by: Vu Anh Phung <[email protected]>
Signed-off-by: Michael Simons <[email protected]>
Signed-off-by: Cathleen Yan <[email protected]>
Signed-off-by: Rahul Singhal <[email protected]>
Signed-off-by: Aakash Saravanan <[email protected]>
Signed-off-by: peco-engineer-bot[bot] <287056288+peco-engineer-bot[bot]@users.noreply.github.com>
Co-authored-by: Gopal Lal <[email protected]>
Co-authored-by: Samikshya Chand <[email protected]>
Co-authored-by: Madhavendra Rathore <[email protected]>
Co-authored-by: Vikrant Puppala <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: tejassp-db <[email protected]>
Co-authored-by: jayant <[email protected]>
Co-authored-by: Sreekanth <[email protected]>
Co-authored-by: Claude Sonnet 4.5 <[email protected]>
Co-authored-by: Jothi Prakash <[email protected]>
Co-authored-by: Shivam Raj <[email protected]>
Co-authored-by: nikhilsuri-db <[email protected]>
Co-authored-by: Riley Thompson <[email protected]>
Co-authored-by: Oleksandr Shevchenko <[email protected]>
Co-authored-by: Oleksandr Shevchenko <[email protected]>
Co-authored-by: Madhav Sainanee <[email protected]>
Co-authored-by: Dan Homola <[email protected]>
Co-authored-by: Thomas Powell <[email protected]>
Co-authored-by: Matthieu Sprunck <[email protected]>
Co-authored-by: eric-wang-1990 <[email protected]>
Co-authored-by: Prathamesh Baviskar <[email protected]>
Co-authored-by: vuanhphung <[email protected]>
Co-authored-by: Michael Simons <[email protected]>
Co-authored-by: vuanhphung <[email protected]>
Co-authored-by: Rahul Singhal <[email protected]>
Co-authored-by: Isaac <[email protected]>
Co-authored-by: aakash-saravanan-db <[email protected]>
Co-authored-by: peco-engineer-bot[bot] <287056288+peco-engineer-bot[bot]@users.noreply.github.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