xx789633 commented on code in PR #1441: URL: https://github.com/apache/fluss/pull/1441#discussion_r2281407749
########## fluss-lake/fluss-lake-lance/src/main/java/com/alibaba/fluss/lake/lance/tiering/LanceCommittableSerializer.java: ########## @@ -0,0 +1,67 @@ +/* + * 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 com.alibaba.fluss.lake.lance.tiering; + +import com.alibaba.fluss.lake.serializer.SimpleVersionedSerializer; + +import com.lancedb.lance.FragmentMetadata; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.util.List; + +/** The serializer of {@link LanceCommittable}. */ +public class LanceCommittableSerializer implements SimpleVersionedSerializer<LanceCommittable> { + private static final int CURRENT_VERSION = 1; + + @Override + public int getVersion() { + return CURRENT_VERSION; + } + + @Override + public byte[] serialize(LanceCommittable lanceCommittable) throws IOException { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + ObjectOutputStream oos = new ObjectOutputStream(baos); + oos.writeObject(lanceCommittable.committable()); + oos.close(); + return baos.toByteArray(); + } + + @Override + public LanceCommittable deserialize(int version, byte[] serialized) throws IOException { + if (version != CURRENT_VERSION) { + throw new UnsupportedOperationException( + "Expecting LanceCommittable version to be " + + CURRENT_VERSION + + ", but found " + + version + + "."); + } + ByteArrayInputStream bais = new ByteArrayInputStream(serialized); + ObjectInputStream ois = new ObjectInputStream(bais); + try { + return new LanceCommittable((List<FragmentMetadata>) ois.readObject()); + } catch (ClassNotFoundException e) { + throw new RuntimeException(e); + } Review Comment: The `ClassNotFoundException` will be thrown if the class of the serialized object read by `ObjectInputStream.readObject()` cannot be found. Actually this is a typical exception thrown by `readObject`: https://docs.oracle.com/javase/8/docs/api/java/io/ObjectInputStream.html#readObject--. An example code: https://github.com/apache/flink/blob/master/flink-state-backends/flink-statebackend-changelog/src/main/java/org/apache/flink/state/changelog/restore/ChangelogBackendLogApplier.java#L135 -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
