Github user dasahcc commented on a diff in the pull request:
https://github.com/apache/helix/pull/169#discussion_r177527495
--- Diff:
helix-core/src/main/java/org/apache/helix/common/caches/BasicClusterDataCache.java
---
@@ -104,6 +108,52 @@ public void refresh(HelixDataAccessor accessor) {
}
}
+ /**
+ * Selective update Helix Cache by version
+ * @param accessor the HelixDataAccessor
+ * @param reloadKeys keys needs to be reload
+ * @param cachedKeys keys already exists in the cache
+ * @param cachedPropertyMap cached map of propertykey -> property object
+ * @param <T> the type of metadata
+ * @return
+ */
+ public static <T extends HelixProperty> Map<PropertyKey, T>
updateReloadProperties(
+ HelixDataAccessor accessor, List<PropertyKey> reloadKeys,
List<PropertyKey> cachedKeys,
+ Map<PropertyKey, T> cachedPropertyMap) {
+ // All new entries from zk not cached locally yet should be read from
ZK.
+ Map<PropertyKey, T> refreshedPropertyMap = Maps.newHashMap();
+ List<HelixProperty.Stat> stats = accessor.getPropertyStats(cachedKeys);
+ for (int i = 0; i < cachedKeys.size(); i++) {
+ PropertyKey key = cachedKeys.get(i);
+ HelixProperty.Stat stat = stats.get(i);
+ if (stat != null) {
+ T property = cachedPropertyMap.get(key);
+ if (property != null && property.getBucketSize() == 0 &&
property.getStat().equals(stat)) {
+ refreshedPropertyMap.put(key, property);
+ } else {
+ // need update from zk
+ reloadKeys.add(key);
+ }
+ } else {
+ LOG.warn("stat is null for key: " + key);
+ reloadKeys.add(key);
+ }
+ }
+
+ List<T> reloadedProperty = accessor.getProperty(reloadKeys, true);
+ Iterator<PropertyKey> csKeyIter = reloadKeys.iterator();
+ for (T property : reloadedProperty) {
+ PropertyKey key = csKeyIter.next();
+ if (property != null) {
+ refreshedPropertyMap.put(key, property);
+ } else {
+ LOG.warn("CurrentState null for key: " + key);
--- End diff --
Good catch. Will make correct logs.
---