Skip to content

fix(bigquery-jdbc): isolate per-connection log handlers with graceful path degradation - #15168

Open
Neenu1995 wants to merge 4 commits into
fix/bq-jdbc-url-log-maskingfrom
fix/bq-jdbc-per-conn-log-isolation
Open

Neenu1995 wants to merge 4 commits into
fix/bq-jdbc-url-log-maskingfrom
fix/bq-jdbc-per-conn-log-isolation

Conversation

@Neenu1995

Copy link
Copy Markdown
Contributor

Summary

PR 5 of 6 in the diagnostic logging stack (b/584840083, part 2 of 2; stacked on fix/bq-jdbc-url-log-masking). Replaces global handler replacement on BigQueryJdbcRootLogger with a persistent multi-connection PerConnectionFileHandler so concurrent connections maintain isolated (LogLevel, LogPath) slots and preserve shared JUL/OpenTelemetry handlers.

Environment Variables & System Properties

  • New Environment Variables / System Properties: None added in this PR (refines existing BIGQUERY_JDBC_LOG_LEVEL and BIGQUERY_JDBC_LOG_PATH handling so BQ-JDBC-GLOBAL.log is opened only when both JVM-level environment variables are configured).

Design Decisions

  • Single persistent PerConnectionFileHandler with per-connection (LogPath, LogLevel) slots: Previously, opening a new connection replaced and closed the single FileHandler on com.google.cloud.bigquery, redirecting or silencing concurrent connections. Storing per-connectionId slots inside one persistent handler isolates file destinations and thresholds across concurrent connections.
  • Dynamic root logger threshold & external handler preservation: Computes the com.google.cloud.bigquery root level as the minimum (most verbose) active level across open connections, preserves OpenTelemetryJulHandler, ConsoleHandler, and externally attached JUL handlers when a connection specifies LogLevel=0, and restores any external handler floor when verbose connections close.
  • One-shot graceful LogPath degradation: If a connection's LogPath is unwritable, read-only, non-directory, symlinked, or syntactically invalid, registerConnection / publishIfOpen closes that connection's file slot and reports once via JUL ErrorManager without throwing from DriverManager.getConnection(...) or retrying failed file opens on every subsequent log record.

… path degradation

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

Isolates per-connection LogLevel and LogPath slots inside a single persistent PerConnectionFileHandler without stripping OpenTelemetryJulHandler or external JUL handlers on LogLevel=0, degrades gracefully on unwritable/invalid/symlinked LogPath without failing Driver.connect, and computes the root logger threshold dynamically across open connections.
@Neenu1995
Neenu1995 requested review from a team as code owners November 23, 2026 20:01

@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 updates the BigQuery JDBC driver's logging mechanism to support per-connection logging levels and paths, introducing PerConnectionFileHandler and updating BigQueryJdbcRootLogger to dynamically manage active connections and handle external handlers. The review feedback suggests two key improvements: passing the exception object directly to logger.log instead of using string concatenation to preserve the stack trace, and explicitly resetting several static fields in resetForTesting() to prevent state leakage and ensure test isolation.

Comment on lines +384 to +386
} catch (Exception ex) {
logger.warning("Log File warning : " + ex);
}

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.

medium

When catching an exception and logging it, avoid using string concatenation with the exception object (e.g., + ex) as it discards the stack trace and makes debugging difficult. Instead, pass the exception object as the third argument to logger.log to preserve the full stack trace.

Suggested change
} catch (Exception ex) {
logger.warning("Log File warning : " + ex);
}
} catch (Exception ex) {
logger.log(Level.WARNING, "Log File warning", ex);
}

Comment on lines +425 to 442
static synchronized void resetForTesting() {
for (String id : ACTIVE_CONNECTIONS.keySet()) {
ConnectionLogContext ctx = ACTIVE_CONNECTIONS.remove(id);
if (ctx != null) {
ctx.setLevelValue(ConnectionLogContext.OFF_VALUE);
}
if (persistentFileHandler != null) {
persistentFileHandler.closeHandler(id);
}
}
if (fileHandler != null) {
fileHandler.close();
logger.removeHandler(fileHandler);
fileHandler = null;
}
explicitGlobalLevel = Level.OFF;
refreshEffectiveRootLevel();
}

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.

medium

To prevent state leakage and ensure test isolation, explicitly reset the static fields lastDriverAppliedLevel, hasExternalFloor, and externalFloorLevel to their default values in resetForTesting() before calling refreshEffectiveRootLevel().

  static synchronized void resetForTesting() {
    for (String id : ACTIVE_CONNECTIONS.keySet()) {
      ConnectionLogContext ctx = ACTIVE_CONNECTIONS.remove(id);
      if (ctx != null) {
        ctx.setLevelValue(ConnectionLogContext.OFF_VALUE);
      }
      if (persistentFileHandler != null) {
        persistentFileHandler.closeHandler(id);
      }
    }
    if (fileHandler != null) {
      fileHandler.close();
      logger.removeHandler(fileHandler);
      fileHandler = null;
    }
    explicitGlobalLevel = Level.OFF;
    lastDriverAppliedLevel = null;
    hasExternalFloor = false;
    externalFloorLevel = null;
    refreshEffectiveRootLevel();
  }

@Neenu1995
Neenu1995 added this pull request to stack #15170 November 23, 2026 20:21
@Neenu1995
Neenu1995 force-pushed the fix/bq-jdbc-per-conn-log-isolation branch from 63f8a7c to 3b01d92 Compare November 23, 2026 20:23
@Neenu1995
Neenu1995 requested a review from a team as a code owner November 23, 2026 20:23
@Neenu1995
Neenu1995 force-pushed the fix/bq-jdbc-per-conn-log-isolation branch from 3b01d92 to a209aeb Compare November 23, 2026 20:58
@Neenu1995 Neenu1995 changed the title [WIP] fix(bigquery-jdbc): isolate per-connection log handlers with graceful path degradation fix(bigquery-jdbc): isolate per-connection log handlers with graceful path degradation Nov 24, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant