jsancio commented on a change in pull request #9512: URL: https://github.com/apache/kafka/pull/9512#discussion_r517703078
########## File path: raft/src/main/java/org/apache/kafka/snapshot/SnapshotReader.java ########## @@ -0,0 +1,36 @@ +/* + * 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.nio.ByteBuffer; +import java.util.Iterator; +import org.apache.kafka.common.record.RecordBatch; +import org.apache.kafka.raft.OffsetAndEpoch; + +// TODO: Write documentation for this type and all of the methods +public interface SnapshotReader extends Closeable, Iterable<RecordBatch> { Review comment: This comment applies to some of your other observations. At high-level there are 4 use cases that we need to design and implement. Two use cases are for the Raft implementation. Two use cases are for the state machine. ### Raft implementation These types are internal to the raft implementation and don't have to be exposed to the state machine. #### Leader Use Case The leader needs to be able to send a part of the snapshot over the network. Something like this ```java interface SnapshotReader extends Closeable { long transferTo(long position, long maxBytes, WritableChannel channel); int read(ByteBuffer buffer, long position); } ``` #### Follower Use Case The followers need to be able to copy bytes from the network and validate the snapshot on disk when fetching is done. ```java interface SnapshotWriter extends Closeable { void append(ByteBuffer buffer); void validate(); void freeze(); } ``` ### State machine implementation These types are exposed to the state machine. #### Load Snapshot The state machine needs to be able to load/scan the entire snapshot. The state machine can use `close` to tell the raft client that it finished loading the snapshot. This will be implemented in a future PR but it could look like this: ```java interface BatchedSnapshotReader<T> extends Iterable<Iterable<T>>, Closeable { } ``` #### Generate Snapshot The state machine needs to be able to generate a snapshot by appending records/values and marking the snapshot as immutable (`freeze`) when it is done. ```java interface BatchdSnapshotWriter<T> extends Closeable { void append(Iterable<T> records); void freeze(); } ``` ### Notes `SnapshotWriter` and `SnapshotReader` need to be interfaces because we will have a real implementation and a mocked implementation for testing. These two types are internal to raft and are not exposed to the state machine. `BatchedSnapshotReader` and `BatchedSnapshotWriter` can depend on `SnapshotWriter` and `SnapshotReade` to reuse some code but this is not strictly required. These two type don't have to be `interfaces` if they delegate the IO to `SnapshotWriter` and `SnapshotReader`. What do you think @hachikuji? ---------------------------------------------------------------- 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