jsancio commented on a change in pull request #10899: URL: https://github.com/apache/kafka/pull/10899#discussion_r654014807
########## 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: Lets add this version field to the `LeaderChangeMessage` schema JSON also. ########## 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: Closing the writer here will abort the snapshot since we are not done and we didn't call. ########## 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: The change proposed in this PR already a backward incompatible change. I think we agreed to make `LEADER_CHANGE(2)` and `SNAPSHOT_HEADER(3)`. ########## 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: I would move all of this functionality as a private instance method of `SnapshotWriter`. ########## 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: I would remove these gitignore patterns from the project. Git allows you to have personal gitignore patterns. -- 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