Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Comment thread
keshavdandeva marked this conversation as resolved.
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 =
Expand All @@ -41,8 +40,7 @@ static MdcCloseable registerInstance(BigQueryConnection connection, String id) {
instanceIds.computeIfAbsent(
connection,
k -> {
String suffix =
(id != null && !id.isEmpty()) ? id : String.valueOf(nextId.getAndIncrement());
String suffix = (id != null && !id.isEmpty()) ? id : UUID.randomUUID().toString();
return "JdbcConnection-" + suffix;
});

Expand Down
Loading