junrao commented on a change in pull request #10271: URL: https://github.com/apache/kafka/pull/10271#discussion_r614993697
########## File path: storage/src/main/java/org/apache/kafka/server/log/remote/metadata/storage/serialization/RemoteLogMetadataSerdes.java ########## @@ -0,0 +1,56 @@ +/* + * 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.server.log.remote.metadata.storage.serialization; + +import org.apache.kafka.common.protocol.Message; + +import java.nio.ByteBuffer; + +/** + * The default implementation of {@link org.apache.kafka.server.log.remote.storage.RemoteLogMetadataManager} stores all + * the remote log metadata in an internal topic. Those messages can be {@link org.apache.kafka.server.log.remote.storage.RemoteLogSegmentMetadata}, + * {@link org.apache.kafka.server.log.remote.storage.RemoteLogSegmentMetadataUpdate}, or {@link org.apache.kafka.server.log.remote.storage.RemotePartitionDeleteMetadata}. + * These messages are written in Kafka's protocol message format as mentioned in + * <a href="https://cwiki.apache.org/confluence/display/KAFKA/KIP-405%3A+Kafka+Tiered+Storage#KIP405:KafkaTieredStorage-MessageFormat">KIP-405</a> + * <p> + * This interface is about serializing and deserializing these messages that are stored in remote log metadata internal + * topic. There are respective implementations for the mentioned message types. + * <p> + * @param <T> metadata type to be serialized/deserialized. + * + * @see RemoteLogSegmentMetadataSerdes + * @see RemoteLogSegmentMetadataUpdateSerdes + * @see RemotePartitionDeleteMetadataSerdes + */ +public interface RemoteLogMetadataSerdes<T> { + + /** + * Returns the message serialized for the given {@code metadata} object. + * + * @param metadata object to be serialized. + */ + Message serialize(T metadata); Review comment: This is a bit weird since normally serialize() returns a ByteBuffer to be consistent with deserialize. ########## File path: storage/src/main/java/org/apache/kafka/server/log/remote/metadata/storage/RemoteLogMetadataContext.java ########## @@ -0,0 +1,83 @@ +/* + * 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.server.log.remote.metadata.storage; + +import java.util.Objects; + +/** + * The context associated with the record in remote log metadata topic. This contains api-key, version and the + * payload object. + * <br> + * <p> + * For example: + * Remote log segment metadata record will have + * <pre> + * <ul> + * <li>api key as: {@link org.apache.kafka.server.log.remote.metadata.storage.generated.RemoteLogSegmentMetadataRecord#apiKey()}* </li> + * <li>version as: 0 (or respective version) , and </li> + * <li>payload as: {@link org.apache.kafka.server.log.remote.storage.RemoteLogSegmentMetadata}</li> + * </ul> + * </pre> + * <p> + * + * You can read more details in <a href="https://cwiki.apache.org/confluence/display/KAFKA/KIP-405%3A+Kafka+Tiered+Storage#KIP405:KafkaTieredStorage-MessageFormat">KIP-405</a> + */ +public class RemoteLogMetadataContext { Review comment: This class is very similar to ApiMessageAndVersion. Both the metadata and the storage module need to serialize/deserialize ApiMessage. Instead of creating different variants, I am wondering if it would be better to put the common code in a new server-side module or the client module under the server package that can be shared. ########## File path: storage/src/main/java/org/apache/kafka/server/log/remote/metadata/storage/serialization/RemoteLogMetadataContextSerdes.java ########## @@ -0,0 +1,116 @@ +/* + * 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.server.log.remote.metadata.storage.serialization; + +import org.apache.kafka.server.log.remote.metadata.storage.RemoteLogMetadataContext; +import org.apache.kafka.common.protocol.ByteBufferAccessor; +import org.apache.kafka.common.protocol.Message; +import org.apache.kafka.common.protocol.ObjectSerializationCache; +import org.apache.kafka.common.serialization.Deserializer; +import org.apache.kafka.common.serialization.Serde; +import org.apache.kafka.common.serialization.Serializer; +import org.apache.kafka.server.log.remote.metadata.storage.generated.RemoteLogSegmentMetadataRecord; +import org.apache.kafka.server.log.remote.metadata.storage.generated.RemoteLogSegmentMetadataUpdateRecord; +import org.apache.kafka.server.log.remote.metadata.storage.generated.RemotePartitionDeleteMetadataRecord; + +import java.nio.ByteBuffer; +import java.util.HashMap; +import java.util.Map; + +/** + * This class provides serialization and deserialization for {@link RemoteLogMetadataContext}. This is the root serdes + * for the messages that are stored in internal remote log metadata topic. + */ +public class RemoteLogMetadataContextSerdes implements Serde<RemoteLogMetadataContext> { + + public static final byte REMOTE_LOG_SEGMENT_METADATA_API_KEY = (byte) new RemoteLogSegmentMetadataRecord().apiKey(); + public static final byte REMOTE_LOG_SEGMENT_METADATA_UPDATE_API_KEY = (byte) new RemoteLogSegmentMetadataUpdateRecord().apiKey(); + public static final byte REMOTE_PARTITION_DELETE_API_KEY = (byte) new RemotePartitionDeleteMetadataRecord().apiKey(); + + private final Map<Byte, RemoteLogMetadataSerdes> keyToSerdes; Review comment: It seems that keyToSerdes can just be a static val? -- 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