zhijiangW commented on a change in pull request #8880: [FLINK-12986] [network] 
Fix instability of BoundedBlockingSubpartition under memory pressure.
URL: https://github.com/apache/flink/pull/8880#discussion_r298030365
 
 

 ##########
 File path: 
flink-runtime/src/main/java/org/apache/flink/runtime/io/network/partition/FileChannelMemoryMappedBoundedData.java
 ##########
 @@ -0,0 +1,190 @@
+/*
+ * 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;
+
+import org.apache.flink.runtime.io.network.buffer.Buffer;
+import org.apache.flink.util.IOUtils;
+
+import org.apache.flink.shaded.netty4.io.netty.util.internal.PlatformDependent;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.nio.channels.FileChannel;
+import java.nio.channels.FileChannel.MapMode;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.StandardOpenOption;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Collectors;
+
+import static org.apache.flink.util.Preconditions.checkState;
+
+final class FileChannelMemoryMappedBoundedData implements BoundedData {
+
+       /** The file channel backing the memory mapped file. */
+       private final FileChannel fileChannel;
+
+       /** The reusable array with header buffer and data buffer, to use 
gathering writes on the
+        * file channel ({@link 
java.nio.channels.GatheringByteChannel#write(ByteBuffer[])}). */
+       private final ByteBuffer[] headerAndBufferArray;
+
+       /** All memory mapped regions. */
+       private final ArrayList<ByteBuffer> memoryMappedRegions;
+
+       /** The path of the memory mapped file. */
+       private final Path filePath;
+
+       /** The position in the file channel. Cached for efficiency, because an 
actual position
+        * lookup in the channel involves various locks and checks. */
+       private long pos;
+
+       /** The position where the current memory mapped region must end. */
+       private long endOfCurrentRegion;
+
+       /** The position where the current memory mapped started. */
+       private long startOfCurrentRegion;
+
+       /** The maximum size of each mapped region. */
+       private final long maxRegionSize;
+
+       FileChannelMemoryMappedBoundedData(
+                       Path filePath,
+                       FileChannel fileChannel,
+                       int maxSizePerMappedRegion) throws IOException {
 
 Review comment:
   nit: `IOException` would never be thrown atm

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to