lgbo-ustc commented on code in PR #12327:
URL: https://github.com/apache/gluten/pull/12327#discussion_r3510084122


##########
gluten-flink/runtime/src/main/java/org/apache/gluten/table/runtime/operators/GlutenTwoInputOperator.java:
##########
@@ -234,18 +262,33 @@ public void processWatermark2(Watermark mark) throws 
Exception {
     processElementInternal();
   }
 
+  @Override
+  public void endInput(int inputId) throws Exception {
+    switch (inputId) {
+      case 1:
+        leftInputEnded = true;
+        if (leftInputQueue != null) {
+          leftInputQueue.noMoreInput();
+        }
+        break;
+      case 2:
+        rightInputEnded = true;
+        if (rightInputQueue != null) {
+          rightInputQueue.noMoreInput();
+        }
+        break;
+      default:
+        throw new IllegalArgumentException("Unknown input id: " + inputId);
+    }
+  }
+
   @Override
   public void close() throws Exception {
     closing = true;
     GlutenCloseables.runWithCleanup(
         () -> {
-          if (leftInputQueue != null) {
-            leftInputQueue.close();
-          }
-        },
-        () -> {
-          if (rightInputQueue != null) {
-            rightInputQueue.close();
+          if (task != null) {
+            finishTask();

Review Comment:
   Calling `finishTask()` from `close()` is unsafe because Flink closes an 
operator chain from tail to head. For a chain like `op1 -> op2 -> op3`, 
`op3.close()` has already run when `op2.close()` is invoked. If `finishTask()` 
drains native output here, `processAvailableElement()` can still call 
`outputBridge.collect(...)` and push new records to a downstream operator/sink 
that has already been closed. Final draining should happen in the normal 
end-of-input/finish path, where Flink finishes operators head-to-tail, not in 
`close()` which should only release resources/cancel the native task.



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to