wsry commented on code in PR #20216: URL: https://github.com/apache/flink/pull/20216#discussion_r934105686
########## flink-runtime/src/main/java/org/apache/flink/runtime/io/compression/AirCompressor.java: ########## @@ -0,0 +1,117 @@ +/* + * 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.flink.runtime.io.compression; + +import io.airlift.compress.Compressor; + +import java.nio.BufferOverflowException; +import java.nio.ByteBuffer; +import java.nio.ByteOrder; + +import static org.apache.flink.runtime.io.compression.CompressorUtils.writeIntLE; +import static org.apache.flink.runtime.io.compression.Lz4BlockCompressionFactory.HEADER_LENGTH; + +/** Flink compressor that wrap {@link Compressor}. */ +public class AirCompressor implements BlockCompressor { + Compressor internalCompressor; + + public AirCompressor(Compressor internalCompressor) { + this.internalCompressor = internalCompressor; + } + + @Override + public int getMaxCompressedSize(int srcSize) { + return AirCompressorFactory.HEADER_LENGTH + internalCompressor.maxCompressedLength(srcSize); + } + + @Override + public int compress(ByteBuffer src, int srcOff, int srcLen, ByteBuffer dst, int dstOff) + throws InsufficientBufferException { + try { + final int prevSrcOff = src.position() + srcOff; + final int prevDstOff = dst.position() + dstOff; + + src.position(prevSrcOff); + dst.position(prevDstOff + HEADER_LENGTH); + + internalCompressor.compress(src, dst); + + int compressedLength = dst.position() - prevDstOff - HEADER_LENGTH; + + dst.position(prevDstOff); + dst.order(ByteOrder.LITTLE_ENDIAN); + dst.putInt(compressedLength); + dst.putInt(srcLen); + dst.position(prevDstOff + compressedLength + HEADER_LENGTH); + + return HEADER_LENGTH + compressedLength; + } catch (IllegalArgumentException + | ArrayIndexOutOfBoundsException + | BufferOverflowException e) { + if (e instanceof IllegalArgumentException + && !isInsufficientBuffer((IllegalArgumentException) e)) { + throw e; + } + throw new InsufficientBufferException(e); Review Comment: I mean the second one. IMO, the BufferCompressionException and BufferDecompressionException can cover the InsufficientBufferException, it just means that exception was thrown when compressing and decompressing data. I think a coarse grained exception type is enough here because the ```caused by``` will give the root cause. Maybe a fine grained exception type is better. But we must figure the InsufficientBufferException out, which can be inaccurate and an inaccurate exception type causes confusion. -- 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: issues-unsubscr...@flink.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org