JingsongLi commented on a change in pull request #7944: [FLINK-11863][table-runtime-blink] Introduce channel to read and write compressed data URL: https://github.com/apache/flink/pull/7944#discussion_r263981370
########## File path: flink-table/flink-table-runtime-blink/src/main/java/org/apache/flink/table/runtime/io/CompressedBlockChannelReader.java ########## @@ -0,0 +1,222 @@ +/* + * 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.table.runtime.io; + +import org.apache.flink.core.memory.MemorySegment; +import org.apache.flink.core.memory.MemorySegmentFactory; +import org.apache.flink.runtime.io.disk.iomanager.BlockChannelReader; +import org.apache.flink.runtime.io.disk.iomanager.BufferFileReader; +import org.apache.flink.runtime.io.disk.iomanager.IOManager; +import org.apache.flink.runtime.io.disk.iomanager.RequestDoneCallback; +import org.apache.flink.runtime.io.network.buffer.Buffer; +import org.apache.flink.runtime.io.network.buffer.BufferRecycler; +import org.apache.flink.runtime.io.network.buffer.NetworkBuffer; +import org.apache.flink.table.runtime.compression.BlockCompressionFactory; +import org.apache.flink.table.runtime.compression.BlockCompressor; +import org.apache.flink.table.runtime.compression.BlockDecompressor; +import org.apache.flink.util.Preconditions; + +import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.channels.FileChannel; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicReference; + +/** + * Compressed block channel reader provides a scenario where MemorySegment must be maintained. + */ +public class CompressedBlockChannelReader implements BlockChannelReader<MemorySegment>, + RequestDoneCallback<Buffer>, + BufferRecycler { + + private final LinkedBlockingQueue<MemorySegment> blockQueue; + + private final boolean copyCompress; + private final BlockDecompressor decompressor; + private final BufferFileReader reader; + private final AtomicReference<IOException> cause; + + private final LinkedBlockingQueue<Buffer> retBuffers = new LinkedBlockingQueue<>(); + + private byte[] buf; + private ByteBuffer bufWrapper; + private int offset; + private int len; + + public CompressedBlockChannelReader( + IOManager ioManager, ID channel, + LinkedBlockingQueue<MemorySegment> blockQueue, + BlockCompressionFactory codecFactory, int preferBlockSize, int segmentSize) throws IOException { + this.reader = ioManager.createBufferFileReader(channel, this); + this.blockQueue = blockQueue; + copyCompress = preferBlockSize > segmentSize * 2; Review comment: You can add a comment to explain that in order to avoid multiple copies, only when preferBlockSize > segmentSize * 2 will new a buffer to compress. ---------------------------------------------------------------- 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: [email protected] With regards, Apache Git Services
