narendly commented on a change in pull request #1058:
URL: https://github.com/apache/helix/pull/1058#discussion_r438374696
##########
File path: helix-core/src/main/java/org/apache/helix/util/HelixUtil.java
##########
@@ -175,37 +176,50 @@ public static String serializeByComma(List<String>
objects) {
String metadataStoreAddress, ClusterConfig clusterConfig,
List<InstanceConfig> instanceConfigs, List<String> liveInstances,
List<IdealState> idealStates, List<ResourceConfig> resourceConfigs) {
+ // Copy the cluster config and make globalRebalance happen synchronously
+ // Otherwise, globalRebalance may not complete and this util might end up
returning
+ // an empty assignment.
+ ClusterConfig globalSyncClusterConfig = new
ClusterConfig(clusterConfig.getRecord());
+ globalSyncClusterConfig.setGlobalRebalanceAsyncMode(false);
+
// Prepare a data accessor for a dataProvider (cache) refresh
BaseDataAccessor<ZNRecord> baseDataAccessor = new
ZkBaseDataAccessor<>(metadataStoreAddress);
HelixDataAccessor helixDataAccessor =
- new ZKHelixDataAccessor(clusterConfig.getClusterName(),
baseDataAccessor);
+ new ZKHelixDataAccessor(globalSyncClusterConfig.getClusterName(),
baseDataAccessor);
// Create an instance of read-only WAGED rebalancer
- ReadOnlyWagedRebalancer readOnlyWagedRebalancer =
- new ReadOnlyWagedRebalancer(metadataStoreAddress,
clusterConfig.getClusterName(),
- clusterConfig.getGlobalRebalancePreference());
+ DryrunWagedRebalancer dryrunWagedRebalancer =
+ new DryrunWagedRebalancer(metadataStoreAddress,
globalSyncClusterConfig.getClusterName(),
+ globalSyncClusterConfig.getGlobalRebalancePreference());
// Use a dummy event to run the required stages for BestPossibleState
calculation
// Attributes RESOURCES and RESOURCES_TO_REBALANCE are populated in
ResourceComputationStage
- ClusterEvent event = new ClusterEvent(clusterConfig.getClusterName(),
ClusterEventType.Unknown);
+ ClusterEvent event =
+ new ClusterEvent(globalSyncClusterConfig.getClusterName(),
ClusterEventType.Unknown);
try {
// Obtain a refreshed dataProvider (cache) and overwrite cluster
parameters with the given parameters
ResourceControllerDataProvider dataProvider =
- new ResourceControllerDataProvider(clusterConfig.getClusterName());
+ new
ResourceControllerDataProvider(globalSyncClusterConfig.getClusterName());
dataProvider.requireFullRefresh();
dataProvider.refresh(helixDataAccessor);
- dataProvider.setClusterConfig(clusterConfig);
+ dataProvider.setClusterConfig(globalSyncClusterConfig);
dataProvider.setInstanceConfigMap(instanceConfigs.stream()
.collect(Collectors.toMap(InstanceConfig::getInstanceName,
Function.identity())));
- dataProvider.setLiveInstances(
-
liveInstances.stream().map(LiveInstance::new).collect(Collectors.toList()));
+ // For LiveInstances, we must preserve the existing session IDs
+ // So read LiveInstance objects from the cluster and do a "retainAll" on
them
+ // liveInstanceMap is an unmodifiableMap instances, so we filter using a
stream
+ Map<String, LiveInstance> liveInstanceMap =
dataProvider.getLiveInstances();
+ List<LiveInstance> filteredLiveInstances =
liveInstanceMap.entrySet().stream()
+ .filter(entry ->
liveInstances.contains(entry.getKey())).map(Map.Entry::getValue)
Review comment:
Fixed
----------------------------------------------------------------
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]