|
31 | 31 | import java.util.List;
|
32 | 32 | import java.util.Map;
|
33 | 33 | import java.util.Optional;
|
34 |
| -import java.util.OptionalLong; |
35 | 34 | import java.util.concurrent.ConcurrentHashMap;
|
36 | 35 | import java.util.concurrent.atomic.AtomicLong;
|
37 | 36 | import java.util.function.Consumer;
|
@@ -82,15 +81,15 @@ public class QuorumControllerMetrics implements AutoCloseable {
|
82 | 81 | private final AtomicLong lastAppliedRecordTimestamp = new AtomicLong(0);
|
83 | 82 | private final Consumer<Long> eventQueueTimeUpdater;
|
84 | 83 | private final Consumer<Long> eventQueueProcessingTimeUpdater;
|
85 |
| - public final TimeRatio avgIdleTimeRatio; |
| 84 | + private final TimeRatio avgIdleTimeRatio; |
86 | 85 |
|
87 | 86 | private final AtomicLong timedOutHeartbeats = new AtomicLong(0);
|
88 | 87 | private final AtomicLong operationsStarted = new AtomicLong(0);
|
89 | 88 | private final AtomicLong operationsTimedOut = new AtomicLong(0);
|
90 | 89 | private final AtomicLong newActiveControllers = new AtomicLong(0);
|
91 | 90 | private final Map<Integer, Long> brokerContactTimesMs = new ConcurrentHashMap<>();
|
92 | 91 | private final int sessionTimeoutMs;
|
93 |
| - private volatile OptionalLong idleStartTime = OptionalLong.empty(); |
| 92 | + private final AtomicLong idleStartTime = new AtomicLong(-1); |
94 | 93 |
|
95 | 94 | private Consumer<Long> newHistogram(MetricName name, boolean biased) {
|
96 | 95 | if (registry.isPresent()) {
|
@@ -176,18 +175,17 @@ public Double value() {
|
176 | 175 | }
|
177 | 176 |
|
178 | 177 | public void updateIdleStartTime() {
|
179 |
| - if (idleStartTime.isEmpty()) { |
180 |
| - idleStartTime = OptionalLong.of(time.milliseconds()); |
181 |
| - } |
| 178 | + idleStartTime.compareAndExchange(-1, time.milliseconds()); |
182 | 179 | }
|
183 | 180 |
|
184 | 181 | public void updateIdleEndTime() {
|
185 |
| - if (this.idleStartTime.isPresent()) { |
186 |
| - long idleDurationMs = Math.max(time.milliseconds() - idleStartTime.getAsLong(), 0); |
| 182 | + long startTime = idleStartTime.getAndSet(-1); |
| 183 | + if (startTime != -1) { |
| 184 | + long idleDurationMs = Math.max(time.milliseconds() - startTime, 0); |
187 | 185 | avgIdleTimeRatio.record(METRIC_CONFIG, (double) idleDurationMs, time.milliseconds());
|
188 |
| - idleStartTime = OptionalLong.empty(); |
189 | 186 | }
|
190 | 187 | }
|
| 188 | + |
191 | 189 | public void addTimeSinceLastHeartbeatMetric(int brokerId) {
|
192 | 190 | brokerContactTimesMs.put(brokerId, time.milliseconds());
|
193 | 191 | registry.ifPresent(r -> r.newGauge(
|
|
0 commit comments