This is an automated email from the ASF dual-hosted git repository.
gian pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/druid.git
The following commit(s) were added to refs/heads/master by this push:
new dc1c4d92737 Fix stop race in MonitorScheduler. (#19161)
dc1c4d92737 is described below
commit dc1c4d927371f77d9edcff59ef1b655421030b97
Author: Gian Merlino <[email protected]>
AuthorDate: Mon Mar 16 10:55:49 2026 -0700
Fix stop race in MonitorScheduler. (#19161)
When MonitorScheduler "stop" is called, it in turn calls "removeMonitor".
This calls "monitor" on all monitors. The whole process is synchronized
on the MonitorScheduler itself, but it is not synchronized with the
regularly-scheduled calls to "monitor". It can lead to "monitor" running
concurrently with itself, which can lead to unpredictable behavior in
metrics emission.
One likely effect of this would be to emit metrics twice, due to the
common pattern of snapshot -> emit deltas from previous snapshot ->
save snapshot.
This patch also removes the unused CompoundMonitor.
---
.../druid/java/util/metrics/AbstractMonitor.java | 2 +-
.../druid/java/util/metrics/CompoundMonitor.java | 65 ----------------------
.../apache/druid/java/util/metrics/Monitor.java | 3 +-
3 files changed, 3 insertions(+), 67 deletions(-)
diff --git
a/processing/src/main/java/org/apache/druid/java/util/metrics/AbstractMonitor.java
b/processing/src/main/java/org/apache/druid/java/util/metrics/AbstractMonitor.java
index 3fa5fc5c9c1..44386f9d20b 100644
---
a/processing/src/main/java/org/apache/druid/java/util/metrics/AbstractMonitor.java
+++
b/processing/src/main/java/org/apache/druid/java/util/metrics/AbstractMonitor.java
@@ -48,7 +48,7 @@ public abstract class AbstractMonitor implements Monitor
}
@Override
- public boolean monitor(ServiceEmitter emitter)
+ public synchronized boolean monitor(ServiceEmitter emitter)
{
if (started) {
return doMonitor(emitter);
diff --git
a/processing/src/main/java/org/apache/druid/java/util/metrics/CompoundMonitor.java
b/processing/src/main/java/org/apache/druid/java/util/metrics/CompoundMonitor.java
deleted file mode 100644
index 676c77a772f..00000000000
---
a/processing/src/main/java/org/apache/druid/java/util/metrics/CompoundMonitor.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.druid.java.util.metrics;
-
-import com.google.common.collect.Lists;
-import org.apache.druid.java.util.emitter.service.ServiceEmitter;
-
-import java.util.Arrays;
-import java.util.List;
-
-public abstract class CompoundMonitor implements Monitor
-{
- private final List<Monitor> monitors;
-
- public CompoundMonitor(List<Monitor> monitors)
- {
- this.monitors = monitors;
- }
-
- public CompoundMonitor(Monitor... monitors)
- {
- this(Arrays.asList(monitors));
- }
-
- @Override
- public void start()
- {
- for (Monitor monitor : monitors) {
- monitor.start();
- }
- }
-
- @Override
- public void stop()
- {
- for (Monitor monitor : monitors) {
- monitor.stop();
- }
- }
-
- @Override
- public boolean monitor(final ServiceEmitter emitter)
- {
- return shouldReschedule(Lists.transform(monitors, monitor ->
monitor.monitor(emitter)));
- }
-
- public abstract boolean shouldReschedule(List<Boolean> reschedules);
-}
diff --git
a/processing/src/main/java/org/apache/druid/java/util/metrics/Monitor.java
b/processing/src/main/java/org/apache/druid/java/util/metrics/Monitor.java
index 8ddb3fa8301..356f39d6435 100644
--- a/processing/src/main/java/org/apache/druid/java/util/metrics/Monitor.java
+++ b/processing/src/main/java/org/apache/druid/java/util/metrics/Monitor.java
@@ -31,7 +31,8 @@ public interface Monitor
void stop();
/**
- * Emit metrics using the given emitter.
+ * Emit metrics using the given emitter. May be called from two separate
threads: the scheduling thread and
+ * a lifecycle thread that is shutting down monitors. Therefore, this method
must be thread-safe.
*
* @return true if this monitor needs to continue monitoring. False
otherwise.
*/
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]