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



##########
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:
       Why do we need the second level here?

##########
File path: 
raft/src/main/java/org/apache/kafka/raft/metadata/MetaLogRaftShim.java
##########
@@ -124,6 +126,15 @@ public void handleCommit(BatchReader<ApiMessageAndVersion> 
reader) {
             }
         }
 
+        @Override
+        public void handleSnapshot(SnapshotReader<ApiMessageAndVersion> 
reader) {
+            // TODO: Create Jira: Handle loading commit in ListenerShim

Review comment:
       We can probably take care of this when we merge the two interfaces. I'm 
hoping to get to that shortly.

##########
File path: raft/src/main/java/org/apache/kafka/snapshot/SnapshotReader.java
##########
@@ -0,0 +1,153 @@
+/*
+ * 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.snapshot;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.NoSuchElementException;
+import org.apache.kafka.common.protocol.ByteBufferAccessor;
+import org.apache.kafka.common.record.Record;
+import org.apache.kafka.common.record.RecordBatch;
+import org.apache.kafka.common.utils.BufferSupplier;
+import org.apache.kafka.raft.OffsetAndEpoch;
+import org.apache.kafka.raft.RecordSerde;
+
+public final class SnapshotReader<T> implements Closeable, Iterable<List<T>> {

Review comment:
       I guess I'll renew my appeal to converge this interface with 
`BatchReader`. We really ought to be able to share some code.

##########
File path: raft/src/main/java/org/apache/kafka/raft/KafkaRaftClient.java
##########
@@ -2154,8 +2182,14 @@ private boolean maybeCompleteShutdown(long 
currentTimeMs) {
         return false;
     }
 
-    private void maybeUpdateOldestSnapshotId() {
-        log.latestSnapshotId().ifPresent(log::deleteBeforeSnapshot);
+    private void maybeUpdateEarliestSnapshotId() {

Review comment:
       nit: it seems like the objective here is deleting old snapshots, which 
is why we call `deleteBeforeSnaphshot`. Updating the earliest snapshot id seems 
more like a side effect.

##########
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) {

Review comment:
       I guess snapshots for this replicated counter would end up with a single 
value? 




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