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/06/18 21:19:54 UTC

[GitHub] [kafka] niket-goel commented on a change in pull request #10899: KAFKA-12952 Adding Delimeters to Metadata Snapshot File

niket-goel commented on a change in pull request #10899:
URL: https://github.com/apache/kafka/pull/10899#discussion_r654552376



##########
File path: clients/src/main/resources/common/message/MetadataSnapshotHeaderRecord.json
##########
@@ -0,0 +1,25 @@
+// 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.
+
+{
+  "type": "data",
+  "name": "MetadataSnapshotHeaderRecord",
+  "validVersions": "0",
+  "flexibleVersions": "0+",
+  "fields": [
+    {"name": "Version", "type": "int16", "versions": "0+",
+      "about": "The version of the metadata snapshot file"}

Review comment:
       Yep. Added in the next commit.

##########
File path: clients/src/main/java/org/apache/kafka/common/record/ControlRecordType.java
##########
@@ -43,9 +43,13 @@
 public enum ControlRecordType {
     ABORT((short) 0),
     COMMIT((short) 1),
+
     // Raft quorum related control messages.
-    QUORUM_REASSIGNMENT((short) 2),
+    // TODO - ngoel
+    // Burn enum val 2 to prevent
+    // accidental corruption. (Consult with team)

Review comment:
       Makes sense. Made the change in the next revision

##########
File path: raft/src/main/java/org/apache/kafka/snapshot/SnapshotWriter.java
##########
@@ -78,6 +81,52 @@ public SnapshotWriter(
         );
     }
 
+    /**
+     * FIXME ngoel Improve this comment
+     * Instantiates a SnapshotWriter and stamps the underlying
+     * snapshot with a @MetadataSnapshotHeaderRecord.
+     *
+     * @return {@link Optional}{@link SnapshotWriter}
+     */
+    public static <T> Optional<SnapshotWriter<T>> create(
+            Supplier<Optional<RawSnapshotWriter>> supplier,
+            int maxBatchSize,
+            MemoryPool memoryPool,
+            Time snapshotTime,
+            CompressionType compressionType,
+            RecordSerde<T> serde
+            ){
+        Optional<SnapshotWriter<T>> writer = supplier.get().map(snapshot -> {
+            return new SnapshotWriter<T>(
+                    snapshot,
+                    maxBatchSize,
+                    memoryPool,
+                    snapshotTime,
+                    CompressionType.NONE,
+                    serde
+                    );
+        });
+        if (writer.isPresent()) {
+            //TODO ngoel Append Header
+            // Once the snapshot is intantiated assert that
+            // the snapshot file is 0 bytes and then append a
+            // header
+            SnapshotWriter<T> snapWriter = writer.get();
+            RawSnapshotWriter snapshot = snapWriter.snapshot;
+            if (snapshot.sizeInBytes() != 0){
+                throw new IllegalStateException("Initializing new snapshot with a non-empty file");
+            }
+            // Append the header control record.
+            // FIXME ngoel Where should we define the version?
+            short headerVersion = 0;
+            MetadataSnapshotHeaderRecord headerRecord = new MetadataSnapshotHeaderRecord().setVersion(headerVersion);
+            snapWriter.accumulator.appendSnapshotHeaderMessage(headerRecord);
+            snapWriter.accumulator.forceDrain();
+            snapWriter.close();

Review comment:
       Good catch. Fixed in next version.

##########
File path: raft/src/main/java/org/apache/kafka/snapshot/SnapshotWriter.java
##########
@@ -78,6 +81,52 @@ public SnapshotWriter(
         );
     }
 
+    /**
+     * FIXME ngoel Improve this comment
+     * Instantiates a SnapshotWriter and stamps the underlying
+     * snapshot with a @MetadataSnapshotHeaderRecord.
+     *
+     * @return {@link Optional}{@link SnapshotWriter}
+     */
+    public static <T> Optional<SnapshotWriter<T>> create(
+            Supplier<Optional<RawSnapshotWriter>> supplier,
+            int maxBatchSize,
+            MemoryPool memoryPool,
+            Time snapshotTime,
+            CompressionType compressionType,
+            RecordSerde<T> serde
+            ){
+        Optional<SnapshotWriter<T>> writer = supplier.get().map(snapshot -> {
+            return new SnapshotWriter<T>(
+                    snapshot,
+                    maxBatchSize,
+                    memoryPool,
+                    snapshotTime,
+                    CompressionType.NONE,
+                    serde
+                    );
+        });
+        if (writer.isPresent()) {
+            //TODO ngoel Append Header
+            // Once the snapshot is intantiated assert that
+            // the snapshot file is 0 bytes and then append a
+            // header
+            SnapshotWriter<T> snapWriter = writer.get();
+            RawSnapshotWriter snapshot = snapWriter.snapshot;
+            if (snapshot.sizeInBytes() != 0){
+                throw new IllegalStateException("Initializing new snapshot with a non-empty file");
+            }
+            // Append the header control record.
+            // FIXME ngoel Where should we define the version?
+            short headerVersion = 0;
+            MetadataSnapshotHeaderRecord headerRecord = new MetadataSnapshotHeaderRecord().setVersion(headerVersion);
+            snapWriter.accumulator.appendSnapshotHeaderMessage(headerRecord);
+            snapWriter.accumulator.forceDrain();

Review comment:
       Done

##########
File path: .gitignore
##########
@@ -56,3 +56,8 @@ jmh-benchmarks/src/main/generated
 raft/.jqwik-database
 **/src/generated
 **/src/generated-test
+
+.vim
+.bloop/
+.metals/
+bin/

Review comment:
       Yes. Pushed by mistake. Fixed in next version.




-- 
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:
users@infra.apache.org