kevin-wu24 commented on code in PR #22669:
URL: https://github.com/apache/kafka/pull/22669#discussion_r3537984759


##########
jmh-benchmarks/src/main/java/org/apache/kafka/jmh/raft/LeaderBenchmarks.java:
##########
@@ -50,8 +50,7 @@ public class LeaderBenchmarks {
 
     /**
      * Starting state: the local node is Leader with the high watermark at the 
log end and a caught-up
-     * follower ready to fetch. Built once per trial and reused across 
invocations, since handling a
-     * caught-up fetch does not mutate it.
+     * follower ready to fetch.
      */
     @State(Scope.Thread)
     public static class LeaderWithCaughtUpFollower {

Review Comment:
   nit: Technically any follower request may or may not be caught up. The only 
thing we know is that the local node is leader and has the HWM at the end of 
its local log.



##########
raft/src/testFixtures/java/org/apache/kafka/raft/DrainableCounter.java:
##########
@@ -0,0 +1,45 @@
+/*
+ * 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.kafka.raft;
+
+import java.util.function.IntSupplier;
+
+/**
+ * Tracks a cumulative, monotonically increasing counter (e.g. the work 
counters on the raft mocks) as
+ * a drainable delta against a baseline. {@link #reset()} snapshots the 
current value (so the next
+ * {@link #delta()} starts from zero), and {@link #delta()} returns the 
increase since the last
+ * reset/delta and advances the baseline.
+ */
+final class DrainableCounter {
+    private final IntSupplier source;
+    private int baseline;
+
+    DrainableCounter(IntSupplier source) {
+        this.source = source;
+    }
+
+    void reset() {
+        baseline = source.getAsInt();
+    }

Review Comment:
   It seems odd that we don't set the baseline to a value when constructing the 
object. It means the user of the API needs to call `reset()` before calling 
`delta()` if the value from `source` is non-zero. 
   
   One thing I asee in the usages of this class currently is that we don't need 
`reset()`. We could call `delta()` to reset our baseline too right, and just 
throw away the returned value. What do you think?



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to