Skip to content

Commit

Permalink
Fix a race condition in WatcherCleanerTest.testDeadWatcherMetrics
Browse files Browse the repository at this point in the history
Because the metrics were updated _after_ the listener is invoked, the listener does not always see
the fresh metric value. This fixes it so that the updated metric value is always visible to the
listener.
  • Loading branch information
PapaCharlie committed Mar 8, 2023
1 parent 4f84cf3 commit 84afb8c
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,13 @@ public void run() {
cleaners.schedule(new WorkRequest() {
@Override
public void doWork() throws Exception {
ServerMetrics.getMetrics().DEAD_WATCHERS_CLEARED.add(total);
totalDeadWatchers.addAndGet(-total);
long startTime = Time.currentElapsedTime();
listener.processDeadWatchers(snapshot);
long latency = Time.currentElapsedTime() - startTime;
LOG.info("Takes {} to process {} watches", latency, total);
ServerMetrics.getMetrics().DEAD_WATCHERS_CLEANER_LATENCY.add(latency);
ServerMetrics.getMetrics().DEAD_WATCHERS_CLEARED.add(total);
totalDeadWatchers.addAndGet(-total);
synchronized (processingCompletedEvent) {
processingCompletedEvent.notifyAll();
}
Expand Down

0 comments on commit 84afb8c

Please sign in to comment.