Skip to content

feat(bqjdbc): Per connection logs - Add BigQueryJdbcMdc#12833

Open
Neenu1995 wants to merge 9 commits intomainfrom
ns/mdc-per-conn-logs2
Open

feat(bqjdbc): Per connection logs - Add BigQueryJdbcMdc#12833
Neenu1995 wants to merge 9 commits intomainfrom
ns/mdc-per-conn-logs2

Conversation

@Neenu1995
Copy link
Copy Markdown
Contributor

@Neenu1995 Neenu1995 commented Apr 17, 2026

PR 1 of Per connection logging implementation.

  • Implements BigQueryJdbcMdc using an InheritableThreadLocal design and corresponding unit tests for verification.
  • Use DateTimeFormatter instead of SimpleDateFormat for better performance.

@Neenu1995 Neenu1995 requested review from a team as code owners April 17, 2026 16:44
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 introduces a lightweight MDC implementation for the BigQuery JDBC driver to track connection IDs and updates the logging formatter to use modern java.time APIs. The review feedback identifies several critical issues in the new BigQueryJdbcMdc class, including potential memory leaks from static maps holding connection references, thread-safety bugs in the clear() method, and performance inefficiencies caused by redundant InheritableThreadLocal instances. Suggestions were also provided to refine the connection removal logic and ensure side-effect-free mapping functions.

}
}

public static void clear() {
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.

So, this method clears the global instanceLocals and instanceIds maps. I understand its use in the tests (to reset state) but if this method is used in production code in finally blocks after every operation (as suggested in the design doc), it will wipe the context for other concurrent connections, no?

maybe im misreading it but just wanted to confirm if this is intended.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch. You're right, it gets cleared but then gets re-registered on a new method entry to preserve the intended behaviour, so I missed it. Fixed it now.

* instance.
*/
public class BigQueryJdbcMdc {
private static final AtomicLong nextId = new AtomicLong(1);
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.

Doubt: I think design doc says we use connection ID or UUID but here we are using incremental atomicLong? Am I confusing two different things?

Copy link
Copy Markdown
Contributor Author

@Neenu1995 Neenu1995 Apr 20, 2026

Choose a reason for hiding this comment

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

I am using this Atomic counter to generate a connection ID like JdbcConnection-N. Figured this pattern has better readability in logs.

@Neenu1995 Neenu1995 force-pushed the ns/mdc-per-conn-logs2 branch from e348c11 to 17920d4 Compare April 20, 2026 18:13
@Neenu1995 Neenu1995 requested a review from keshavdandeva April 20, 2026 18:15
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.

3 participants