dimas-b commented on code in PR #4962:
URL: https://github.com/apache/polaris/pull/4962#discussion_r3597105283


##########
runtime/service/src/main/java/org/apache/polaris/service/task/TaskExecutorImpl.java:
##########
@@ -229,35 +230,39 @@ protected void handleTask(
             .addKeyValue("taskEntityId", taskEntityId)
             .addKeyValue("taskType", task.getTaskType())
             .log("Unable to find handler for task type");
-        throw new RuntimeException(
+        throw new TaskHandlerNotFoundException(
             "Unable to find handler for task type "
                 + task.getTaskType()
                 + " for task entity id "
                 + taskEntityId);
       }
       TaskHandler handler = handlerOpt.get();
-      success = handler.handleTask(task, ctx);
-      if (success) {
-        LOGGER
-            .atInfo()
-            .addKeyValue("taskEntityId", taskEntityId)
-            .addKeyValue("handlerClass", handler.getClass())
-            .log("Task successfully handled");
-        metaStoreManager.dropEntityIfExists(
-            ctx.getPolarisCallContext(), null, taskEntity, Map.of(), false);
-      } else {
+      // Normal return from handleTask means the task work completed 
successfully. Set success
+      // before dropEntityIfExists so a later cleanup failure still reports 
TASK_SUCCESS=true
+      // (the exception is rethrown for retry/logging, but the attempt is not 
a handler failure).
+      handler.handleTask(task, ctx);
+      success = true;
+      LOGGER
+          .atInfo()
+          .addKeyValue("taskEntityId", taskEntityId)
+          .addKeyValue("handlerClass", handler.getClass())
+          .log("Task successfully handled");
+      metaStoreManager.dropEntityIfExists(
+          ctx.getPolarisCallContext(), null, taskEntity, Map.of(), false);
+    } catch (TaskHandlerNotFoundException e) {
+      // success stays false (never set true). Re-throw without the generic 
failure log below.
+      throw e;
+    } catch (Exception e) {
+      // Do not force success=false: handleTask may already have completed 
(success=true) and the
+      // failure may be from post-completion cleanup (e.g. dropEntityIfExists).
+      if (!success) {
         LOGGER
             .atWarn()
             .addKeyValue("taskEntityId", taskEntityId)
-            .addKeyValue("taskEntityName", taskEntity.getName())
+            .addKeyValue("taskEntityName", taskEntity != null ? 
taskEntity.getName() : "")
             .log("Unable to execute async task");
-        throw new RuntimeException(
-            "Task handler returned false for task entity id "
-                + taskEntityId
-                + " (handler: "
-                + handler.getClass().getSimpleName()
-                + ")");
       }
+      throw e;

Review Comment:
   Yes, logged here: 
https://github.com/apache/polaris/blob/b2ed126a817c2392357d2558a72d1d4cf74aa649/runtime/service/src/main/java/org/apache/polaris/service/task/TaskExecutorImpl.java#L191



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