You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by GitBox <gi...@apache.org> on 2021/11/24 15:35:34 UTC

[GitHub] [kafka] jsancio commented on a change in pull request #11529: KAFKA-12932: Interfaces for SnapshotReader and SnapshotWriter

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



##########
File path: raft/src/main/java/org/apache/kafka/snapshot/FileSnapshotReader.java
##########
@@ -0,0 +1,52 @@
+/*
+ * 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 org.apache.kafka.raft.OffsetAndEpoch;
+import java.util.Iterator;
+import org.apache.kafka.raft.Batch;
+
+/**
+ * Interface of the snapshot reader
+ */
+public interface FileSnapshotReader<T> extends AutoCloseable, Iterator<Batch<T>> {

Review comment:
       How about naming this interface `SnapshotReader` and renaming the class `SnapshotReader` to `RecordsSnapshotReader`

##########
File path: raft/src/main/java/org/apache/kafka/snapshot/FileSnapshotWriter.java
##########
@@ -0,0 +1,68 @@
+/*
+ * 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 org.apache.kafka.raft.OffsetAndEpoch;
+import org.apache.kafka.common.message.SnapshotFooterRecord;
+
+import java.util.List;
+public interface FileSnapshotWriter<T> extends AutoCloseable {

Review comment:
       How about naming this interface `SnapshotWriter` and renaming the class `SnapshotWriter` to `RecordsSnapshotWriter`

##########
File path: raft/src/main/java/org/apache/kafka/snapshot/FileSnapshotWriter.java
##########
@@ -0,0 +1,68 @@
+/*
+ * 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 org.apache.kafka.raft.OffsetAndEpoch;
+import org.apache.kafka.common.message.SnapshotFooterRecord;
+
+import java.util.List;
+public interface FileSnapshotWriter<T> extends AutoCloseable {

Review comment:
       Let's _move_ the documentation in `class SnapshotWriter` to this interface.

##########
File path: raft/src/main/java/org/apache/kafka/snapshot/FileSnapshotWriter.java
##########
@@ -0,0 +1,68 @@
+/*
+ * 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 org.apache.kafka.raft.OffsetAndEpoch;
+import org.apache.kafka.common.message.SnapshotFooterRecord;
+
+import java.util.List;
+public interface FileSnapshotWriter<T> extends AutoCloseable {
+    /**
+     * Returns the end offset and epoch for the snapshot.
+     */
+    OffsetAndEpoch snapshotId();
+
+    /**
+     * Returns the last log offset which is represented in the snapshot.
+     */
+    long lastContainedLogOffset();
+
+    /**
+     * Returns the epoch of the last log offset which is represented in the snapshot.
+     */
+    int lastContainedLogEpoch();
+
+    /**
+     * Returns true if the snapshot has been frozen, otherwise false is returned.
+     * <p>
+     * Modification to the snapshot are not allowed once it is frozen.
+     */
+    boolean isFrozen();
+
+    /**
+     * Appends a list of values to the snapshot.
+     * <p>

Review comment:
       I think we can remove the `<p>` HTML tag. This occurs 3 times in this file.

##########
File path: raft/src/main/java/org/apache/kafka/snapshot/FileSnapshotReader.java
##########
@@ -0,0 +1,52 @@
+/*
+ * 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 org.apache.kafka.raft.OffsetAndEpoch;
+import java.util.Iterator;
+import org.apache.kafka.raft.Batch;

Review comment:
       Please fix the import order by sorting these lines.

##########
File path: raft/src/main/java/org/apache/kafka/snapshot/FileSnapshotWriter.java
##########
@@ -0,0 +1,68 @@
+/*
+ * 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 org.apache.kafka.raft.OffsetAndEpoch;
+import org.apache.kafka.common.message.SnapshotFooterRecord;
+
+import java.util.List;

Review comment:
       Please fix the import formatting. Need a space between the `package` line and the `import` lines. Need a space betwee the `import` lines and the `interface` line.
   
   Need to also short the import lines.

##########
File path: raft/src/main/java/org/apache/kafka/snapshot/SnapshotWriter.java
##########
@@ -74,6 +74,7 @@ private SnapshotWriter(
             compressionType,
             serde
         );
+        initializeSnapshotWithHeader();

Review comment:
       Ideally, we shouldn't change the semantic of this type in this PR. Why are we moving this here from the `static` method?

##########
File path: core/src/test/scala/unit/kafka/security/authorizer/AclAuthorizerTest.scala
##########
@@ -123,8 +123,14 @@ class AclAuthorizerTest extends QuorumTestHarness with BaseAuthorizerTest {
     val user1 = new KafkaPrincipal(KafkaPrincipal.USER_TYPE, username)
     val user2 = new KafkaPrincipal(KafkaPrincipal.USER_TYPE, "rob")
     val user3 = new KafkaPrincipal(KafkaPrincipal.USER_TYPE, "batman")
+    val user4 = new KafkaPrincipal(KafkaPrincipal.USER_TYPE, "segment")

Review comment:
       Are the changes to this file needed?

##########
File path: raft/src/main/java/org/apache/kafka/snapshot/FileSnapshotReader.java
##########
@@ -0,0 +1,52 @@
+/*
+ * 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 org.apache.kafka.raft.OffsetAndEpoch;
+import java.util.Iterator;
+import org.apache.kafka.raft.Batch;
+
+/**
+ * Interface of the snapshot reader
+ */

Review comment:
       Let's _move_ the documentation in `class SnapshotReader` to this interface.




-- 
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: jira-unsubscribe@kafka.apache.org

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