jerrypeng commented on a change in pull request #10370:
URL: https://github.com/apache/pulsar/pull/10370#discussion_r632663569



##########
File path: 
pulsar-functions/instance/src/main/java/org/apache/pulsar/functions/instance/JavaInstanceRunnable.java
##########
@@ -317,46 +322,77 @@ private void setupStateStore() throws Exception {
         }
     }
 
-    private void processResult(Record srcRecord,
-                               CompletableFuture<JavaExecutionResult> result) 
throws Exception {
-        result.whenComplete((result1, throwable) -> {
-            if (throwable != null || result1.getUserException() != null) {
-                Throwable t = throwable != null ? throwable : 
result1.getUserException();
-                log.warn("Encountered exception when processing message {}",
-                        srcRecord, t);
-                stats.incrUserExceptions(t);
-                srcRecord.fail();
-            } else {
-                if (result1.getResult() != null) {
-                    sendOutputMessage(srcRecord, result1.getResult());
+    private void processResult(@SuppressWarnings("rawtypes") Record srcRecord,
+                               JavaExecutionResult result) throws 
SinkException {
+       
+       if (result.getUserException() != null) {
+            stats.incrUserExceptions(result.getUserException());
+            srcRecord.fail();
+            return;
+       }
+       
+       if (result.isAsync()) {
+          result.getFuture().whenComplete((result1, throwable) -> {
+              if (throwable != null) {
+                  Throwable t = throwable;
+                  log.warn("Encountered exception when processing message {}", 
srcRecord, t);
+                  stats.incrUserExceptions(t);
+                  srcRecord.fail();
+              } else {
+                if (result1 != null) {
+                  try {
+                    sendOutputMessage(srcRecord, result1);
+                  } catch (SinkException e) {
+                    log.warn("Encountered exception when publishing result 
{}", srcRecord, e);
+                  }
                 } else {
-                    if (instanceConfig.getFunctionDetails().getAutoAck()) {
-                        // the function doesn't produce any result or the user 
doesn't want the result.
-                        srcRecord.ack();
-                    }
+                  if (instanceConfig.getFunctionDetails().getAutoAck()) {
+                    // the function doesn't produce any result or the user 
doesn't want the result.
+                    srcRecord.ack();
+                  }
                 }
                 // increment total successfully processed
                 stats.incrTotalProcessedSuccessfully();
+              }
+          }); 
+         } else {

Review comment:
       In this code path we still need to check if there was a user exception 
thrown in the function and fail the record is there was.




-- 
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:
us...@infra.apache.org


Reply via email to