TanYuxin-tyx commented on code in PR #22804:
URL: https://github.com/apache/flink/pull/22804#discussion_r1233854834


##########
flink-runtime/src/main/java/org/apache/flink/runtime/io/network/partition/hybrid/tiered/storage/file/ProducerMergePartitionFileWriter.java:
##########
@@ -0,0 +1,182 @@
+/*
+ * 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.network.partition.hybrid.tiered.storage.file;
+
+import org.apache.flink.runtime.io.network.buffer.Buffer;
+import org.apache.flink.runtime.io.network.partition.BufferReaderWriterUtil;
+import 
org.apache.flink.runtime.io.network.partition.hybrid.tiered.netty.NettyPayload;
+import org.apache.flink.util.ExceptionUtils;
+import org.apache.flink.util.FatalExitExceptionHandler;
+
+import 
org.apache.flink.shaded.guava30.com.google.common.util.concurrent.ThreadFactoryBuilder;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.channels.FileChannel;
+import java.nio.file.Path;
+import java.nio.file.StandardOpenOption;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Optional;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import static 
org.apache.flink.runtime.io.network.partition.hybrid.tiered.common.TieredStorageUtils.generateBufferWithHeaders;
+import static org.apache.flink.util.Preconditions.checkState;
+
+/** THe implementation of {@link PartitionFileWriter} with merged logic. */
+public class ProducerMergePartitionFileWriter implements PartitionFileWriter {
+
+    private static final Logger LOG =
+            LoggerFactory.getLogger(ProducerMergePartitionFileWriter.class);
+
+    /** One thread to perform spill operation. */
+    private final ExecutorService ioExecutor =
+            Executors.newSingleThreadExecutor(
+                    new ThreadFactoryBuilder()
+                            .setNameFormat("ProducerMergePartitionFileWriter 
Spiller")
+                            
.setUncaughtExceptionHandler(FatalExitExceptionHandler.INSTANCE)
+                            .build());
+
+    /** File channel to write data. */
+    private final FileChannel dataFileChannel;
+
+    /** Records the current writing location. */
+    private long totalBytesWritten;
+
+    private final PartitionFileIndex partitionFileIndex;
+
+    public ProducerMergePartitionFileWriter(
+            Path dataFilePath, PartitionFileIndex partitionFileIndex) {
+        LOG.info("Creating partition file " + dataFilePath);
+        try {
+            this.dataFileChannel =
+                    FileChannel.open(
+                            dataFilePath, StandardOpenOption.CREATE_NEW, 
StandardOpenOption.WRITE);
+        } catch (IOException e) {
+            throw new RuntimeException("Failed to create file channel.", e);
+        }
+        this.partitionFileIndex = partitionFileIndex;
+    }
+
+    @Override
+    public CompletableFuture<Void> write(List<SubpartitionNettyPayload> 
toWriteBuffers) {
+        List<NettyPayload> buffersToSpill =
+                toWriteBuffers.stream()
+                        .map(SubpartitionNettyPayload::getSegmentNettyPayloads)
+                        .flatMap(
+                                (Function<List<SegmentNettyPayload>, 
Stream<SegmentNettyPayload>>)
+                                        Collection::stream)
+                        .map(SegmentNettyPayload::getNettyPayloads)
+                        .flatMap(
+                                (Function<List<NettyPayload>, 
Stream<NettyPayload>>)
+                                        Collection::stream)
+                        .collect(Collectors.toList());

Review Comment:
   Because the subpartition id and segment id are used in the hash mode 
partition file. While the producer merge mode does not need that.



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

Reply via email to