jsancio commented on a change in pull request #10085:
URL: https://github.com/apache/kafka/pull/10085#discussion_r610944539



##########
File path: raft/src/main/java/org/apache/kafka/raft/ReplicatedCounter.java
##########
@@ -68,20 +70,65 @@ public synchronized void increment() {
     @Override
     public synchronized void handleCommit(BatchReader<Integer> reader) {
         try {
-            int initialValue = this.committed;
+            int initialValue = committed;
             while (reader.hasNext()) {
                 BatchReader.Batch<Integer> batch = reader.next();
                 log.debug("Handle commit of batch with records {} at base 
offset {}",
                     batch.records(), batch.baseOffset());
                 for (Integer value : batch.records()) {
-                    if (value != this.committed + 1) {
-                        throw new AssertionError("Expected next committed 
value to be " +
-                            (this.committed + 1) + ", but instead found " + 
value + " on node " + nodeId);
+                    if (value != committed + 1) {
+                        throw new AssertionError(
+                            String.format(
+                                "Expected next committed value to be %s, but 
instead found %s on node %s",
+                                committed + 1,
+                                value,
+                                nodeId
+                            )
+                        );
                     }
-                    this.committed = value;
+                    committed = value;
                 }
+
+                nextReadOffset = batch.lastOffset() + 1;
+                readEpoch = batch.epoch();
             }
             log.debug("Counter incremented from {} to {}", initialValue, 
committed);
+
+            if (lastSnapshotEndOffset + 10 < nextReadOffset) {

Review comment:
       Hmm. We should only generate snapshots at batch boundaries. There is no 
guarantee that the `lastOffset` of a batch is a multiple of some number since 
batches can any number of records.




-- 
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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to