Source:
<code>private void globalRebalance(ResourceControllerDataProvider clusterData, Map<String, Resource> resourceMap, final CurrentStateOutput currentStateOutput, RebalanceAlgorithm algorithm) throws HelixRebalanceException { _changeDetector.updateSnapshots(clusterData); final Map<HelixConstants.ChangeType, Set<String>> clusterChanges = _changeDetector.getAllChanges(); if (clusterChanges.keySet().stream() .anyMatch(GLOBAL_REBALANCE_REQUIRED_CHANGE_TYPES::contains)) { Map<String, ResourceAssignment> currentBaseline = getBaselineAssignment(_assignmentMetadataStore, currentStateOutput, resourceMap.keySet()); ClusterModel clusterModel; try { clusterModel = ClusterModelProvider .generateClusterModelForBaseline(clusterData, resourceMap, clusterData.getAllInstances(), clusterChanges, currentBaseline); } catch (Exception ex) { throw new HelixRebalanceException("Failed to generate cluster model for global rebalance.", HelixRebalanceException.Type.INVALID_CLUSTER_STATUS, ex); } <START> final boolean waitForGlobalRebalance = !_asyncBaselineCalculation; <END> final String clusterName = clusterData.getClusterName(); Future<Boolean> result = _baselineCalculateExecutor.submit(() -> { try { calculateAndUpdateBaseline(clusterModel, algorithm, !waitForGlobalRebalance, clusterName); } catch (HelixRebalanceException e) { LOG.error("Failed to calculate baseline assignment!", e); return false; } return true; }); if (waitForGlobalRebalance) { try { if (!result.get()) { throw new HelixRebalanceException("Failed to calculate for the new Baseline.", HelixRebalanceException.Type.FAILED_TO_CALCULATE); } } catch (InterruptedException | ExecutionException e) { throw new HelixRebalanceException("Failed to execute new Baseline calculation.", HelixRebalanceException.Type.FAILED_TO_CALCULATE, e); } } } }</code><technical_language>Prefer a consistent boolean variable, _waitForGlobalRebalance is sufficient _asyncBaselineCalculation</technical_language>

Target:
private void globalRebalance(ResourceControllerDataProvider clusterData, Map<String, Resource> resourceMap, final CurrentStateOutput currentStateOutput, RebalanceAlgorithm algorithm) throws HelixRebalanceException { _changeDetector.updateSnapshots(clusterData); final Map<HelixConstants.ChangeType, Set<String>> clusterChanges = _changeDetector.getAllChanges(); if (clusterChanges.keySet().stream() .anyMatch(GLOBAL_REBALANCE_REQUIRED_CHANGE_TYPES::contains)) { Map<String, ResourceAssignment> currentBaseline = getBaselineAssignment(_assignmentMetadataStore, currentStateOutput, resourceMap.keySet()); ClusterModel clusterModel; try { clusterModel = ClusterModelProvider .generateClusterModelForBaseline(clusterData, resourceMap, clusterData.getAllInstances(), clusterChanges, currentBaseline); } catch (Exception ex) { throw new HelixRebalanceException("Failed to generate cluster model for global rebalance.", HelixRebalanceException.Type.INVALID_CLUSTER_STATUS, ex); } final boolean waitForGlobalRebalance = !_asyncGlobalRebalanceEnabled; final String clusterName = clusterData.getClusterName(); Future<Boolean> result = _baselineCalculateExecutor.submit(() -> { try { calculateAndUpdateBaseline(clusterModel, algorithm, !waitForGlobalRebalance, clusterName); } catch (HelixRebalanceException e) { LOG.error("Failed to calculate baseline assignment!", e); return false; } return true; }); if (waitForGlobalRebalance) { try { if (!result.get()) { throw new HelixRebalanceException("Failed to calculate for the new Baseline.", HelixRebalanceException.Type.FAILED_TO_CALCULATE); } } catch (InterruptedException | ExecutionException e) { throw new HelixRebalanceException("Failed to execute new Baseline calculation.", HelixRebalanceException.Type.FAILED_TO_CALCULATE, e); } } } }