use of 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.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.curator.framework.recipes.cache.PathChildrenCache in project coprhd-controller by CoprHD.
the class DistributedDataManagerImpl method ensureCacheStarted.
/**
* Use the double-check algorithm to initialize the child path cache for use in limit checking
*/
private void ensureCacheStarted() {
if (_basePathCache == null) {
synchronized (this) {
if (_basePathCache == null) {
try {
_basePathCache = new PathChildrenCache(_zkClient, _basePath, false);
_basePathCache.start();
} catch (Exception ex) {
_basePathCache = null;
_log.error(String.format("%s: error initializing cache; will re-attempt", _basePath), ex);
}
}
}
}
}
use of org.apache.curator.framework.recipes.cache.PathChildrenCache in project hive by apache.
the class LlapZookeeperRegistryImpl method checkPathChildrenCache.
private synchronized void checkPathChildrenCache(long clusterReadyTimeoutMs) throws IOException {
Preconditions.checkArgument(zooKeeperClient != null && zooKeeperClient.getState() == CuratorFrameworkState.STARTED, "client is not started");
// lazily create PathChildrenCache
if (instancesCache != null)
return;
ExecutorService tp = Executors.newFixedThreadPool(1, new ThreadFactoryBuilder().setDaemon(true).setNameFormat("StateChangeNotificationHandler").build());
long startTimeNs = System.nanoTime(), deltaNs = clusterReadyTimeoutMs * 1000000L;
long sleepTimeMs = Math.min(16, clusterReadyTimeoutMs);
while (true) {
PathChildrenCache instancesCache = new PathChildrenCache(zooKeeperClient, workersPath, true);
instancesCache.getListenable().addListener(new InstanceStateChangeListener(), tp);
try {
instancesCache.start(PathChildrenCache.StartMode.BUILD_INITIAL_CACHE);
this.instancesCache = instancesCache;
break;
} catch (InvalidACLException e) {
// PathChildrenCache tried to mkdir when the znode wasn't there, and failed.
CloseableUtils.closeQuietly(instancesCache);
long elapsedNs = System.nanoTime() - startTimeNs;
if (deltaNs == 0 || deltaNs <= elapsedNs) {
LOG.error("Unable to start curator PathChildrenCache", e);
throw new IOException(e);
}
LOG.warn("The cluster is not started yet (InvalidACL); will retry");
try {
Thread.sleep(Math.min(sleepTimeMs, (deltaNs - elapsedNs) / 1000000L));
} catch (InterruptedException e1) {
LOG.error("Interrupted while retrying the PathChildrenCache startup");
throw new IOException(e1);
}
sleepTimeMs = sleepTimeMs << 1;
} catch (Exception e) {
CloseableUtils.closeQuietly(instancesCache);
LOG.error("Unable to start curator PathChildrenCache", e);
throw new IOException(e);
}
}
}
use of org.apache.curator.framework.recipes.cache.PathChildrenCache in project druid by druid-io.
the class ZkCoordinator method start.
@LifecycleStart
public void start() throws IOException {
synchronized (lock) {
if (started) {
return;
}
log.info("Starting zkCoordinator for server[%s]", me.getName());
final String loadQueueLocation = ZKPaths.makePath(zkPaths.getLoadQueuePath(), me.getName());
final String servedSegmentsLocation = ZKPaths.makePath(zkPaths.getServedSegmentsPath(), me.getName());
final String liveSegmentsLocation = ZKPaths.makePath(zkPaths.getLiveSegmentsPath(), me.getName());
loadQueueCache = new PathChildrenCache(curator, loadQueueLocation, true, true, Execs.multiThreaded(config.getNumLoadingThreads(), "ZkCoordinator-%s"));
try {
curator.newNamespaceAwareEnsurePath(loadQueueLocation).ensure(curator.getZookeeperClient());
curator.newNamespaceAwareEnsurePath(servedSegmentsLocation).ensure(curator.getZookeeperClient());
curator.newNamespaceAwareEnsurePath(liveSegmentsLocation).ensure(curator.getZookeeperClient());
loadLocalCache();
loadQueueCache.getListenable().addListener(new PathChildrenCacheListener() {
@Override
public void childEvent(CuratorFramework client, PathChildrenCacheEvent event) throws Exception {
final ChildData child = event.getData();
switch(event.getType()) {
case CHILD_ADDED:
final String path = child.getPath();
final DataSegmentChangeRequest request = jsonMapper.readValue(child.getData(), DataSegmentChangeRequest.class);
log.info("New request[%s] with zNode[%s].", request.asString(), path);
try {
request.go(getDataSegmentChangeHandler(), new DataSegmentChangeCallback() {
boolean hasRun = false;
@Override
public void execute() {
try {
if (!hasRun) {
curator.delete().guaranteed().forPath(path);
log.info("Completed request [%s]", request.asString());
hasRun = true;
}
} catch (Exception e) {
try {
curator.delete().guaranteed().forPath(path);
} catch (Exception e1) {
log.error(e1, "Failed to delete zNode[%s], but ignoring exception.", path);
}
log.error(e, "Exception while removing zNode[%s]", path);
throw Throwables.propagate(e);
}
}
});
} catch (Exception e) {
try {
curator.delete().guaranteed().forPath(path);
} catch (Exception e1) {
log.error(e1, "Failed to delete zNode[%s], but ignoring exception.", path);
}
log.makeAlert(e, "Segment load/unload: uncaught exception.").addData("node", path).addData("nodeProperties", request).emit();
}
break;
case CHILD_REMOVED:
log.info("zNode[%s] was removed", event.getData().getPath());
break;
default:
log.info("Ignoring event[%s]", event);
}
}
});
loadQueueCache.start();
} catch (Exception e) {
Throwables.propagateIfPossible(e, IOException.class);
throw Throwables.propagate(e);
}
started = true;
}
}
Aggregations