Skip to content

fix(bigquery-jdbc): gate per-connection log writers on active connection lifecycle - #15166

Closed
Neenu1995 wants to merge 15 commits into
fix/bq-jdbc-log-rotation-and-contextfrom
fix/bq-jdbc-log-handler-lifecycle
Closed

Neenu1995 wants to merge 15 commits into
fix/bq-jdbc-log-rotation-and-contextfrom
fix/bq-jdbc-log-handler-lifecycle

Conversation

@Neenu1995

Copy link
Copy Markdown
Contributor

Summary

PR 3 of 6 in the diagnostic logging stack (b/584840147, part 3 of 3; stacked on fix/bq-jdbc-log-rotation-and-context). Tracks active connections in BigQueryJdbcRootLogger and gates per-connection log writers behind synchronized ConnectionFileSlot lifecycle state so closed or failed connections never leak or reopen file descriptors.

Environment Variables & System Properties

  • New Environment Variables / System Properties: None added in this PR.

Design Decisions

  • Active-connection registry & constructor failure cleanup: BigQueryJdbcRootLogger maintains ACTIVE_CONNECTIONS for open BigQueryConnection instances, and BigQueryConnection's constructor cleans up its handler registration in a finally block if initialization throws before returning a connection.
  • Lock-order-safe ConnectionFileSlot lifecycle: Wraps each connection's BoundedLogFileWriter in a ConnectionFileSlot with a volatile closed flag checked both outside and inside synchronized slot methods (avoiding nested lock acquisition inside ConcurrentHashMap.compute). Once closeConnection(connectionId) runs, late logs from post-close ResultSet, Struct, Array, or concurrent worker threads cannot resurrect a closed log file.

…g files

PR 1 of 6 in the diagnostic logging series (b/584840147, part 1 of 3).

Replaces java.util.logging.FileHandler inside PerConnectionFileHandler with an NIO SeekableByteChannel writer enforcing 0700/0600 POSIX permissions, symlink rejection, collision-safe exclusive creation, literal % path handling, and graceful ErrorManager degradation.
…tionLogContext

PR 2 of 6 in the diagnostic logging series (b/584840147, part 2 of 3).

Adds bounded 1 GiB two-file (.log + .1.log 0600 backup) rotation with graceful ErrorManager fallback to PerConnectionFileHandler, and replaces raw String LogRecord parameter stamping with typed ConnectionLogContext across BigQueryJdbcResultSetLogger and OpenTelemetryJulHandler.
…ion lifecycle

PR 3 of 6 in the diagnostic logging series (b/584840147, part 3 of 3).

Tracks active connections in BigQueryJdbcRootLogger with BigQueryConnection constructor finally cleanup and wraps per-connection writers in synchronized ConnectionFileSlot entries so post-close ResultSet/Struct calls and concurrent close() vs publish() calls do not reopen closed writers.
@Neenu1995
Neenu1995 requested review from a team as code owners November 23, 2026 19:58

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces robust connection lifecycle tracking and resource cleanup for the BigQuery JDBC driver, particularly around logging and executor services. It adds mechanisms to track active connections, register/unregister them, and refactors PerConnectionFileHandler to use a slot-based architecture (ConnectionFileSlot) to prevent resource leaks and ensure files are closed properly. Unit tests are also added to cover concurrency and post-close scenarios. The review feedback highlights two important improvements: first, fixing a potential issue in PerConnectionFileHandler where log records could be silently dropped if a slot is closed but the connection remains active; second, optimizing BigQueryJdbcResultSetLogger to default to OFF_VALUE for inactive connections to prevent unnecessary logging overhead.

@Neenu1995
Neenu1995 added this pull request to stack #15170 November 23, 2026 20:21
…tation-and-context

# Conflicts:
#	java-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/PerConnectionFileHandler.java
…log-handler-lifecycle

# Conflicts:
#	java-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/PerConnectionFileHandler.java
…tation-and-context

# Conflicts:
#	java-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/PerConnectionFileHandler.java
@Neenu1995 Neenu1995 changed the title [WIP] fix(bigquery-jdbc): gate per-connection log writers on active connection lifecycle fix(bigquery-jdbc): gate per-connection log writers on active connection lifecycle Nov 24, 2026
@Neenu1995

Copy link
Copy Markdown
Contributor Author

/gcbrun

@keshavdandeva keshavdandeva left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This does what it says. Repro: logging after close() no longer creates a file or leaks a descriptor, and 8 threads × 50 concurrent connects leave 1 handler (12–14 before). Two non-blocking comments inline. Please don't merge ahead of the PR 1 and PR 2 fixes. On the bot comment about a closed slot: the record isn't lost, it falls through to the default writer.

@Neenu1995

Copy link
Copy Markdown
Contributor Author

Closing as superseded: the changes and review feedback from #15166, #15167, and #15169 have been consolidated into Layer 6 (#15255) of the finalized 6-PR diagnostic logging stack (#15256).

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