lei-xia commented on a change in pull request #941: Fix unexpceted partition 
movements in the CrushEd strategy.
URL: https://github.com/apache/helix/pull/941#discussion_r407625983
 
 

 ##########
 File path: 
helix-core/src/main/java/org/apache/helix/controller/dataproviders/ResourceControllerDataProvider.java
 ##########
 @@ -294,4 +312,33 @@ public void clearMonitoringRecords() {
     _missingTopStateMap.clear();
     _lastTopStateLocationMap.clear();
   }
+
+  /**
+   * Return the cached stable partition list of the specified resource. If no 
such cached item,
+   * return empty list.
+   * This is for a backward compatible workaround to fix 
https://github.com/apache/helix/issues/940.
+   *
+   * @param resourceName
+   */
+  public List<String> getStablePartitionList(String resourceName) {
+    return _stablePartitionListCache.getOrDefault(resourceName, 
Collections.EMPTY_LIST);
+  }
+
+  /**
+   * Refresh the stable partition list cache items and remove the non-exist 
resources' cache.
+   * This is for a backward compatible workaround to fix 
https://github.com/apache/helix/issues/940.
+   *
+   * @param idealStateMap
+   */
+  final void refreshStablePartitionList(Map<String, IdealState> idealStateMap) 
{
+    _stablePartitionListCache.keySet().retainAll(idealStateMap.keySet());
+    for (String resourceName : idealStateMap.keySet()) {
+      Set<String> newPartitionSet = 
idealStateMap.get(resourceName).getPartitionSet();
+      List<String> cachedPartitionList = getStablePartitionList(resourceName);
+      if (cachedPartitionList.size() != newPartitionSet.size() || 
!newPartitionSet
+          .containsAll(cachedPartitionList)) {
 
 Review comment:
   Keep in mind "newPartitionSet.containsAll(cachedPartitionList))" could cause 
a performance (delay) issue, the operation is O(N^2), given if we have large 
number of partitions. 

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

Reply via email to