Repository navigation
Conversation
…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.
…tation-and-context
There was a problem hiding this comment.
Code Review
This pull request introduces diagnostic logging configuration and bounded log file rotation (using .log and .1.log backup files) configured via environment variables, JDBC URL properties, or JVM system properties. It also introduces ConnectionLogContext to carry per-connection logging identity and threshold safely across threads. The review feedback identifies two potential resource leaks in PerConnectionFileHandler.java where newly opened or recovered channels could be leaked if channel.size() throws an IOException during the rotation recovery or reopening phases.
| OpenedChannel recovered = | ||
| DEFAULT_HANDLER_ID.equals(id) | ||
| ? openLockedGlobalChannel(activePath) | ||
| : new OpenedChannel(activePath, null, openSecureAppendChannel(activePath)); | ||
| activePath = recovered.path; | ||
| claimedGlobalPath = recovered.claimedGlobalPath; | ||
| channel = recovered.channel; | ||
| writtenBytes = channel.size(); |
There was a problem hiding this comment.
Similarly, if channel.size() throws an IOException during the recovery path after a failed move, the recovered channel will be leaked.
Wrap the assignment and size check in a try-catch block and call recovered.releaseOnFailure(e) to ensure the channel is properly closed on failure. Catch IOException specifically instead of Throwable since this is not an asynchronous operation or Future boundary.
OpenedChannel recovered =
DEFAULT_HANDLER_ID.equals(id)
? openLockedGlobalChannel(activePath)
: new OpenedChannel(activePath, null, openSecureAppendChannel(activePath));
try {
activePath = recovered.path;
claimedGlobalPath = recovered.claimedGlobalPath;
channel = recovered.channel;
writtenBytes = channel.size();
} catch (IOException e) {
recovered.releaseOnFailure(e);
throw e;
}References
- Catching
Throwableinstead ofExceptionis acceptable at Future boundaries or during stream cleanup in asynchronous operations to ensure all failures are captured and propagated. For synchronous operations, catch specific exceptions likeIOException.
| OpenedChannel reopened = reopenOrAllocate(logDir, id, activePath); | ||
| activePath = reopened.path; | ||
| claimedGlobalPath = reopened.claimedGlobalPath; | ||
| channel = reopened.channel; | ||
| writtenBytes = channel.size(); |
There was a problem hiding this comment.
If channel.size() throws an IOException after reopening the channel, the newly opened channel in reopened will be leaked because it is never closed.
To prevent this resource leak, wrap the assignment and size check in a try-catch block, and call reopened.releaseOnFailure(e) to safely close the channel if an exception occurs during initialization. Catch IOException specifically instead of Throwable since this is not an asynchronous operation or Future boundary.
OpenedChannel reopened = reopenOrAllocate(logDir, id, activePath);
try {
activePath = reopened.path;
claimedGlobalPath = reopened.claimedGlobalPath;
channel = reopened.channel;
writtenBytes = channel.size();
} catch (IOException e) {
reopened.releaseOnFailure(e);
throw e;
}References
- Catching
Throwableinstead ofExceptionis acceptable at Future boundaries or during stream cleanup in asynchronous operations to ensure all failures are captured and propagated. For synchronous operations, catch specific exceptions likeIOException.
…tation-and-context # 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
Summary
PR 2 of 6 in the diagnostic logging stack (
b/584840147, part 2 of 3; stacked onfix/bq-jdbc-log-file-hardening). UpgradesChannelLogWritertoBoundedLogFileWriterwith bounded two-file (1 GiB+.1.logbackup) size rotation and introduces typedConnectionLogContextLogRecordparameter stamping.Environment Variables & System Properties
-Dcom.google.cloud.bigquery.jdbc.maxLogFileBytes=<bytes>(default:1073741824/ 1 GiB, parsed aslong). Configures the maximum byte size of an active driver.logfile before rotating onto a.1.logbackup file. Documented inREADME.MDanddocs/USER_GUIDE.md.Design Decisions
long) cap + single.1.log(0600) backup rotation (revisable): High-throughputResultSetiteration atLogLevel=6/7(FINER/FINEST) can emit tens of megabytes per minute, so a small cap or in-placetruncate(0)rollover would discard recent context right before an error. Rotating the full active file onto a single owner-only0600.1.logbackup (retaining 1–2 GiB / 30+ minutes of history per connection while bounding total disk usage to 2x cap) preserves diagnostic continuity. If.1.logrotation fails, the writer reopens/truncates cleanly and reports via JULErrorManager. (The 1 GiB default cap is a revisable threshold.)<base>.1.log): Uses a.1.logsuffix so rotated backups do not match active*-<shortId>.logfilters while remaining easy to locate alongside the active log.ConnectionLogContextover rawStringparams[0]: Replaces rawStringconnection-ID stamping inBigQueryJdbcResultSetLoggerwith package-privateConnectionLogContextso plainStringparameters logged by internal helpers are never misread as connection IDs, while preserving{0}..{9}positional formatting inOpenTelemetryJulHandler.