Repository navigation
fix(bigquery-jdbc): harden Clearcut opt-out lifecycle and preserve DataSource URL opt-out #15394
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
Changes from all commits
7ede96a
d284c85
9e67769
1b0a793
06efe55
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 |
|---|---|---|
|
|
@@ -68,6 +68,10 @@ final class TelemetryBatcher implements AutoCloseable { | |
| private volatile boolean backoffActive; | ||
|
|
||
| private final AtomicBoolean isClosed = new AtomicBoolean(false); | ||
| // Set concurrently by close(false) without acquiring flushLock so opt-out or suppression | ||
| // teardown never blocks on an in-flight upload and aborts or skips requeue on the batcher | ||
| // thread. | ||
| private volatile boolean discardPending = false; | ||
|
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. I'd suggest just passing it as argument since it is only 2 methods
Contributor
Author
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.
|
||
| private final AtomicBoolean flushPending = new AtomicBoolean(); | ||
| private final AtomicLong currentScheduleDelayMs = new AtomicLong(-1); | ||
| private volatile ScheduledFuture<?> scheduledTask; | ||
|
|
@@ -132,11 +136,30 @@ private boolean isConfigured() { | |
|
|
||
| @Override | ||
| public void close() { | ||
| close(true); | ||
| } | ||
|
|
||
| /** | ||
| * Stops background flushing. | ||
| * | ||
| * <p>Called with {@code flush = false} on opt-out, suppression, or race-loser teardown so | ||
| * buffered metrics are discarded immediately without attempting an outbound upload or blocking on | ||
| * an in-flight flush. | ||
| */ | ||
| void close(boolean flush) { | ||
|
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. When do we call it with false?
Contributor
Author
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. It's called via
Updated the |
||
| if (!flush) { | ||
| discardPending = true; | ||
| } | ||
| if (isClosed.compareAndSet(false, true)) { | ||
| if (scheduledTask != null) { | ||
| scheduledTask.cancel(false); | ||
| } | ||
| boolean flushed = flushOnClose(); | ||
| boolean flushed = false; | ||
| if (flush) { | ||
| flushed = flushOnClose(); | ||
| } else { | ||
|
keshavdandeva marked this conversation as resolved.
Resolved
|
||
| metricsMap = new ConcurrentHashMap<>(); | ||
| } | ||
| if (ownsExecutor && executorService != null) { | ||
| if (flushed) { | ||
| executorService.shutdown(); | ||
|
|
@@ -206,7 +229,10 @@ private <A extends TelemetryAccumulator> A getOrAddAccumulator(TelemetryKey key) | |
| TransportResult flush() { | ||
| flushLock.lock(); | ||
| try { | ||
| if (!isConfigured()) { | ||
| if (!isConfigured() || discardPending) { | ||
| if (discardPending) { | ||
| this.metricsMap = new ConcurrentHashMap<>(); | ||
|
keshavdandeva marked this conversation as resolved.
Resolved
|
||
| } | ||
| return TransportResult.disabled(); | ||
| } | ||
|
|
||
|
|
@@ -232,6 +258,12 @@ TransportResult flush() { | |
| accumulator.addToPayload(payloadBuilder); | ||
| } | ||
|
|
||
| // Re-check before sending: close(false) may set discardPending concurrently without | ||
| // flushLock. | ||
| if (discardPending) { | ||
|
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. Actually this is also unreachable? Line 226
Contributor
Author
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. Reachable under concurrency: |
||
| return TransportResult.disabled(); | ||
| } | ||
|
|
||
| TransportResult result; | ||
| try { | ||
| result = transport.send(payloadBuilder.build()); | ||
|
|
@@ -241,6 +273,11 @@ TransportResult flush() { | |
| } | ||
|
|
||
| if (!result.isSuccess()) { | ||
| // Re-check after send: close(false) may have fired (or interrupted send) while in flight; | ||
| // skip re-merging discarded metrics back into metricsMap. | ||
| if (discardPending) { | ||
|
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. This is unreachable? Line 255 should return
Contributor
Author
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. Also reachable under concurrency: if |
||
| return result; | ||
| } | ||
| // Suppress the size trigger until a flush succeeds; reschedule() below spaces the retries. | ||
| backoffActive = true; | ||
| // Simple requeue logic for failed requests | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Careful when merging with @Neenu1995 changes around datasource