rkhachatryan commented on a change in pull request #10151: [FLINK-14231] Handle 
the pending processing-time timers to make endInput semantics on the operator 
chain strict
URL: https://github.com/apache/flink/pull/10151#discussion_r362469562
 
 

 ##########
 File path: 
flink-streaming-java/src/main/java/org/apache/flink/streaming/runtime/tasks/StreamOperatorWrapper.java
 ##########
 @@ -0,0 +1,230 @@
+/*
+ * 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.streaming.runtime.tasks;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.annotation.VisibleForTesting;
+import org.apache.flink.streaming.api.operators.BoundedMultiInput;
+import org.apache.flink.streaming.api.operators.BoundedOneInput;
+import org.apache.flink.streaming.api.operators.MailboxExecutor;
+import org.apache.flink.streaming.api.operators.StreamOperator;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.CompletionException;
+import java.util.concurrent.ExecutionException;
+
+import static org.apache.flink.util.Preconditions.checkNotNull;
+import static org.apache.flink.util.Preconditions.checkState;
+
+/**
+ * This class handles the close, endInput and other related logic of a {@link 
StreamOperator}. It also
+ * supports automatically transmitting the close operation to all operators on 
the operator chain behind
+ * it in the topological order.
+ *
+ * <p>After closing the operator, it quiesces its processing time service to 
prevent the pending timers
+ * from firing, but allow the timers in running to finish.
+ */
+@Internal
+public class StreamOperatorWrapper<OUT, OP extends StreamOperator<OUT>> {
+
+       /**
+        * For iteration, the head operator of the task ({@link 
StreamIterationHead}) executing the
+        * feedback edges is null and therefore the {@code wrapped} is nullable.
+        */
+       @Nullable
+       private final OP wrapped;
+
+       private final MailboxExecutor mailboxExecutor;
+
+       private StreamOperatorWrapper<?, ?> previous;
+
+       private StreamOperatorWrapper<?, ?> next;
+
+       StreamOperatorWrapper(OP wrapped, MailboxExecutor mailboxExecutor) {
+               this.wrapped = wrapped;
+               this.mailboxExecutor = checkNotNull(mailboxExecutor);
+       }
+
+       public void close(StreamTask<?, ?> containingTask, boolean transitive) 
throws Exception {
+               close(containingTask, transitive, false);
+       }
+
+       /**
+        * Ends an input of the operator contained by this wrapper.
+        *
+        * @param inputId the input ID starts from 1 which indicates the first 
input.
+        */
+       public void endOperatorInput(int inputId) throws Exception {
+               if (wrapped instanceof BoundedOneInput) {
+                       ((BoundedOneInput) wrapped).endInput();
+               } else if (wrapped instanceof BoundedMultiInput) {
+                       ((BoundedMultiInput) wrapped).endInput(inputId);
+               }
+       }
+
+       public OP getStreamOperator() {
+               return wrapped;
+       }
+
+       void setPrevious(StreamOperatorWrapper previous) {
+               this.previous = previous;
+       }
+
+       void setNext(StreamOperatorWrapper next) {
+               this.next = next;
+       }
+
+       @VisibleForTesting
+       void close(StreamTask<?, ?> containingTask, boolean transitive, boolean 
invokingEndInput) throws Exception {
 
 Review comment:
   The `transitive` argument is always `true`, except for 
`testCloseWithoutTransitivity`.
   So it looks like we don't need the test and the argument.

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