jiajunwang commented on a change in pull request #632: Asynchronously
calculating the Baseline
URL: https://github.com/apache/helix/pull/632#discussion_r360534965
##########
File path:
helix-core/src/main/java/org/apache/helix/controller/rebalancer/waged/WagedRebalancer.java
##########
@@ -199,23 +211,33 @@ private WagedRebalancer(AssignmentMetadataStore
assignmentMetadataStore,
BaselineDivergenceGauge.class);
_changeDetector = new ResourceChangeDetector(true);
+
+ _baselineCalculateExecutor = Executors.newSingleThreadExecutor();
+ _asyncGlobalRebalance = asyncGlobalRebalance;
+ }
+
+ // Update the global rebalance mode to be asynchronous or synchronous
+ public void setGlobalRebalanceAsyncMode(boolean asyncGlobalRebalance) {
+ _asyncGlobalRebalance = asyncGlobalRebalance;
}
- // Update the rebalancer preference configuration if the new preference is
different from the
- // current preference configuration.
- public void updatePreference(
+ // Update the rebalancer pereference if the new options are different from
the current
+ // pereference.
+ public synchronized void updateRebalancePereference(
Map<ClusterConfig.GlobalRebalancePreferenceKey, Integer> newPreference) {
- if (_preference.equals(NOT_CONFIGURED_PREFERENCE) ||
_preference.equals(newPreference)) {
- // 1. if the preference was not configured during constructing, no need
to update.
- // 2. if the preference equals to the new preference, no need to update.
- return;
+ // 1. if the preference was not configured during constructing, no need to
update.
+ // 2. if the preference equals to the new preference, no need to update.
+ if (!_preference.equals(NOT_CONFIGURED_PREFERENCE) &&
!_preference.equals(newPreference)) {
+ _rebalanceAlgorithm =
ConstraintBasedAlgorithmFactory.getInstance(newPreference);
+ _preference = ImmutableMap.copyOf(newPreference);
}
- _rebalanceAlgorithm =
ConstraintBasedAlgorithmFactory.getInstance(newPreference);
- _preference = ImmutableMap.copyOf(newPreference);
}
// Release all the resources.
public void close() {
+ if (_baselineCalculateExecutor != null) {
+ _baselineCalculateExecutor.shutdown();
+ }
Review comment:
That is to ensure the shutdown also cancel the ongoing runnable. My original
thought is that we don't cancel the ongoing calculation. Since there are at
most one in running state. So it should not take a long time. In addition,
since the change detector already finds something so we started calculating a
new baseline, it might be worthy to finish the process instead of just ignore
those changes.
What do you think?
----------------------------------------------------------------
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]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]