helix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject [helix] branch master updated: Remove lock in HelixStateTransitionHandler (#1681)
Date Tue, 27 Apr 2021 18:10:45 GMT
This is an automated email from the ASF dual-hosted git repository.

jxue pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/helix.git


The following commit(s) were added to refs/heads/master by this push:
     new 07e3ed5  Remove lock in HelixStateTransitionHandler (#1681)
07e3ed5 is described below

commit 07e3ed590c61f3ee82b78b9f16b1b19ea7c92a8a
Author: xyuanlu <xyuanlu@gmail.com>
AuthorDate: Tue Apr 27 11:10:33 2021 -0700

    Remove lock in HelixStateTransitionHandler (#1681)
    
    * reducing lock scope in HelixStateTransitionHandler
    * remove lock
---
 .../handling/HelixStateTransitionHandler.java      | 96 +++++++++++-----------
 1 file changed, 48 insertions(+), 48 deletions(-)

diff --git a/helix-core/src/main/java/org/apache/helix/messaging/handling/HelixStateTransitionHandler.java
b/helix-core/src/main/java/org/apache/helix/messaging/handling/HelixStateTransitionHandler.java
index d32e90e..174d2b1 100644
--- a/helix-core/src/main/java/org/apache/helix/messaging/handling/HelixStateTransitionHandler.java
+++ b/helix-core/src/main/java/org/apache/helix/messaging/handling/HelixStateTransitionHandler.java
@@ -318,60 +318,60 @@ public class HelixStateTransitionHandler extends MessageHandler {
     NotificationContext context = _notificationContext;
     Message message = _message;
 
-    synchronized (_stateModel) {
-      HelixTaskResult taskResult = new HelixTaskResult();
-      HelixManager manager = context.getManager();
-
-      _statusUpdateUtil.logInfo(message, HelixStateTransitionHandler.class,
-          "Message handling task begin execute", manager);
-      message.setExecuteStartTimeStamp(System.currentTimeMillis());
-
-      try {
-        preHandleMessage();
-        invoke(manager, context, taskResult, message);
-      } catch (HelixDuplicatedStateTransitionException e) {
-        // Duplicated state transition problem is fine
-        taskResult.setSuccess(true);
-        taskResult.setMessage(e.toString());
-        taskResult.setInfo(e.getMessage());
-      } catch (HelixStateMismatchException e) {
-        // Simply log error and return from here if State mismatch.
-        // The current state of the state model is intact.
+    HelixTaskResult taskResult = new HelixTaskResult();
+    HelixManager manager = context.getManager();
+
+    _statusUpdateUtil
+        .logInfo(message, HelixStateTransitionHandler.class, "Message handling task begin
execute",
+            manager);
+    message.setExecuteStartTimeStamp(System.currentTimeMillis());
+
+    try {
+      preHandleMessage();
+      invoke(manager, context, taskResult, message);
+    } catch (HelixDuplicatedStateTransitionException e) {
+      // Duplicated state transition problem is fine
+      taskResult.setSuccess(true);
+      taskResult.setMessage(e.toString());
+      taskResult.setInfo(e.getMessage());
+    } catch (HelixStateMismatchException e) {
+      // Simply log error and return from here if State mismatch.
+      // The current state of the state model is intact.
+      taskResult.setSuccess(false);
+      taskResult.setMessage(e.toString());
+      taskResult.setException(e);
+    } catch (Exception e) {
+      String errorMessage =
+          "Exception while executing a state transition task " + message.getPartitionName();
+      logger.error(errorMessage, e);
+      if (e.getCause() != null && e.getCause() instanceof InterruptedException) {
+        e = (InterruptedException) e.getCause();
+      }
+
+      if (e instanceof HelixRollbackException || (e.getCause() != null && e
+          .getCause() instanceof HelixRollbackException)) {
+        // TODO : Support cancel to any state
+        logger.info(
+            "Rollback happened of state transition on resource \"" + _message.getResourceName()
+                + "\" partition \"" + _message.getPartitionName() + "\" from \"" + _message
+                .getFromState() + "\" to \"" + _message.getToState() + "\"");
+        taskResult.setCancelled(true);
+      } else {
+        _statusUpdateUtil
+            .logError(message, HelixStateTransitionHandler.class, e, errorMessage, manager);
         taskResult.setSuccess(false);
         taskResult.setMessage(e.toString());
         taskResult.setException(e);
-      } catch (Exception e) {
-        String errorMessage =
-            "Exception while executing a state transition task " + message.getPartitionName();
-        logger.error(errorMessage, e);
-        if (e.getCause() != null && e.getCause() instanceof InterruptedException)
{
-          e = (InterruptedException) e.getCause();
-        }
-
-        if (e instanceof HelixRollbackException
-            || (e.getCause() != null && e.getCause() instanceof HelixRollbackException))
{
-          // TODO : Support cancel to any state
-          logger.info("Rollback happened of state transition on resource \""
-              + _message.getResourceName() + "\" partition \"" + _message.getPartitionName()
-              + "\" from \"" + _message.getFromState() + "\" to \"" + _message.getToState()
+ "\"");
-          taskResult.setCancelled(true);
-        } else {
-          _statusUpdateUtil.logError(message, HelixStateTransitionHandler.class, e, errorMessage,
-              manager);
-          taskResult.setSuccess(false);
-          taskResult.setMessage(e.toString());
-          taskResult.setException(e);
-          taskResult.setInterrupted(e instanceof InterruptedException);
-        }
+        taskResult.setInterrupted(e instanceof InterruptedException);
       }
+    }
 
-      taskResult.setCompleteTime(System.currentTimeMillis());
-      // add task result to context for postHandling
-      context.add(MapKey.HELIX_TASK_RESULT.toString(), taskResult);
-      postHandleMessage();
+    taskResult.setCompleteTime(System.currentTimeMillis());
+    // add task result to context for postHandling
+    context.add(MapKey.HELIX_TASK_RESULT.toString(), taskResult);
+    postHandleMessage();
 
-      return taskResult;
-    }
+    return taskResult;
   }
 
   private void invoke(HelixManager manager, NotificationContext context, HelixTaskResult
taskResult,

Mime
View raw message