jiajunwang commented on a change in pull request #827: Add intermediate storage
for customized state
URL: https://github.com/apache/helix/pull/827#discussion_r387862692
##########
File path:
helix-core/src/main/java/org/apache/helix/common/caches/CurrentStateCache.java
##########
@@ -55,149 +46,33 @@ public CurrentStateCache(String clusterName) {
public CurrentStateCache(ControlContextProvider contextProvider) {
super(contextProvider);
- _currentStateMap = Collections.emptyMap();
- _snapshot = new CurrentStateSnapshot(_currentStateCache);
+ _snapshot = new CurrentStateSnapshot(_participantStateCache);
}
- /**
- * This refreshes the CurrentStates data by re-fetching the data from
zookeeper in an efficient
- * way
- *
- * @param accessor
- * @param liveInstanceMap map of all liveInstances in cluster
- *
- * @return
- */
- public boolean refresh(HelixDataAccessor accessor,
- Map<String, LiveInstance> liveInstanceMap) {
- long startTime = System.currentTimeMillis();
-
- refreshCurrentStatesCache(accessor, liveInstanceMap);
- Map<String, Map<String, Map<String, CurrentState>>> allCurStateMap = new
HashMap<>();
- for (PropertyKey key : _currentStateCache.keySet()) {
- CurrentState currentState = _currentStateCache.get(key);
- String[] params = key.getParams();
- if (currentState != null && params.length >= 4) {
- String instanceName = params[1];
- String sessionId = params[2];
- String stateName = params[3];
- Map<String, Map<String, CurrentState>> instanceCurStateMap =
- allCurStateMap.get(instanceName);
- if (instanceCurStateMap == null) {
- instanceCurStateMap = Maps.newHashMap();
- allCurStateMap.put(instanceName, instanceCurStateMap);
- }
- Map<String, CurrentState> sessionCurStateMap =
instanceCurStateMap.get(sessionId);
- if (sessionCurStateMap == null) {
- sessionCurStateMap = Maps.newHashMap();
- instanceCurStateMap.put(sessionId, sessionCurStateMap);
- }
- sessionCurStateMap.put(stateName, currentState);
- }
- }
-
- for (String instance : allCurStateMap.keySet()) {
- allCurStateMap.put(instance,
Collections.unmodifiableMap(allCurStateMap.get(instance)));
- }
- _currentStateMap = Collections.unmodifiableMap(allCurStateMap);
-
- long endTime = System.currentTimeMillis();
- LogUtil.logInfo(LOG, genEventInfo(),
- "END: CurrentStateCache.refresh() for cluster " +
_controlContextProvider.getClusterName()
- + ", started at : " + startTime + ", took " + (endTime -
startTime) + " ms");
- if (LOG.isDebugEnabled()) {
- LogUtil.logDebug(LOG, genEventInfo(),
- String.format("Current State refreshed : %s",
_currentStateMap.toString()));
+ protected void refreshSnapshot(Map<PropertyKey, CurrentState> newStateCache,
+ Map<PropertyKey, CurrentState> participantStateCache, Set<PropertyKey>
reloadedKeys) {
+ if (_initialized) {
+ _snapshot = new CurrentStateSnapshot(newStateCache,
participantStateCache, reloadedKeys);
+ } else {
+ _snapshot = new CurrentStateSnapshot(newStateCache);
+ _initialized = true;
}
- return true;
}
- // reload current states that has been changed from zk to local cache.
- private void refreshCurrentStatesCache(HelixDataAccessor accessor,
- Map<String, LiveInstance> liveInstanceMap) {
-
- long start = System.currentTimeMillis();
+ public void PopulateParticipantKeys(HelixDataAccessor accessor,
Review comment:
If the input participantStateKeys is always empty and is a return value, why
not just let this method return a set for the keys?
----------------------------------------------------------------
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]