jiajunwang commented on a change in pull request #1756:
URL: https://github.com/apache/helix/pull/1756#discussion_r640045956



##########
File path: 
helix-core/src/main/java/org/apache/helix/controller/rebalancer/waged/ReadOnlyWagedRebalancer.java
##########
@@ -69,6 +71,10 @@ public void 
updateChangeDetectorSnapshots(ResourceControllerDataProvider dataPro
       super(new ZkBucketDataAccessor(metadataStoreAddress), clusterName);
     }
 
+    ReadOnlyAssignmentMetadataStore(ZkBucketDataAccessor zkBucketDataAccessor, 
String clusterName) {

Review comment:
       Optional, but if there is no other use cases, please just remove the 
older constructor. The newer one is more specific and avoid misusage, IMO.

##########
File path: helix-core/src/main/java/org/apache/helix/util/HelixUtil.java
##########
@@ -295,7 +352,6 @@ public static String serializeByComma(List<String> objects) 
{
       LOG.error("getIdealAssignmentForWagedFullAuto(): Failed to compute 
ResourceAssignments!", e);
     } finally {
       // Close all ZK connections
-      baseDataAccessor.close();
       readOnlyWagedRebalancer.close();

Review comment:
       readOnlyWagedRebalancer is also passed in object, why closing it but 
removing baseDataAccessor close?

##########
File path: helix-core/src/main/java/org/apache/helix/util/HelixUtil.java
##########
@@ -239,6 +277,25 @@ public static String serializeByComma(List<String> 
objects) {
         new ReadOnlyWagedRebalancer(metadataStoreAddress, 
globalSyncClusterConfig.getClusterName(),
             globalSyncClusterConfig.getGlobalRebalancePreference());
 
+    Map<String, ResourceAssignment> result =
+        getAssignmentForWagedFullAutoImpl(helixDataAccessor, 
readOnlyWagedRebalancer,
+            globalSyncClusterConfig, instanceConfigs, liveInstances, 
idealStates, resourceConfigs,
+            usePrefLists);
+    baseDataAccessor.close();

Review comment:
       close readOnlyWagedRebalancer?

##########
File path: helix-core/src/main/java/org/apache/helix/util/HelixUtil.java
##########
@@ -210,19 +231,36 @@ public static String serializeByComma(List<String> 
objects) {
       String metadataStoreAddress, ClusterConfig clusterConfig,
       List<InstanceConfig> instanceConfigs, List<String> liveInstances,
       List<IdealState> idealStates, List<ResourceConfig> resourceConfigs) {
-    return getAssignmentForWagedFullAutoImpl(metadataStoreAddress, 
clusterConfig,
-        instanceConfigs, liveInstances, idealStates, resourceConfigs, false);
+    return getAssignmentForWagedFullAutoHelper(metadataStoreAddress, 
clusterConfig, instanceConfigs,
+        liveInstances, idealStates, resourceConfigs, false);
   }
 
-  /*
-   * If usePrefLists is set to true, the returned assignment is based on 
preference lists; if
-   * false, the returned assignment is based on partition state mapping, which 
may differ from
-   * preference lists.
-   */
-  private static Map<String, ResourceAssignment> 
getAssignmentForWagedFullAutoImpl(
+  private static Map<String, ResourceAssignment> 
getAssignmentForWagedFullAutoHelper(
+      ZkBucketDataAccessor zkBucketDataAccessor, HelixDataAccessor 
helixDataAccessor,
+      ClusterConfig clusterConfig, List<InstanceConfig> instanceConfigs, 
List<String> liveInstances,
+      List<IdealState> idealStates, List<ResourceConfig> resourceConfigs, 
boolean usePrefLists) {
+
+    // 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);
+
+    // Create an instance of read-only WAGED rebalancer
+    ReadOnlyWagedRebalancer readOnlyWagedRebalancer =
+        new ReadOnlyWagedRebalancer(zkBucketDataAccessor, 
globalSyncClusterConfig.getClusterName(),
+            globalSyncClusterConfig.getGlobalRebalancePreference());
+
+    return getAssignmentForWagedFullAutoImpl(helixDataAccessor, 
readOnlyWagedRebalancer,
+        globalSyncClusterConfig, instanceConfigs, liveInstances, idealStates, 
resourceConfigs,
+        usePrefLists);
+  }
+
+  private static Map<String, ResourceAssignment> 
getAssignmentForWagedFullAutoHelper(

Review comment:
       This method is making the code here more complicated. I suggest not 
adding this one but making data accessor construction logic private methods and 
then call them repeatedly in the existing APIs.




-- 
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