loserwang1024 commented on code in PR #2647: URL: https://github.com/apache/fluss/pull/2647#discussion_r2851942445
########## fluss-common/src/main/java/org/apache/fluss/shaded/arrow/org/apache/arrow/vector/VectorLoader.java: ########## @@ -0,0 +1,155 @@ +/* + * 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.fluss.shaded.arrow.org.apache.arrow.vector; + +import org.apache.fluss.shaded.arrow.org.apache.arrow.memory.ArrowBuf; +import org.apache.fluss.shaded.arrow.org.apache.arrow.util.Collections2; +import org.apache.fluss.shaded.arrow.org.apache.arrow.util.Preconditions; +import org.apache.fluss.shaded.arrow.org.apache.arrow.vector.compression.CompressionCodec; +import org.apache.fluss.shaded.arrow.org.apache.arrow.vector.compression.CompressionUtil; +import org.apache.fluss.shaded.arrow.org.apache.arrow.vector.compression.CompressionUtil.CodecType; +import org.apache.fluss.shaded.arrow.org.apache.arrow.vector.compression.NoCompressionCodec; +import org.apache.fluss.shaded.arrow.org.apache.arrow.vector.compression.NoCompressionCodec.Factory; +import org.apache.fluss.shaded.arrow.org.apache.arrow.vector.ipc.message.ArrowFieldNode; +import org.apache.fluss.shaded.arrow.org.apache.arrow.vector.ipc.message.ArrowRecordBatch; +import org.apache.fluss.shaded.arrow.org.apache.arrow.vector.types.pojo.Field; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +/** + * A patched version of Arrow's {@code VectorLoader} that ensures decompressed buffers are properly + * released when an error (e.g. OOM) occurs during {@link #load(ArrowRecordBatch)}. + * + * <p>In the original Arrow implementation, the decompression loop runs <b>outside</b> the + * try-finally block that guards {@code loadFieldBuffers}. This means if decompression succeeds for + * the first N buffers of a field but fails on the (N+1)-th buffer, the already-decompressed buffers + * in {@code ownBuffers} are never closed, leaking Direct Memory. + * + * <p>This workaround moves the decompression loop <b>inside</b> the try block so that the finally + * clause always closes every buffer in {@code ownBuffers}, regardless of whether the load succeeds + * or fails: + * + * <ul> + * <li><b>Success path:</b> {@code loadFieldBuffers} retains each buffer (ref count +1), then the + * finally close decrements it back (ref count -1). The field vector still holds the buffer. + * <li><b>Error path:</b> The finally close decrements each already-decompressed buffer's ref + * count to 0, immediately freeing the Direct Memory. + * </ul> + * + * @see <a href="https://github.com/apache/fluss/issues/2646">FLUSS-2646</a> + */ +public class VectorLoader { Review Comment: done it -- 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]
