mgao0 commented on a change in pull request #1456:
URL: https://github.com/apache/helix/pull/1456#discussion_r508866971



##########
File path: 
helix-core/src/main/java/org/apache/helix/controller/GenericHelixController.java
##########
@@ -333,15 +338,19 @@ private void forceRebalance(HelixManager manager, 
ClusterEventType eventType) {
   void startPeriodRebalance(long period, HelixManager manager) {
     if (period != _timerPeriod) {

Review comment:
       Second JJ's comment. IMO since the set of this value is inside critical 
section, the read should be included too. Theoretically you could get a bad 
value.

##########
File path: 
helix-core/src/main/java/org/apache/helix/controller/GenericHelixController.java
##########
@@ -172,13 +173,15 @@
   private boolean _inMaintenanceMode;
 
   /**
-   * The timer that can periodically run the rebalancing pipeline. The timer 
will start if there is
-   * one resource group has the config to use the timer.
+   * The executors that can periodically run the rebalancing pipeline. A
+   * SingleThreadScheduledExecutor will start if there is resource group that 
has the config to do
+   * periodically rebalance.
    */
-  Timer _periodicalRebalanceTimer = null;
+  private static final ScheduledExecutorService _periodicalRebalanceExecutor =
+      Executors.newSingleThreadScheduledExecutor();

Review comment:
       When you initialize the executor service, you might want to 
setRemoveOnCancelPolicy to true, so the cancelled tasks are immediately removed 
from the work queue at time of cancellation. Otherwise, there could be memory 
leak in the work queue, might be a minor issue if we don't cancel tasks for 
many times, but if we cancel tasks frequently, you should consider adding this.

##########
File path: 
helix-core/src/main/java/org/apache/helix/controller/GenericHelixController.java
##########
@@ -1299,6 +1308,10 @@ protected void 
checkLiveInstancesObservation(List<LiveInstance> liveInstances,
   }
 
   public void shutdown() throws InterruptedException {
+    if (_periodicRebalancerFutureTasks != null) {
+      _periodicRebalancerFutureTasks.cancel(false);
+    }
+    _periodicalRebalanceExecutor.shutdown();

Review comment:
       Should we use shutDownNow() here then? You could add something like this:
   ` _periodicalRebalanceExecutor.shutdown();`
   ` stopPeriodRebalance();`
   `shutdownOnDemandTimer();`
   `if (!_periodicalRebalanceExecutor.awaitTermination(10, TimeUnit.SECONDS)) {`
   `          _periodicalRebalanceExecutor.shutdownNow(); }`
   This is also suggested here 
https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ExecutorService.html.
 This way you could make sure there's no leakage.




----------------------------------------------------------------
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:
[email protected]



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

Reply via email to