mirror of https://github.com/apache/kafka.git
MINOR: fixing updateBrokerContactTime (#19828)
Fix `updateBrokerContactTime` so that existing brokers still have their contact time updated when they are already tracked. Also, update the unit test to test this case. Reviewers: Kuan-Po Tseng <brandboat@gmail.com>, Yung <yungyung7654321@gmail.com>, TengYao Chi <frankvicky@apache.org>, Ken Huang <s7133700@gmail.com>
This commit is contained in:
parent
383a9ff9df
commit
8731c96122
|
@ -267,7 +267,8 @@ public class QuorumControllerMetrics implements AutoCloseable {
|
|||
}
|
||||
|
||||
public void updateBrokerContactTime(int brokerId) {
|
||||
brokerContactTimesMs.putIfAbsent(brokerId, new AtomicLong(time.milliseconds()));
|
||||
AtomicLong contactTime = brokerContactTimesMs.computeIfAbsent(brokerId, k -> new AtomicLong());
|
||||
contactTime.set(time.milliseconds());
|
||||
}
|
||||
|
||||
public int timeSinceLastHeartbeatMs(int brokerId) {
|
||||
|
|
|
@ -179,6 +179,8 @@ public class QuorumControllerMetricsTest {
|
|||
metrics.updateBrokerContactTime(brokerId);
|
||||
time.sleep(1000);
|
||||
assertEquals(1000, timeSinceLastHeartbeatReceivedMs.value());
|
||||
metrics.updateBrokerContactTime(brokerId);
|
||||
assertEquals(0, timeSinceLastHeartbeatReceivedMs.value());
|
||||
time.sleep(100000);
|
||||
assertEquals(sessionTimeoutMs, timeSinceLastHeartbeatReceivedMs.value());
|
||||
metrics.removeTimeSinceLastHeartbeatMetrics();
|
||||
|
|
Loading…
Reference in New Issue