You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@helix.apache.org by GitBox <gi...@apache.org> on 2021/04/15 20:05:51 UTC

[GitHub] [helix] jiajunwang opened a new pull request #1698: Fix unexpected result when resuming a cluster from paused/maintenance mode.

jiajunwang opened a new pull request #1698:
URL: https://github.com/apache/helix/pull/1698


   ### Issues
   
   - [X] My PR addresses the following Helix issues and references them in the PR description:
   
   Resolves #1661 
   
   ### Description
   
   - [X] Here are some details about my PR, including screenshots of any UI changes:
   
   Fix unexpected results when resuming a cluster from paused/maintenance mode.
   
   This PR aims to fix a race condition that the resume event could be pushed to the event queue before the cluster status has been updated. In this case, when the event is processed, the controller might still think the cluster is in paused/maintenance mode. As a result, the resume event is discarded and the rebalance won't be done until the next event happens.
   
   ### Tests
   
   - [X] The following tests are written for this issue:
   
   A new test for the race condition is not easy unless we add some stubs for the test only. That will potentially slow the pipeline or introduce confusion. So I suggest that we rely on the existing test to ensure the changes are good. This logic is called in almost all the integration test, so if it has any regression, we shall see many failures.
   
   In addition, I have repeatedly run TestCleanupExternalView more than 50 times. And it works fine.
   
   - The following is the result of the "mvn test" command on the appropriate module:
   
   (If CI test fails due to known issue, please specify the issue and test PR locally. Then copy & paste the result of "mvn test" to here.)
   
   ### Documentation (Optional)
   
   - In case of new functionality, my PR adds documentation in the following wiki page:
   
   (Link the GitHub wiki you added)
   
   ### Commits
   
   - My commits all reference appropriate Apache Helix GitHub issues in their subject lines. In addition, my commits follow the guidelines from "[How to write a good git commit message](http://chris.beams.io/posts/git-commit/)":
     1. Subject is separated from body by a blank line
     1. Subject is limited to 50 characters (not including Jira issue reference)
     1. Subject does not end with a period
     1. Subject uses the imperative mood ("add", not "adding")
     1. Body wraps at 72 characters
     1. Body explains "what" and "why", not "how"
   
   ### Code Quality
   
   - My diff has been formatted using helix-style.xml 
   (helix-style-intellij.xml if IntelliJ IDE is used)
   


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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org
For additional commands, e-mail: reviews-help@helix.apache.org


[GitHub] [helix] jiajunwang commented on pull request #1698: Fix unexpected result when resuming a cluster from paused/maintenance mode.

Posted by GitBox <gi...@apache.org>.
jiajunwang commented on pull request #1698:
URL: https://github.com/apache/helix/pull/1698#issuecomment-823463449


   Approved by @dasahcc, I will merge soon.


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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org
For additional commands, e-mail: reviews-help@helix.apache.org


[GitHub] [helix] jiajunwang commented on a change in pull request #1698: Fix unexpected result when resuming a cluster from paused/maintenance mode.

Posted by GitBox <gi...@apache.org>.
jiajunwang commented on a change in pull request #1698:
URL: https://github.com/apache/helix/pull/1698#discussion_r614392945



##########
File path: helix-core/src/main/java/org/apache/helix/controller/GenericHelixController.java
##########
@@ -1469,35 +1463,41 @@ private void shutdownPipeline(Thread thread, ClusterEventBlockingQueue queue)
     }
   }
 
-  private boolean updateControllerState(NotificationContext changeContext, PauseSignal signal,
-      boolean statusFlag) {
+  private boolean updateControllerState(PauseSignal signal, boolean statusFlag) {
     if (signal != null) {
-      // This logic is used for recording first time entering PAUSE/MAINTENCE mode
       if (!statusFlag) {
         statusFlag = true;
+        // This log is recorded for the first time entering PAUSE/MAINTENANCE mode
         logger.info(String.format("controller is now %s",
             (signal instanceof MaintenanceSignal) ? "in maintenance mode" : "paused"));
       }
     } else {
-      if (statusFlag) {
-        statusFlag = false;
-        logger.info("controller is now resumed from paused state");
-        String uid = UUID.randomUUID().toString().substring(0, 8);
-        ClusterEvent event = new ClusterEvent(_clusterName, ClusterEventType.Resume,
-            String.format("%s_%s", uid, Pipeline.Type.DEFAULT.name()));
-        event.addAttribute(AttributeName.EVENT_SESSION.name(),
-            changeContext.getManager().getSessionIdIfLead());
-        event.addAttribute(AttributeName.changeContext.name(), changeContext);
-        event.addAttribute(AttributeName.helixmanager.name(), changeContext.getManager());
-        event.addAttribute(AttributeName.AsyncFIFOWorkerPool.name(), _asyncFIFOWorkerPool);
-        enqueueEvent(_eventQueue, event);
-        enqueueEvent(_taskEventQueue,
-            event.clone(String.format("%s_%s", uid, Pipeline.Type.TASK.name())));
-      }
+      statusFlag = false;
     }
     return statusFlag;
   }
 
+  /**
+   * Trigger a Resume Event if the cluster is back to activated.
+   * @param changeContext
+   * @param prevPaused the previous paused status.
+   * @param prevInMaintenanceMode the previous in maintenance mode status.
+   */
+  private void triggerResumeEvent(NotificationContext changeContext, boolean prevPaused,
+      boolean prevInMaintenanceMode) {
+    /**
+     * WARNING: the logic here is tricky.
+     * 1. Only resume if not paused. So if the Maintenance mode is removed but the cluster is still
+     * paused, the resume event should not be sent.
+     * 2. Only send resume event if the status is changed back to active. So we don't send multiple
+     * event unnecessarily.
+     */
+    if (!_paused && (prevPaused || (prevInMaintenanceMode && !_inMaintenanceMode))) {

Review comment:
       Do we need a resume event for the leaderswitch? I think it would send init event, right?




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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org
For additional commands, e-mail: reviews-help@helix.apache.org


[GitHub] [helix] jiajunwang merged pull request #1698: Fix unexpected result when resuming a cluster from paused/maintenance mode.

Posted by GitBox <gi...@apache.org>.
jiajunwang merged pull request #1698:
URL: https://github.com/apache/helix/pull/1698


   


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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org
For additional commands, e-mail: reviews-help@helix.apache.org


[GitHub] [helix] dasahcc commented on a change in pull request #1698: Fix unexpected result when resuming a cluster from paused/maintenance mode.

Posted by GitBox <gi...@apache.org>.
dasahcc commented on a change in pull request #1698:
URL: https://github.com/apache/helix/pull/1698#discussion_r614362946



##########
File path: helix-core/src/main/java/org/apache/helix/controller/GenericHelixController.java
##########
@@ -1469,35 +1463,41 @@ private void shutdownPipeline(Thread thread, ClusterEventBlockingQueue queue)
     }
   }
 
-  private boolean updateControllerState(NotificationContext changeContext, PauseSignal signal,
-      boolean statusFlag) {
+  private boolean updateControllerState(PauseSignal signal, boolean statusFlag) {
     if (signal != null) {
-      // This logic is used for recording first time entering PAUSE/MAINTENCE mode
       if (!statusFlag) {
         statusFlag = true;
+        // This log is recorded for the first time entering PAUSE/MAINTENANCE mode
         logger.info(String.format("controller is now %s",
             (signal instanceof MaintenanceSignal) ? "in maintenance mode" : "paused"));
       }
     } else {
-      if (statusFlag) {
-        statusFlag = false;
-        logger.info("controller is now resumed from paused state");
-        String uid = UUID.randomUUID().toString().substring(0, 8);
-        ClusterEvent event = new ClusterEvent(_clusterName, ClusterEventType.Resume,
-            String.format("%s_%s", uid, Pipeline.Type.DEFAULT.name()));
-        event.addAttribute(AttributeName.EVENT_SESSION.name(),
-            changeContext.getManager().getSessionIdIfLead());
-        event.addAttribute(AttributeName.changeContext.name(), changeContext);
-        event.addAttribute(AttributeName.helixmanager.name(), changeContext.getManager());
-        event.addAttribute(AttributeName.AsyncFIFOWorkerPool.name(), _asyncFIFOWorkerPool);
-        enqueueEvent(_eventQueue, event);
-        enqueueEvent(_taskEventQueue,
-            event.clone(String.format("%s_%s", uid, Pipeline.Type.TASK.name())));
-      }
+      statusFlag = false;
     }
     return statusFlag;
   }
 
+  /**
+   * Trigger a Resume Event if the cluster is back to activated.
+   * @param changeContext
+   * @param prevPaused the previous paused status.
+   * @param prevInMaintenanceMode the previous in maintenance mode status.
+   */
+  private void triggerResumeEvent(NotificationContext changeContext, boolean prevPaused,
+      boolean prevInMaintenanceMode) {
+    /**
+     * WARNING: the logic here is tricky.
+     * 1. Only resume if not paused. So if the Maintenance mode is removed but the cluster is still
+     * paused, the resume event should not be sent.
+     * 2. Only send resume event if the status is changed back to active. So we don't send multiple
+     * event unnecessarily.
+     */
+    if (!_paused && (prevPaused || (prevInMaintenanceMode && !_inMaintenanceMode))) {

Review comment:
       Could this check let first event missed when leaderswitch? Because when leaderswitch, prevPaused is false and current paused is false as well.




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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org
For additional commands, e-mail: reviews-help@helix.apache.org