JingGe commented on a change in pull request #18428:
URL: https://github.com/apache/flink/pull/18428#discussion_r791937510



##########
File path: 
flink-streaming-java/src/main/java/org/apache/flink/streaming/runtime/operators/sink/committables/SubtaskCommittables.java
##########
@@ -0,0 +1,168 @@
+/*
+ * 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.operators.sink.committables;
+
+import org.apache.flink.streaming.api.connector.sink2.CommittableSummary;
+import org.apache.flink.streaming.api.connector.sink2.CommittableWithLineage;
+
+import java.util.ArrayDeque;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Deque;
+import java.util.Iterator;
+import java.util.List;
+import java.util.OptionalLong;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import static org.apache.flink.util.Preconditions.checkArgument;
+import static org.apache.flink.util.Preconditions.checkNotNull;
+
+class SubtaskCommittables<CommT> {
+    private CommittableSummary<CommT> summary;
+    private final Deque<CommitRequestImpl<CommT>> requests;
+    private int numDrained;
+    private int numFailed;
+
+    SubtaskCommittables(CommittableSummary<CommT> summary) {
+        this(summary, Collections.emptyList(), 0, 0);
+    }
+
+    SubtaskCommittables(
+            CommittableSummary<CommT> summary,
+            Collection<CommitRequestImpl<CommT>> requests,
+            int numDrained,
+            int numFailed) {
+        this.summary = checkNotNull(summary);
+        this.requests = new ArrayDeque<>(checkNotNull(requests));
+        this.numDrained = numDrained;
+        this.numFailed = numFailed;
+    }
+
+    void add(CommittableWithLineage<CommT> committable) {
+        add(committable.getCommittable());
+    }
+
+    void add(CommT committable) {
+        requests.add(new CommitRequestImpl<>(committable));
+    }
+
+    boolean hasReceivedAll() {
+        return getNumCommittables() == summary.getNumberOfCommittables();
+    }
+
+    int getNumCommittables() {
+        return requests.size() + numDrained + numFailed;
+    }
+
+    int getNumPending() {
+        return summary.getNumberOfCommittables() - (numDrained + numFailed);
+    }
+
+    int getNumFailed() {
+        return numFailed;
+    }
+
+    boolean isFinished() {
+        return getNumPending() == 0;
+    }
+
+    Stream<CommitRequestImpl<CommT>> getPendingRequests() {
+        return requests.stream().filter(c -> !c.isFinished());
+    }
+
+    List<CommittableWithLineage<CommT>> drainCommitted() {

Review comment:
       I think java doc is required for this method. Will this method be called 
multiple times? How to make the numbers being synched with the `summary`, i.e. 
`hasReceivedAll()`? 
   
   There are many numbers defined in this class that need more detailed 
description about the relationship between them:
   1. total number of commitables in `summary`
   2. total number of `CommitRequestImpl` in `request`
      2.1 number of unfinished request
      2.2 number of failed request
      2.3 number of request that will be drained and removed
   3. numFailed, accumulated if this method would be called multiple time.
   4. numDrained, accumulated if this method would be called multiple time.




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