apalan60 commented on code in PR #19888: URL: https://github.com/apache/kafka/pull/19888#discussion_r2128497097
########## metadata/src/main/java/org/apache/kafka/controller/metrics/QuorumControllerMetrics.java: ########## @@ -267,19 +267,15 @@ public long newActiveControllers() { } public void updateBrokerContactTime(int brokerId) { - AtomicLong contactTime = brokerContactTimesMs.computeIfAbsent(brokerId, k -> new AtomicLong()); - contactTime.set(time.milliseconds()); + brokerContactTimesMs.put(brokerId, time.milliseconds()); } public int timeSinceLastHeartbeatMs(int brokerId) { - if (!brokerContactTimesMs.containsKey(brokerId)) { + Long lastTime = brokerContactTimesMs.get(brokerId); + if (lastTime == null) { return sessionTimeoutMs; - } else { - return Math.min( - (int) (time.milliseconds() - brokerContactTimesMs.get(brokerId).get()), - sessionTimeoutMs - ); Review Comment: After reviewing the call path, I realized that `timeSinceLastHeartbeatMs ` is only used inside `addTimeSinceLastHeartbeatMetric`, which always puts the value into `brokerContactTimesMs `before the gauge is registered. So the map should never return null for that key. Given that, I think it makes sense to simply remove the null check altogether. Will update accordingly. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org