feat(bqjdbc): Per connection logs - Add BigQueryJdbcMdc#12833
feat(bqjdbc): Per connection logs - Add BigQueryJdbcMdc#12833
Conversation
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
I am using this Atomic counter to generate a connection ID like JdbcConnection-N. Figured this pattern has better readability in logs.
e348c11 to
17920d4
Compare
PR 1 of Per connection logging implementation.