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



##########
File path: raft/src/main/java/org/apache/kafka/raft/ReplicatedCounter.java
##########
@@ -87,6 +96,25 @@ public synchronized void handleCommit(BatchReader<Integer> 
reader) {
         }
     }
 
+    @Override
+    public synchronized void handleSnapshot(SnapshotReader<Integer> reader) {
+        try {
+            try (SnapshotReader<Integer> snapshot = reader) {
+                log.debug("Loading snapshot {}", snapshot.snapshotId());
+                for (List<Integer> batch : snapshot) {
+                    for (Integer value : batch) {
+                        log.debug("Setting value: {}", value);
+                        this.committed = value;
+                        this.uncommitted = value;
+                    }
+                }
+                log.debug("Finished loading snapshot. Set value: {}", 
this.committed);
+            }
+        } catch (IOException e) {

Review comment:
       This is because `SnapshotReader::close` was declare as throwing an 
`IOException`.
   
   This made the API for `SnapshotReader` confusing as `hasNext` and `next` 
don't throw an `IOException` even though they read from disk in some cases. I 
fixed this by changing `SnapshotReader` to implement `AutoCloseable` instead of 
`Closeable`.




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