kevin-wu24 commented on code in PR #18304: URL: https://github.com/apache/kafka/pull/18304#discussion_r1926140480
########## raft/src/main/java/org/apache/kafka/raft/internals/KRaftControlRecordStateMachine.java: ########## @@ -87,14 +91,21 @@ public KRaftControlRecordStateMachine( RecordSerde<?> serde, BufferSupplier bufferSupplier, int maxBatchSizeBytes, - LogContext logContext + LogContext logContext, + KafkaRaftMetrics kafkaRaftMetrics, + ExternalKRaftMetrics externalKRaftMetrics ) { this.log = log; this.voterSetHistory = new VoterSetHistory(staticVoterSet, logContext); this.serde = serde; this.bufferSupplier = bufferSupplier; this.maxBatchSizeBytes = maxBatchSizeBytes; this.logger = logContext.logger(this.getClass()); + this.kafkaRaftMetrics = kafkaRaftMetrics; + this.externalKRaftMetrics = externalKRaftMetrics; + this.staticVoterSet = Optional.ofNullable(staticVoterSet); + + this.staticVoterSet.ifPresent(voters -> kafkaRaftMetrics.updateNumVoters(voters.size())); Review Comment: `truncateOldEntries` never truncates the latest entry: ``` @Override public void truncateOldEntries(long startOffset) { NavigableMap<Long, T> lesserValues = history.headMap(startOffset, true); while (lesserValues.size() > 1) { // Poll and ignore the entry to remove the first entry lesserValues.pollFirstEntry(); } } ``` However, with `truncateNewEntries`, I'm not sure how we should be updating our metric properly. Given we already claim a lock on `voterSetHistory` to perform the truncation, is this an exception where we can synchronously update the metric? In the case where all log entries of voter sets are truncated by this function, the metric should report the number of voters in the static configuration correct? -- 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