use of org.apache.flink.shaded.curator5.org.apache.curator.framework.recipes.cache.PathChildrenCache in project pravega by pravega.
the class ZooKeeperBucketManager method startBucketOwnershipListener.
@Override
public void startBucketOwnershipListener() {
PathChildrenCache pathChildrenCache = bucketOwnershipCacheMap.computeIfAbsent(getServiceType(), x -> bucketStore.getServiceOwnershipPathChildrenCache(getServiceType()));
PathChildrenCacheListener bucketListener = (client, event) -> {
switch(event.getType()) {
case CHILD_ADDED:
// no action required
break;
case CHILD_REMOVED:
int bucketId = Integer.parseInt(ZKPaths.getNodeFromPath(event.getData().getPath()));
RetryHelper.withIndefiniteRetriesAsync(() -> tryTakeOwnership(bucketId), e -> log.warn("{}: exception while attempting to take ownership for bucket {}: {}", getServiceType(), bucketId, e.getMessage()), getExecutor());
break;
case CONNECTION_LOST:
log.warn("{}: Received connectivity error", getServiceType());
break;
default:
log.warn("Received unknown event {} on bucket root {} ", event.getType(), getServiceType());
}
};
pathChildrenCache.getListenable().addListener(bucketListener);
log.info("bucket ownership listener registered on bucket root {}", getServiceType());
try {
pathChildrenCache.start(PathChildrenCache.StartMode.NORMAL);
} catch (Exception e) {
log.error("Starting ownership listener for service {} threw exception", getServiceType(), e);
throw Exceptions.sneakyThrow(e);
}
}
use of org.apache.flink.shaded.curator5.org.apache.curator.framework.recipes.cache.PathChildrenCache in project BRFS by zhangnianli.
the class ResourceDuplicateNodeSelector method setClient.
public ResourceDuplicateNodeSelector setClient(CuratorFramework client, String zkPath) {
this.client = client;
this.pathCache = new PathChildrenCache(client, zkPath, true);
return this;
}
use of org.apache.flink.shaded.curator5.org.apache.curator.framework.recipes.cache.PathChildrenCache in project BRFS by zhangnianli.
the class FileNodeDistributor method serviceRemoved.
@Override
public void serviceRemoved(Service service) {
LOG.info("Service removed#######{}", service.getServiceId());
serviceTimeTable.remove(service.getServiceGroup(), service.getServiceId());
PathChildrenCache childWatcher = childWatchers.get(service.getServiceId());
CloseUtils.closeQuietly(childWatcher);
// 删除服务对应的文件槽
try {
client.delete().quietly().deletingChildrenIfNeeded().forPath(ZkFileCoordinatorPaths.buildServiceSinkPath(service));
} catch (Exception e) {
LOG.warn("Can not delete the sink of crushed service[{}]", service.getServiceId(), e);
}
// 把崩溃的Service持有的文件节点放入列表
executor.submit(new Runnable() {
@Override
public void run() {
for (FileNode node : fileStorer.listFileNodes(new ServiceFileNodeFilter(service))) {
wildFileNodes.add(node);
}
}
});
}
use of org.apache.flink.shaded.curator5.org.apache.curator.framework.recipes.cache.PathChildrenCache in project twister2 by DSC-SPIDAL.
the class ZKMasterController method initRestarting.
/**
* initialize JM when it is coming from failure
* @throws Exception
*/
private void initRestarting() throws Exception {
LOG.info("Job Master restarting .... ");
// build the cache
// we will not get events for the past worker joins/fails
ephemChildrenCache = new PathChildrenCache(client, ephemDir, true);
addEphemChildrenCacheListener(ephemChildrenCache);
ephemChildrenCache.start(PathChildrenCache.StartMode.BUILD_INITIAL_CACHE);
List<ChildData> joinedWorkerZnodes = ephemChildrenCache.getCurrentData();
LOG.info("Initially existing workers: " + joinedWorkerZnodes.size());
// We listen for status updates for persistent path
persChildrenCache = new PathChildrenCache(client, persDir, true);
addPersChildrenCacheListener(persChildrenCache);
persChildrenCache.start(PathChildrenCache.StartMode.BUILD_INITIAL_CACHE);
// get all joined workers and provide them to workerMonitor
List<WorkerWithState> joinedWorkers = new LinkedList<>();
for (ChildData child : joinedWorkerZnodes) {
String fullPath = child.getPath();
int workerID = ZKUtils.getWorkerIDFromEphemPath(fullPath);
WorkerWithState workerWithState = getWorkerWithState(workerID);
if (workerWithState != null) {
joinedWorkers.add(workerWithState);
} else {
LOG.severe("worker[" + fullPath + "] added, but its data can not be retrieved.");
}
}
// publish jm restarted event
jmRestarted();
// if all workers joined and allJoined event has not been published, publish it
boolean allJoined = workerMonitor.addJoinedWorkers(joinedWorkers);
if (allJoined && !allJoinedPublished()) {
LOG.info("Publishing AllJoined event when restarting, since it is not previously published.");
allJoined();
}
}
use of org.apache.flink.shaded.curator5.org.apache.curator.framework.recipes.cache.PathChildrenCache in project twister2 by DSC-SPIDAL.
the class ZKMasterController method initialize.
/**
* initialize ZKMasterController,
* create znode children caches for job master to watch proper events
*/
public void initialize(JobMasterState initialState) throws Twister2Exception {
if (!(initialState == JobMasterState.JM_STARTED || initialState == JobMasterState.JM_RESTARTED)) {
throw new Twister2Exception("initialState has to be either JobMasterState.JM_STARTED or " + "JobMasterState.JM_RESTARTED. Supplied value: " + initialState);
}
try {
String zkServerAddresses = ZKContext.serverAddresses(config);
int sessionTimeoutMs = FaultToleranceContext.sessionTimeout(config);
client = ZKUtils.connectToServer(zkServerAddresses, sessionTimeoutMs);
// with scaling up/down, it may have been changed
if (initialState == JobMasterState.JM_RESTARTED) {
initRestarting();
} else {
// We listen for join/remove events for ephemeral children
ephemChildrenCache = new PathChildrenCache(client, ephemDir, true);
addEphemChildrenCacheListener(ephemChildrenCache);
ephemChildrenCache.start();
// We listen for status updates for persistent path
persChildrenCache = new PathChildrenCache(client, persDir, true);
addPersChildrenCacheListener(persChildrenCache);
persChildrenCache.start();
}
// TODO: we nay need to create ephemeral job master znode so that
// workers can know when jm fails
// createJobMasterZnode(initialState);
LOG.info("Job Master: " + jmAddress + " initialized successfully.");
} catch (Twister2Exception e) {
throw e;
} catch (Exception e) {
throw new Twister2Exception("Exception when initializing ZKMasterController.", e);
}
}
Aggregations