WencongLiu commented on code in PR #24398:
URL: https://github.com/apache/flink/pull/24398#discussion_r1520975025


##########
flink-streaming-java/src/main/java/org/apache/flink/streaming/api/operators/MapPartitionIterator.java:
##########
@@ -0,0 +1,215 @@
+/*
+ * 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.api.operators;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.api.common.functions.MapPartitionFunction;
+import org.apache.flink.util.ExceptionUtils;
+import org.apache.flink.util.concurrent.ExecutorThreadFactory;
+
+import javax.annotation.concurrent.GuardedBy;
+
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.Queue;
+import java.util.concurrent.Executor;
+import java.util.concurrent.Executors;
+import java.util.concurrent.locks.Condition;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
+import java.util.function.Consumer;
+import java.util.function.Supplier;
+
+import static org.apache.flink.util.Preconditions.checkState;
+
+/**
+ * The {@link MapPartitionIterator} is an iterator used in the {@link 
MapPartitionOperator}.The task
+ * main thread will add records to it. It will set itself as the input 
parameter of {@link
+ * MapPartitionFunction} and execute the function.
+ */
+@Internal
+public class MapPartitionIterator<IN> implements Iterator<IN> {
+
+    /**
+     * Max number of caches.
+     *
+     * <p>The constant defines the maximum number of caches that can be 
created. Its value is set to
+     * 100, which is considered sufficient for most parallel jobs. Each cache 
is a record and
+     * occupies a minimal amount of memory so the value is not excessively 
large.
+     */
+    private static final int DEFAULT_MAX_CACHE_NUM = 100;
+
+    /** The lock to ensure consistency between task main thread and udf 
executor. */
+    private final Lock lock = new ReentrantLock();
+
+    /** The queue to store record caches. */
+    @GuardedBy("lock")
+    private final Queue<IN> cacheQueue = new LinkedList<>();
+
+    /** The condition to indicate the cache queue is not empty. */
+    private final Condition cacheNotEmpty = lock.newCondition();
+
+    /** The condition to indicate the cache queue is not full. */
+    private final Condition cacheNotFull = lock.newCondition();
+
+    /** The condition to indicate the udf is finished. */
+    private final Condition udfFinish = lock.newCondition();
+
+    /** The task udf executor. */
+    private final Executor udfExecutor =

Review Comment:
   I overlooked this point. I have now ensured that the executor can be shut 
down correctly. 😢



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

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

Reply via email to