Search in sources :

Example 66 with PathChildrenCache

use of org.apache.curator.framework.recipes.cache.PathChildrenCache in project druid by druid-io.

the class CuratorDruidCoordinatorTest method setUp.

@Before
public void setUp() throws Exception {
    segmentsMetadataManager = EasyMock.createNiceMock(SegmentsMetadataManager.class);
    dataSourcesSnapshot = EasyMock.createNiceMock(DataSourcesSnapshot.class);
    coordinatorRuntimeParams = EasyMock.createNiceMock(DruidCoordinatorRuntimeParams.class);
    metadataRuleManager = EasyMock.createNiceMock(MetadataRuleManager.class);
    configManager = EasyMock.createNiceMock(JacksonConfigManager.class);
    EasyMock.expect(configManager.watch(EasyMock.eq(CoordinatorDynamicConfig.CONFIG_KEY), EasyMock.anyObject(Class.class), EasyMock.anyObject())).andReturn(new AtomicReference<>(CoordinatorDynamicConfig.builder().build())).anyTimes();
    EasyMock.expect(configManager.watch(EasyMock.eq(CoordinatorCompactionConfig.CONFIG_KEY), EasyMock.anyObject(Class.class), EasyMock.anyObject())).andReturn(new AtomicReference(CoordinatorCompactionConfig.empty())).anyTimes();
    EasyMock.replay(configManager);
    setupServerAndCurator();
    curator.start();
    curator.blockUntilConnected();
    curator.create().creatingParentsIfNeeded().forPath(SEGPATH);
    curator.create().creatingParentsIfNeeded().forPath(SOURCE_LOAD_PATH);
    curator.create().creatingParentsIfNeeded().forPath(DESTINATION_LOAD_PATH);
    objectMapper = new DefaultObjectMapper();
    druidCoordinatorConfig = new TestDruidCoordinatorConfig(new Duration(COORDINATOR_START_DELAY), new Duration(COORDINATOR_PERIOD), null, null, null, new Duration(COORDINATOR_PERIOD), null, null, null, null, null, null, null, null, null, null, 10, new Duration("PT0s"));
    sourceLoadQueueChildrenCache = new PathChildrenCache(curator, SOURCE_LOAD_PATH, true, true, Execs.singleThreaded("coordinator_test_path_children_cache_src-%d"));
    destinationLoadQueueChildrenCache = new PathChildrenCache(curator, DESTINATION_LOAD_PATH, true, true, Execs.singleThreaded("coordinator_test_path_children_cache_dest-%d"));
    sourceLoadQueuePeon = new CuratorLoadQueuePeon(curator, SOURCE_LOAD_PATH, objectMapper, peonExec, callbackExec, druidCoordinatorConfig);
    destinationLoadQueuePeon = new CuratorLoadQueuePeon(curator, DESTINATION_LOAD_PATH, objectMapper, peonExec, callbackExec, druidCoordinatorConfig);
    druidNode = new DruidNode("hey", "what", false, 1234, null, true, false);
    loadManagementPeons = new ConcurrentHashMap<>();
    scheduledExecutorFactory = (corePoolSize, nameFormat) -> Executors.newSingleThreadScheduledExecutor();
    leaderAnnouncerLatch = new CountDownLatch(1);
    leaderUnannouncerLatch = new CountDownLatch(1);
    coordinator = new DruidCoordinator(druidCoordinatorConfig, new ZkPathsConfig() {

        @Override
        public String getBase() {
            return "druid";
        }
    }, configManager, segmentsMetadataManager, baseView, metadataRuleManager, () -> curator, new NoopServiceEmitter(), scheduledExecutorFactory, null, null, new NoopServiceAnnouncer() {

        @Override
        public void announce(DruidNode node) {
            // count down when this coordinator becomes the leader
            leaderAnnouncerLatch.countDown();
        }

        @Override
        public void unannounce(DruidNode node) {
            leaderUnannouncerLatch.countDown();
        }
    }, druidNode, loadManagementPeons, null, null, new CoordinatorCustomDutyGroups(ImmutableSet.of()), new CostBalancerStrategyFactory(), EasyMock.createNiceMock(LookupCoordinatorManager.class), new TestDruidLeaderSelector(), null, ZkEnablementConfig.ENABLED);
}
Also used : SegmentsMetadataManager(org.apache.druid.metadata.SegmentsMetadataManager) MetadataRuleManager(org.apache.druid.metadata.MetadataRuleManager) JacksonConfigManager(org.apache.druid.common.config.JacksonConfigManager) AtomicReference(java.util.concurrent.atomic.AtomicReference) Duration(org.joda.time.Duration) NoopServiceEmitter(org.apache.druid.server.metrics.NoopServiceEmitter) CountDownLatch(java.util.concurrent.CountDownLatch) PathChildrenCache(org.apache.curator.framework.recipes.cache.PathChildrenCache) ZkPathsConfig(org.apache.druid.server.initialization.ZkPathsConfig) DefaultObjectMapper(org.apache.druid.jackson.DefaultObjectMapper) DruidNode(org.apache.druid.server.DruidNode) DataSourcesSnapshot(org.apache.druid.client.DataSourcesSnapshot) NoopServiceAnnouncer(org.apache.druid.curator.discovery.NoopServiceAnnouncer) CoordinatorCustomDutyGroups(org.apache.druid.server.coordinator.duty.CoordinatorCustomDutyGroups) Before(org.junit.Before)

Example 67 with PathChildrenCache

use of org.apache.curator.framework.recipes.cache.PathChildrenCache in project flink by apache.

the class ZooKeeperJobGraphsStoreITCase method createZooKeeperJobGraphStore.

@Nonnull
private JobGraphStore createZooKeeperJobGraphStore(String fullPath) throws Exception {
    final CuratorFramework client = ZooKeeper.getClient();
    // Ensure that the job graphs path exists
    client.newNamespaceAwareEnsurePath(fullPath).ensure(client.getZookeeperClient());
    // All operations will have the path as root
    CuratorFramework facade = client.usingNamespace(client.getNamespace() + fullPath);
    final ZooKeeperStateHandleStore<JobGraph> zooKeeperStateHandleStore = new ZooKeeperStateHandleStore<>(facade, localStateStorage);
    return new DefaultJobGraphStore<>(zooKeeperStateHandleStore, new ZooKeeperJobGraphStoreWatcher(new PathChildrenCache(facade, "/", false)), ZooKeeperJobGraphStoreUtil.INSTANCE);
}
Also used : CuratorFramework(org.apache.flink.shaded.curator5.org.apache.curator.framework.CuratorFramework) JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) ZooKeeperStateHandleStore(org.apache.flink.runtime.zookeeper.ZooKeeperStateHandleStore) PathChildrenCache(org.apache.flink.shaded.curator5.org.apache.curator.framework.recipes.cache.PathChildrenCache) Nonnull(javax.annotation.Nonnull)

Example 68 with PathChildrenCache

use of org.apache.curator.framework.recipes.cache.PathChildrenCache in project Mycat-Server by MyCATApache.

the class ZKUtils method addChildPathCache.

public static void addChildPathCache(String path, PathChildrenCacheListener listener) {
    NameableExecutor businessExecutor = MycatServer.getInstance().getBusinessExecutor();
    ExecutorService executor = businessExecutor == null ? Executors.newFixedThreadPool(5) : businessExecutor;
    try {
        /**
         * 监听子节点的变化情况
         */
        final PathChildrenCache childrenCache = new PathChildrenCache(getConnection(), path, true);
        childrenCache.start(PathChildrenCache.StartMode.POST_INITIALIZED_EVENT);
        childrenCache.getListenable().addListener(listener, executor);
        watchMap.put(path, childrenCache);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : PathChildrenCache(org.apache.curator.framework.recipes.cache.PathChildrenCache) IOException(java.io.IOException)

Example 69 with PathChildrenCache

use of org.apache.curator.framework.recipes.cache.PathChildrenCache in project chassis by Kixeye.

the class DynamicZookeeperConfigurationSource method initializePathChildrenCache.

private void initializePathChildrenCache() {
    pathChildrenCache = new PathChildrenCache(curatorFramework, configPathRoot, true);
    pathChildrenCache.getListenable().addListener(new PathChildrenCacheListener() {

        @Override
        public void childEvent(CuratorFramework client, PathChildrenCacheEvent event) throws Exception {
            LOGGER.debug("Got event {}", event);
            if (event.getType() == PathChildrenCacheEvent.Type.CHILD_ADDED && event.getData().getPath().equals(instanceConfigPath)) {
                // do stuff
                LOGGER.info("Detected creation of node {}. Initializing zookeeper configuration source...", instanceConfigPath);
                try {
                    initializeZookeeperConfigurationSource();
                } catch (BootstrapException e) {
                    LOGGER.error("Failed to initialized zookeeper configuration source for path " + instanceConfigPath, e);
                    throw e;
                }
                return;
            }
            if (event.getType() == PathChildrenCacheEvent.Type.CHILD_REMOVED && event.getData().getPath().equals(instanceConfigPath)) {
                if (running) {
                    LOGGER.info("Detected deletion of node {}, destroying zookeeper configuration source...", instanceConfigPath);
                    destroyZookeeperCofigurationSource();
                    return;
                }
                LOGGER.warn("Detected deletion of node {}, but zookeeper configuration source not currently running. This should not happen. Ignoring event...", instanceConfigPath);
                return;
            }
            LOGGER.debug("Ignoring event {}", event);
        }
    });
    try {
        pathChildrenCache.start(StartMode.BUILD_INITIAL_CACHE);
    } catch (Exception e) {
        throw new BootstrapException("Failed to initialize zookeeper configuration path cache" + configPathRoot, e);
    }
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) PathChildrenCacheListener(org.apache.curator.framework.recipes.cache.PathChildrenCacheListener) PathChildrenCacheEvent(org.apache.curator.framework.recipes.cache.PathChildrenCacheEvent) PathChildrenCache(org.apache.curator.framework.recipes.cache.PathChildrenCache) BootstrapException(com.kixeye.chassis.bootstrap.BootstrapException) BootstrapException(com.kixeye.chassis.bootstrap.BootstrapException) IOException(java.io.IOException)

Example 70 with PathChildrenCache

use of org.apache.curator.framework.recipes.cache.PathChildrenCache in project hive by apache.

the class KillQueryZookeeperManager method start.

@Override
public synchronized void start() {
    super.start();
    if (zooKeeperClient == null) {
        throw new ServiceException("Failed start zookeeperClient in KillQueryZookeeperManager");
    }
    try {
        ZookeeperUtils.setupZookeeperAuth(this.getHiveConf(), SASL_LOGIN_CONTEXT_NAME, zkPrincipal, zkKeytab);
        zooKeeperClient.start();
        try {
            zooKeeperClient.create().creatingParentsIfNeeded().withMode(CreateMode.PERSISTENT).forPath("/" + zkNameSpace);
            if (ZookeeperUtils.isKerberosEnabled(conf)) {
                zooKeeperClient.setACL().withACL(createSecureAcls()).forPath("/" + zkNameSpace);
            }
            LOG.info("Created the root namespace: " + zkNameSpace + " on ZooKeeper");
        } catch (KeeperException e) {
            if (e.code() != KeeperException.Code.NODEEXISTS) {
                LOG.error("Unable to create namespace: " + zkNameSpace + " on ZooKeeper", e);
                throw e;
            }
        }
        // Create a path cache and start to listen for every kill query request from other servers.
        killQueryListener = new PathChildrenCache(zooKeeperClient, "/" + zkNameSpace, false);
        killQueryListener.start(PathChildrenCache.StartMode.NORMAL);
        startListeningForQueries();
        // Init closeable utils in case register is not called (see HIVE-13322)
        CloseableUtils.class.getName();
    } catch (Exception e) {
        throw new RuntimeException("Failed start zookeeperClient in KillQueryZookeeperManager", e);
    }
    LOG.info("KillQueryZookeeperManager service started.");
}
Also used : ServiceException(org.apache.hive.service.ServiceException) PathChildrenCache(org.apache.curator.framework.recipes.cache.PathChildrenCache) KeeperException(org.apache.zookeeper.KeeperException) ServiceException(org.apache.hive.service.ServiceException) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException)

Aggregations

PathChildrenCache (org.apache.curator.framework.recipes.cache.PathChildrenCache)68 IOException (java.io.IOException)25 CuratorFramework (org.apache.curator.framework.CuratorFramework)21 PathChildrenCacheListener (org.apache.curator.framework.recipes.cache.PathChildrenCacheListener)20 PathChildrenCacheEvent (org.apache.curator.framework.recipes.cache.PathChildrenCacheEvent)14 KeeperException (org.apache.zookeeper.KeeperException)10 AtomicReference (java.util.concurrent.atomic.AtomicReference)8 ChildData (org.apache.curator.framework.recipes.cache.ChildData)7 CountDownLatch (java.util.concurrent.CountDownLatch)6 ExponentialBackoffRetry (org.apache.curator.retry.ExponentialBackoffRetry)6 Before (org.junit.Before)5 Test (org.junit.Test)5 ConcurrentMap (java.util.concurrent.ConcurrentMap)4 ExecutorService (java.util.concurrent.ExecutorService)4 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)4 Slf4j (lombok.extern.slf4j.Slf4j)4 ZKPaths (org.apache.curator.utils.ZKPaths)4 Preconditions (com.google.common.base.Preconditions)3 StreamImpl (io.pravega.client.stream.impl.StreamImpl)3 CompletableFuture (java.util.concurrent.CompletableFuture)3