You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2022/04/11 06:44:58 UTC

[GitHub] [flink] KarmaGYZ commented on a diff in pull request #19380: [FLINK-25055][runtime] Support listen and notify mechanism for partition request

KarmaGYZ commented on code in PR #19380:
URL: https://github.com/apache/flink/pull/19380#discussion_r846987716


##########
flink-runtime/src/main/java/org/apache/flink/runtime/io/network/partition/ResultPartitionManager.java:
##########
@@ -104,12 +192,40 @@ public void shutdown() {
 
             registeredPartitions.clear();
 
+            requestPartitionNotifiers.clear();
+
             isShutdown = true;
 
             LOG.debug("Successful shutdown.");
         }
     }
 
+    /**
+     * Check whether the partition notifier is timeout.
+     */
+    private void checkRequestPartitionNotifiers() {
+        List<PartitionRequestNotifier> timeoutPartitionRequestNotifiers = new LinkedList<>();
+        synchronized (registeredPartitions) {
+            if (isShutdown) {
+                return;
+            }
+            long now = System.currentTimeMillis();
+            Iterator<Map.Entry<ResultPartitionID, InputRequestNotifierManager>> iterator = requestPartitionNotifiers.entrySet().iterator();
+            while (iterator.hasNext()) {
+                Map.Entry<ResultPartitionID, InputRequestNotifierManager> entry = iterator.next();
+                InputRequestNotifierManager partitionRequestNotifiers = entry.getValue();
+                partitionRequestNotifiers.removeExpiration(now, partitionNotifierTimeout.toMillis(), timeoutPartitionRequestNotifiers);
+                if (partitionRequestNotifiers.isEmpty()) {
+                    iterator.remove();
+                }
+            }
+        }
+        for (PartitionRequestNotifier partitionRequestNotifier : timeoutPartitionRequestNotifiers) {
+            partitionRequestNotifier.notifyPartitionRequestTimeout();
+        }
+        partitionNotifierTimeoutChecker.schedule(this::checkRequestPartitionNotifiers, partitionNotifierTimeout.toMillis(), TimeUnit.MILLISECONDS);

Review Comment:
   `partitionNotifierTimeoutChecker` has not been closed anywhere.



##########
flink-runtime/src/main/java/org/apache/flink/runtime/io/network/netty/PartitionRequestQueue.java:
##########
@@ -243,6 +246,22 @@ public void userEventTriggered(ChannelHandlerContext ctx, Object msg) throws Exc
             if (toRelease != null) {
                 releaseViewReader(toRelease);
             }
+        } else if (msg.getClass() == PartitionRequestNotifierTimeout.class) {
+            PartitionRequestNotifierTimeout partitionRequestNotifierTimeout = (PartitionRequestNotifierTimeout) msg;
+
+            // Send partition not found message to the downstream task when the notifier is timeout.
+            final PartitionRequestNotifier partitionRequestNotifier = partitionRequestNotifierTimeout
+                    .getPartitionRequestNotifier();
+            final ResultPartitionID resultPartitionId = partitionRequestNotifier.getResultPartitionId();
+            final InputChannelID inputChannelId = partitionRequestNotifier.getReceiverId();
+            availableReaders.remove(partitionRequestNotifier.getViewReader());
+            allReaders.remove(inputChannelId);

Review Comment:
   Not familiar with this mechanism. Could you explain why we need to do the removal?



##########
flink-runtime/src/main/java/org/apache/flink/runtime/io/network/partition/ResultPartitionManager.java:
##########
@@ -104,12 +192,40 @@ public void shutdown() {
 
             registeredPartitions.clear();
 
+            requestPartitionNotifiers.clear();

Review Comment:
   Should we send `PartitionNotFoundException` to downstream?



##########
flink-runtime/src/main/java/org/apache/flink/runtime/io/network/NetworkSequenceViewReader.java:
##########
@@ -40,6 +45,30 @@ void requestSubpartitionView(
             int subPartitionIndex)
             throws IOException;
 
+    /**
+     * The {@link PartitionRequestNotifier} notify and process the downstream task's partition request.
+     *
+     * @param partition the result partition
+     * @param subPartitionIndex the sub partition index
+     * @throws IOException the thrown exception
+     */
+    void requestSubpartitionView(ResultPartition partition, int subPartitionIndex) throws IOException;

Review Comment:
   I think those origin methods should be renamed and reimplemented, same as others.



##########
flink-runtime/src/main/java/org/apache/flink/runtime/io/network/partition/ResultPartitionManager.java:
##########
@@ -79,8 +128,47 @@ public ResultSubpartitionView createSubpartitionView(
         return subpartitionView;
     }
 
+    @Override
+    public ResultSubpartitionView createSubpartitionViewOrNotify(
+            ResultPartitionID partitionId,
+            int subpartitionIndex,
+            BufferAvailabilityListener availabilityListener,
+            PartitionRequestNotifier notifier) throws IOException {
+
+        final ResultSubpartitionView subpartitionView;
+        synchronized (registeredPartitions) {
+            final ResultPartition partition = registeredPartitions.get(partitionId);
+
+            if (partition == null) {
+                requestPartitionNotifiers.computeIfAbsent(partitionId, key -> new InputRequestNotifierManager()).addNotifier(notifier);
+                return null;
+            }
+
+            LOG.debug("Requesting subpartition {} of {}.", subpartitionIndex, partition);
+
+            subpartitionView =
+                    partition.createSubpartitionView(subpartitionIndex, availabilityListener);
+        }
+
+        return subpartitionView;
+    }
+
+    @Override
+    public void releasePartitionRequestNotifier(NettyPartitionRequestNotifier notifier) {

Review Comment:
   What is the previous behavior when the `ViewReader` was released? Should we send an error to the downstream here?



##########
flink-runtime/src/main/java/org/apache/flink/runtime/io/network/netty/PartitionRequestNotifierTimeout.java:
##########
@@ -0,0 +1,36 @@
+/*
+ * 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.netty;
+
+import org.apache.flink.runtime.io.network.partition.PartitionRequestNotifier;
+
+/**
+ * Timeout message of given {@link PartitionRequestNotifier}.
+ */
+public class PartitionRequestNotifierTimeout {

Review Comment:
   Why do we need this class? It seems just contains a `PartitionRequestNotifier`. An interface might be good enough?
   
   BTW, I think we should also reconsider the structure and scope of `PartitionRequestNotifier`.



-- 
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-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org