Skip to content

feat(bqjdbc): Add BigQueryJdbcMdc context to entry level methods - part 3#12954

Open
Neenu1995 wants to merge 18 commits intomainfrom
integ-per-conn-logs
Open

feat(bqjdbc): Add BigQueryJdbcMdc context to entry level methods - part 3#12954
Neenu1995 wants to merge 18 commits intomainfrom
integ-per-conn-logs

Conversation

@Neenu1995
Copy link
Copy Markdown
Contributor

@Neenu1995 Neenu1995 commented Apr 29, 2026

b/501081433

  • MDC Context registration: In All API classes.

  • MDC Nesting Support: Updated BigQueryJdbcMdc.java to use a save-and-restore pattern, supporting safe nesting of contexts across different connections.

  • Eliminated high-frequency overhead: Removed the BigQueryJdbcMdc.registerInstance wrappers from hot path methods (such as next(), getObject(), and ResultSetMetadata getters) to significantly reduce the memory allocation and intermediate static map updates footprint.

  • Implemented fast Context setters:

    • setContextPersistent(String): Created a primitive non-AutoCloseable setter for high volume sequential traces with zero intermediate lambda allocations.
    • setContext(String): Replaced heavy instance hooks inside coarse statement methods (e.g., execute(), close(), getMoreResults()) with a lighter MdcCloseable context boundary operator.
  • Metadata Refactor: Split methods longer than 10 lines in BigQueryDatabaseMetaData and BigQueryResultSetMetadata to separate MDC setup from execution logic.

  • Logging Enhancements:

    • Added LOG.finest("++enter++") to almost all methods in core JDBC classes.
    • Added LOG.info to methods performing significant operations (like transactions and query processing).
    • Replaced the static ++enter++ trace defaults with dynamic parameter traces across principal API methods (e.g., getTables(), execute(sql)). Evaluated lazily only when Level.FINEST is active so non in-situ operational speeds are preserved.
    • Included explicit trace logging for incomplete callback hooks inside BigQueryJdbcBulkInsertWriter to prevent isolated error leaks.
    • Wrapped internal background task executors (tableProcessorExecutor and columnExecutor inside
      BigQueryDatabaseMetaData.java) with wrapWithMdc closures. This ensures background worker threads assume active connection context defaults seamlessly, avoiding orphaned tasks logged into NO_CONN.
  • Cleanup: Made LOG static in metadata and statement classes to support static contexts and cleaned up method signatures by removing passed logger instances.

@Neenu1995 Neenu1995 requested review from a team as code owners April 29, 2026 18:16
Copy link
Copy Markdown
Contributor

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

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 implements comprehensive MDC (Mapped Diagnostic Context) tracking and entry-level logging across the BigQuery JDBC driver. Key changes include refactoring public methods in BigQueryArrowResultSet, BigQueryJsonResultSet, BigQueryPreparedStatement, and BigQueryDatabaseMetaData to wrap operations in MDC context blocks, while moving core logic to internal implementation methods. Additionally, BigQueryJdbcMdc was updated to support nested context registration. The review feedback focuses on ensuring the close() method in BigQueryJsonResultSet is idempotent, replacing unsafe class casts with the standard JDBC unwrap pattern in BigQueryResultSetMetadata, and optimizing performance by eliminating redundant MDC registrations during internal method calls.

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