-
Notifications
You must be signed in to change notification settings - Fork 1.1k
chore(bqjdbc): switch connection identifier to UUID #12957
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,16 +16,15 @@ | |
|
|
||
| package com.google.cloud.bigquery.jdbc; | ||
|
|
||
| import java.util.UUID; | ||
| import java.util.concurrent.ConcurrentHashMap; | ||
| import java.util.concurrent.atomic.AtomicLong; | ||
|
|
||
| /** | ||
| * Lightweight MDC implementation for the BigQuery JDBC driver using InheritableThreadLocal. | ||
| * Allocates a dedicated, independent InheritableThreadLocal object per concrete BigQueryConnection | ||
| * instance. | ||
| */ | ||
| class BigQueryJdbcMdc { | ||
| private static final AtomicLong nextId = new AtomicLong(1); | ||
| private static final ConcurrentHashMap<BigQueryConnection, InheritableThreadLocal<String>> | ||
| instanceLocals = new ConcurrentHashMap<>(); | ||
| private static final ConcurrentHashMap<BigQueryConnection, String> instanceIds = | ||
|
|
@@ -41,9 +40,8 @@ static MdcCloseable registerInstance(BigQueryConnection connection, String id) { | |
| instanceIds.computeIfAbsent( | ||
| connection, | ||
| k -> { | ||
| String suffix = | ||
| (id != null && !id.isEmpty()) ? id : String.valueOf(nextId.getAndIncrement()); | ||
| return "JdbcConnection-" + suffix; | ||
| String baseId = (id != null && !id.isEmpty()) ? id : UUID.randomUUID().toString(); | ||
| return "BQ-JDBC-" + baseId; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: don't think we need
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The user application many have logs generated from other sources. For the file name I think it is useful if we keep the BQ-JDBC prefix. Same with the connection ID, if the user Application is logging from multiple sources , it will be helpful to identify the logs generated by the JDBC Driver.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, but that's the internal ID, not the filename |
||
| }); | ||
|
|
||
| currentConnectionId.set(cleanId); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,8 @@ | |
| import java.nio.file.Files; | ||
| import java.nio.file.Path; | ||
| import java.nio.file.Paths; | ||
| import java.time.LocalDateTime; | ||
| import java.time.format.DateTimeFormatter; | ||
| import java.util.concurrent.ConcurrentHashMap; | ||
| import java.util.logging.FileHandler; | ||
| import java.util.logging.Handler; | ||
|
|
@@ -53,7 +55,13 @@ class PerConnectionFileHandler extends Handler { | |
| } | ||
|
|
||
| private String getLogFilePath(String id) { | ||
| return baseLogPath.resolve("BigQuery-" + id + ".log").toString(); | ||
| String uuid = id; | ||
| if (id.startsWith("BQ-JDBC-")) { | ||
| uuid = id.substring("BQ-JDBC-".length()); | ||
| } | ||
| String timestamp = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss")); | ||
| String shortUuid = uuid.length() >= 4 ? uuid.substring(0, 4) : uuid; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: no need for that check, uuid will never be shorter than 4 |
||
| return baseLogPath.resolve("BQ-JDBC-" + timestamp + "-" + shortUuid + ".log").toString(); | ||
| } | ||
|
|
||
| private FileHandler createFileHandler(String id) { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.