gharris1727 commented on code in PR #15620: URL: https://github.com/apache/kafka/pull/15620#discussion_r1573729186
########## storage/src/main/java/org/apache/kafka/server/log/remote/metadata/storage/serialization/RemoteLogMetadataSerde.java: ########## @@ -74,25 +72,24 @@ protected final Map<Short, RemoteLogMetadataTransform> createRemoteLogMetadataTr return map; } - protected final Map<String, Short> createRemoteLogStorageClassToApiKeyMap() { - Map<String, Short> map = new HashMap<>(); - map.put(RemoteLogSegmentMetadata.class.getName(), REMOTE_LOG_SEGMENT_METADATA_API_KEY); - map.put(RemoteLogSegmentMetadataUpdate.class.getName(), REMOTE_LOG_SEGMENT_METADATA_UPDATE_API_KEY); - map.put(RemotePartitionDeleteMetadata.class.getName(), REMOTE_PARTITION_DELETE_API_KEY); - map.put(RemoteLogSegmentMetadataSnapshot.class.getName(), REMOTE_LOG_SEGMENT_METADATA_SNAPSHOT_API_KEY); - return map; - } - public byte[] serialize(RemoteLogMetadata remoteLogMetadata) { - Short apiKey = remoteLogStorageClassToApiKey.get(remoteLogMetadata.getClass().getName()); - if (apiKey == null) { - throw new IllegalArgumentException("ApiKey for given RemoteStorageMetadata class: " + remoteLogMetadata.getClass() - + " does not exist."); - } - @SuppressWarnings("unchecked") - ApiMessageAndVersion apiMessageAndVersion = remoteLogMetadataTransform(apiKey).toApiMessageAndVersion(remoteLogMetadata); + RemoteLogMetadataTransform metadataTransform; + + if(remoteLogMetadata.getClass() == RemoteLogSegmentMetadata.class) { Review Comment: I don't think it makes a correctness difference since this is a flat hierarchy and there aren't any subclasses of each of the serialized types. There might be a slight performance difference, but not significant when the code is overall unoptimized, and we can't know without measuring it. I would have reached for instance of because it is more null safe, but if there's an explicit null guard somewhere else then there is again no difference in correctness, just style. -- 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-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org