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_r263981423
 
 

 ##########
 File path: 
flink-table/flink-table-runtime-blink/src/main/java/org/apache/flink/table/runtime/io/CompressedBlockChannelWriter.java
 ##########
 @@ -0,0 +1,188 @@
+/*
+ * 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.BlockChannelWriter;
+import org.apache.flink.runtime.io.disk.iomanager.BufferFileWriter;
+import org.apache.flink.runtime.io.disk.iomanager.IOManager;
+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.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;
+
+/**
+ * Compressed block channel writer provides a scenario where MemorySegment 
must be maintained.
+ */
+public class CompressedBlockChannelWriter implements 
BlockChannelWriter<MemorySegment>,
+               BufferRecycler {
+
+       private final LinkedBlockingQueue<MemorySegment> blockQueue;
+       private final LinkedBlockingQueue<MemorySegment> compressedBuffers = 
new LinkedBlockingQueue<>();
+
+       private final BufferFileWriter writer;
+       private final boolean copyCompress;
+       private final BlockCompressor compressor;
+
+       private byte[] buf;
+       private ByteBuffer bufWrapper;
+       private int count;
+
+       public CompressedBlockChannelWriter(
+                       IOManager ioManager, ID channel,
+                       LinkedBlockingQueue<MemorySegment> blockQueue,
+                       BlockCompressionFactory codecFactory, int 
preferBlockSize, int segmentSize) throws IOException {
+               this.writer = ioManager.createBufferFileWriter(channel);
+               this.blockQueue = blockQueue;
+               copyCompress = preferBlockSize > segmentSize * 2;
 
 Review comment:
   same to BlockReader

----------------------------------------------------------------
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

Reply via email to