Skip to content

Commit

Permalink
chore: remove unnecessary variable (#2400)
Browse files Browse the repository at this point in the history
Change-Id: Ide37e9226983ffaa32d8d2cda03c1fd8d1ad7fff

Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:
- [ ] Make sure to open an issue as a [bug/issue](https://togithub.com/googleapis/java-bigtable/issues/new/choose) before writing your code!  That way we can discuss the change, evaluate designs, and agree on the general idea
- [ ] Ensure the tests and linter pass
- [ ] Code coverage does not decrease (if any source code was changed)
- [ ] Appropriate docs were updated (if necessary)
- [ ] Rollback plan is reviewed and LGTMed
- [ ] All new data plane features have a completed end to end testing plan

Fixes #<issue_number_goes_here> ☕️

If you write sample code, please follow the [samples format](
https://togithub.com/GoogleCloudPlatform/java-docs-samples/blob/main/SAMPLE_FORMAT.md).
  • Loading branch information
igorbernstein2 authored Nov 4, 2024
1 parent 0ad0c95 commit e7ffbda
Showing 1 changed file with 5 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ class BuiltinMetricsTracer extends BigtableTracer {
// Stopwatch is not thread safe so this is a workaround to check if the stopwatch changes is
// flushed to memory.
private final Stopwatch serverLatencyTimer = Stopwatch.createUnstarted();
private boolean serverLatencyTimerIsRunning = false;
private final Object timerLock = new Object();

private boolean flowControlIsDisabled = false;
Expand Down Expand Up @@ -163,9 +162,8 @@ public void attemptStarted(Object request, int attemptNumber) {
}
if (!flowControlIsDisabled) {
synchronized (timerLock) {
if (!serverLatencyTimerIsRunning) {
if (!serverLatencyTimer.isRunning()) {
serverLatencyTimer.start();
serverLatencyTimerIsRunning = true;
}
}
}
Expand Down Expand Up @@ -198,9 +196,8 @@ public void onRequest(int requestCount) {
// On request is only called when auto flow control is disabled. When auto flow control is
// disabled, server latency is measured between onRequest and onResponse.
synchronized (timerLock) {
if (!serverLatencyTimerIsRunning) {
if (!serverLatencyTimer.isRunning()) {
serverLatencyTimer.start();
serverLatencyTimerIsRunning = true;
}
}
}
Expand All @@ -219,10 +216,9 @@ public void responseReceived() {
// latency is measured between afterResponse and responseReceived.
// In all the cases, we want to stop the serverLatencyTimer here.
synchronized (timerLock) {
if (serverLatencyTimerIsRunning) {
if (serverLatencyTimer.isRunning()) {
totalServerLatencyNano.addAndGet(serverLatencyTimer.elapsed(TimeUnit.NANOSECONDS));
serverLatencyTimer.reset();
serverLatencyTimerIsRunning = false;
}
}
}
Expand All @@ -235,9 +231,8 @@ public void afterResponse(long applicationLatency) {
// received. If flow control is disabled but requestLeft is greater than 0,
// also start the timer to count the time between afterResponse and responseReceived.
synchronized (timerLock) {
if (!serverLatencyTimerIsRunning) {
if (!serverLatencyTimer.isRunning()) {
serverLatencyTimer.start();
serverLatencyTimerIsRunning = true;
}
}
}
Expand Down Expand Up @@ -324,11 +319,10 @@ private void recordAttemptCompletion(@Nullable Throwable status) {
// If the attempt failed, the time spent in retry should be counted in application latency.
// Stop the stopwatch and decrement requestLeft.
synchronized (timerLock) {
if (serverLatencyTimerIsRunning) {
if (serverLatencyTimer.isRunning()) {
requestLeft.decrementAndGet();
totalServerLatencyNano.addAndGet(serverLatencyTimer.elapsed(TimeUnit.NANOSECONDS));
serverLatencyTimer.reset();
serverLatencyTimerIsRunning = false;
}
}

Expand Down

0 comments on commit e7ffbda

Please sign in to comment.