use of org.apache.helix.model.MaintenanceSignal in project helix by apache.
the class ClusterDataCache method refresh.
/**
* This refreshes the cluster data by re-fetching the data from zookeeper in
* an efficient way
* @param accessor
* @return
*/
public synchronized boolean refresh(HelixDataAccessor accessor) {
long startTime = System.currentTimeMillis();
Builder keyBuilder = accessor.keyBuilder();
if (_propertyDataChangedMap.get(ChangeType.IDEAL_STATE)) {
_propertyDataChangedMap.put(ChangeType.IDEAL_STATE, Boolean.valueOf(false));
clearCachedResourceAssignments();
_idealStateCacheMap = refreshIdealStates(accessor);
}
if (_propertyDataChangedMap.get(ChangeType.LIVE_INSTANCE)) {
long start = System.currentTimeMillis();
_propertyDataChangedMap.put(ChangeType.LIVE_INSTANCE, Boolean.valueOf(false));
clearCachedResourceAssignments();
_liveInstanceCacheMap = accessor.getChildValuesMap(keyBuilder.liveInstances(), true);
_updateInstanceOfflineTime = true;
LOG.info("Refresh LiveInstances for cluster " + _clusterName + ", took " + (System.currentTimeMillis() - startTime) + " ms");
}
if (_propertyDataChangedMap.get(ChangeType.INSTANCE_CONFIG)) {
_propertyDataChangedMap.put(ChangeType.INSTANCE_CONFIG, Boolean.valueOf(false));
clearCachedResourceAssignments();
_instanceConfigCacheMap = accessor.getChildValuesMap(keyBuilder.instanceConfigs(), true);
if (LOG.isDebugEnabled()) {
LOG.debug("Reload InstanceConfig: " + _instanceConfigCacheMap.keySet());
}
}
if (_propertyDataChangedMap.get(ChangeType.RESOURCE_CONFIG)) {
_propertyDataChangedMap.put(ChangeType.RESOURCE_CONFIG, Boolean.valueOf(false));
clearCachedResourceAssignments();
_resourceConfigCacheMap = accessor.getChildValuesMap(accessor.keyBuilder().resourceConfigs(), true);
if (LOG.isDebugEnabled()) {
LOG.debug("Reload ResourceConfigs: " + _resourceConfigCacheMap.size());
}
}
_idealStateMap = new HashMap<>(_idealStateCacheMap);
_liveInstanceMap = new HashMap(_liveInstanceCacheMap);
_instanceConfigMap = new ConcurrentHashMap<>(_instanceConfigCacheMap);
_resourceConfigMap = new HashMap(_resourceConfigCacheMap);
if (_updateInstanceOfflineTime) {
updateOfflineInstanceHistory(accessor);
}
if (_isTaskCache) {
_taskDataCache.refresh(accessor, _resourceConfigMap);
}
Map<String, StateModelDefinition> stateDefMap = accessor.getChildValuesMap(keyBuilder.stateModelDefs(), true);
_stateModelDefMap = new ConcurrentHashMap<>(stateDefMap);
_constraintMap = accessor.getChildValuesMap(keyBuilder.constraints(), true);
_clusterConfig = accessor.getProperty(keyBuilder.clusterConfig());
_instanceMessagesCache.refresh(accessor, _liveInstanceMap);
_currentStateCache.refresh(accessor, _liveInstanceMap);
// current state must be refreshed before refreshing relay messages
// because we need to use current state to validate all relay messages.
_instanceMessagesCache.updateRelayMessages(_liveInstanceMap, _currentStateCache.getCurrentStatesMap());
if (_clusterConfig != null) {
_idealStateRuleMap = _clusterConfig.getIdealStateRules();
} else {
_idealStateRuleMap = new HashMap();
LOG.warn("Cluster config is null!");
}
MaintenanceSignal maintenanceSignal = accessor.getProperty(keyBuilder.maintenance());
_isMaintenanceModeEnabled = (maintenanceSignal != null) ? true : false;
updateDisabledInstances();
long endTime = System.currentTimeMillis();
LOG.info("END: ClusterDataCache.refresh() for cluster " + getClusterName() + ", took " + (endTime - startTime) + " ms");
if (LOG.isDebugEnabled()) {
LOG.debug("# of StateModelDefinition read from zk: " + _stateModelDefMap.size());
LOG.debug("# of ConstraintMap read from zk: " + _constraintMap.size());
LOG.debug("LiveInstances: " + _liveInstanceMap.keySet());
for (LiveInstance instance : _liveInstanceMap.values()) {
LOG.debug("live instance: " + instance.getInstanceName() + " " + instance.getSessionId());
}
LOG.debug("IdealStates: " + _idealStateMap.keySet());
LOG.debug("ResourceConfigs: " + _resourceConfigMap.keySet());
LOG.debug("InstanceConfigs: " + _instanceConfigMap.keySet());
LOG.debug("ClusterConfigs: " + _clusterConfig);
LOG.debug("JobContexts: " + _taskDataCache.getContexts().keySet());
}
if (LOG.isTraceEnabled()) {
LOG.trace("Cache content: " + toString());
}
return true;
}
Aggregations