use of org.apache.helix.zookeeper.zkclient.IZkDataListener in project ambry by linkedin.
the class HelixClusterManager method initializeHelixManagerAndPropertyStoreInLocalDC.
/**
* Initialize HelixManager in local datacenter and complete subscription of HelixPropertyStore to listen for
* PartitionOverride zNode. This needs to happen before other datacenters are initialized so that any partition
* overrides can be properly honored.
* @param dataCenterToZkAddress the map mapping each datacenter to its corresponding ZkAddress.
* @param instanceName the String representation of the instance associated with this manager.
* @param helixFactory the factory class to construct and get a reference to a {@link HelixManager}.
* @return the HelixManager of local datacenter, or {@code null} if the local datacenter is
* {@link ReplicaType#CLOUD_BACKED}, as we currently do not support getting cluster state from Helix for cloud
* datacenters.
* @throws Exception
*/
private HelixManager initializeHelixManagerAndPropertyStoreInLocalDC(Map<String, DcZkInfo> dataCenterToZkAddress, String instanceName, HelixFactory helixFactory) throws Exception {
DcZkInfo dcZkInfo = dataCenterToZkAddress.get(clusterMapConfig.clusterMapDatacenterName);
if (dcZkInfo.getReplicaType() == ReplicaType.CLOUD_BACKED) {
return null;
}
// For now, the first ZK endpoint (if there are more than one endpoints) will be adopted by default. Note that, Ambry
// doesn't support multiple HelixClusterManagers(spectators) on same node.
String zkConnectStr = dcZkInfo.getZkConnectStrs().get(0);
HelixManager manager = helixFactory.getZkHelixManagerAndConnect(clusterName, instanceName, InstanceType.SPECTATOR, zkConnectStr);
helixPropertyStoreInLocalDc = manager.getHelixPropertyStore();
logger.info("HelixPropertyStore from local datacenter {} is: {}", dcZkInfo.getDcName(), helixPropertyStoreInLocalDc);
IZkDataListener dataListener = new IZkDataListener() {
@Override
public void handleDataChange(String dataPath, Object data) {
logger.info("Received data change notification for: {}", dataPath);
}
@Override
public void handleDataDeleted(String dataPath) {
logger.info("Received data delete notification for: {}", dataPath);
}
};
logger.info("Subscribing data listener to HelixPropertyStore.");
helixPropertyStoreInLocalDc.subscribeDataChanges(PARTITION_OVERRIDE_ZNODE_PATH, dataListener);
logger.info("Getting PartitionOverride ZNRecord from HelixPropertyStore");
ZNRecord zNRecord = helixPropertyStoreInLocalDc.get(PARTITION_OVERRIDE_ZNODE_PATH, null, AccessOption.PERSISTENT);
if (clusterMapConfig.clusterMapEnablePartitionOverride) {
if (zNRecord != null) {
partitionOverrideInfoMap.putAll(zNRecord.getMapFields());
logger.info("partitionOverrideInfoMap is initialized!");
} else {
logger.warn("ZNRecord from HelixPropertyStore is NULL, the partitionOverrideInfoMap is empty.");
}
}
return manager;
}
Aggregations