cmccabe commented on a change in pull request #10899: URL: https://github.com/apache/kafka/pull/10899#discussion_r655616706
########## File path: clients/src/main/java/org/apache/kafka/common/record/MemoryRecords.java ########## @@ -664,4 +666,55 @@ private static void writeLeaderChangeMessage(ByteBuffer buffer, builder.close(); } + public static MemoryRecords withSnapshotHeaderRecord( + long initialOffset, + long timestamp, + int leaderEpoch, + ByteBuffer buffer, + MetadataSnapshotHeaderRecord snapshotHeaderRecord) { + writeSnapshotHeaderRecord(buffer, initialOffset, timestamp, leaderEpoch, snapshotHeaderRecord); + buffer.flip(); + return MemoryRecords.readableRecords(buffer); + } + + private static void writeSnapshotHeaderRecord(ByteBuffer buffer, + long initialOffset, + long timestamp, + int leaderEpoch, + MetadataSnapshotHeaderRecord snapshotHeaderRecord) { + MemoryRecordsBuilder builder = new MemoryRecordsBuilder( Review comment: Does this need to be wrapped in a try... catch block to avoid leaking something if we throw an exception in `appendSnapshotHeaderMessage` ? ########## File path: clients/src/main/java/org/apache/kafka/common/record/ControlRecordUtils.java ########## @@ -27,6 +29,8 @@ public class ControlRecordUtils { public static final short LEADER_CHANGE_SCHEMA_VERSION = new LeaderChangeMessage().highestSupportedVersion(); + public static final short METADATA_SNAPSHOT_HEADER_VERSION = new MetadataSnapshotHeaderRecord().highestSupportedVersion(); Review comment: Do we really need this constant? It seems confusing since it implies there is only one version ever, but there may well be more versions later on. If you mean highest supported, why not just say highest supported rather than referring to "the version"? ########## File path: clients/src/main/java/org/apache/kafka/common/record/ControlRecordUtils.java ########## @@ -27,6 +29,8 @@ public class ControlRecordUtils { public static final short LEADER_CHANGE_SCHEMA_VERSION = new LeaderChangeMessage().highestSupportedVersion(); + public static final short METADATA_SNAPSHOT_HEADER_VERSION = new MetadataSnapshotHeaderRecord().highestSupportedVersion(); + public static final short METADATA_SNAPSHOT_FOOTER_VERSION = new MetadataSnapshotFooterRecord().highestSupportedVersion(); Review comment: Same comment for this. ########## File path: clients/src/main/resources/common/message/MetadataSnapshotFooterRecord.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": "MetadataSnapshotFooterRecord", Review comment: This is generic to snapshots, rather than metadata snapshots, right? In other words, if we have another snapshotted topic, we'd want to use this record as well. So I don't think it should have "metadata" in the name ########## 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", Review comment: Same comment about naming here. -- 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