Search in sources :

Example 71 with PathChildrenCache

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

the class LoadQueuePeonTest method setUp.

@Before
public void setUp() throws Exception {
    setupServerAndCurator();
    curator.start();
    curator.blockUntilConnected();
    curator.create().creatingParentsIfNeeded().forPath(LOAD_QUEUE_PATH);
    loadQueueCache = new PathChildrenCache(curator, LOAD_QUEUE_PATH, true, true, Execs.singleThreaded("load_queue_cache-%d"));
}
Also used : PathChildrenCache(org.apache.curator.framework.recipes.cache.PathChildrenCache) Before(org.junit.Before)

Example 72 with PathChildrenCache

use of org.apache.flink.shaded.curator5.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 73 with PathChildrenCache

use of org.apache.flink.shaded.curator5.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 74 with PathChildrenCache

use of org.apache.flink.shaded.curator5.org.apache.curator.framework.recipes.cache.PathChildrenCache in project twister2 by DSC-SPIDAL.

the class ZKWorkerController method initialize.

/**
 * Initialize this ZKWorkerController
 * Connect to the ZK server
 * create a persistent znode for this worker
 *   set this WorkerInfo and its status in the body of that znode
 * create an ephemeral znode for this worker
 * create a cache for the persistent znode of the job for watching job scaling events
 *
 * initialState has to be either: WorkerState.STARTED or WorkerState.RESTARTED
 * <p>
 * The body of the persistent worker znode will be updated as the status of worker changes
 * from STARTED, COMPLETED,
 */
public void initialize(int restartCount1, long jsTime) throws Exception {
    this.restartCount = restartCount1;
    this.initialState = restartCount > 0 ? WorkerState.RESTARTED : WorkerState.STARTED;
    if (!(initialState == WorkerState.STARTED || initialState == WorkerState.RESTARTED)) {
        throw new Exception("initialState has to be either WorkerState.STARTED or " + "WorkerState.RESTARTED. Supplied value: " + initialState);
    }
    try {
        String zkServerAddresses = ZKContext.serverAddresses(config);
        int sessionTimeoutMs = FaultToleranceContext.sessionTimeout(config);
        client = ZKUtils.connectToServer(zkServerAddresses, sessionTimeoutMs);
        // we first create persistent znode for the worker
        if (initialState == WorkerState.STARTED) {
            if (JobZNodeManager.checkJstZNodeWaitIfNeeded(client, rootPath, jobID, jsTime)) {
                ZKPersStateManager.createWorkerPersState(client, rootPath, jobID, workerInfo);
            }
        } else {
            ZKPersStateManager.updateWorkerStatus(client, rootPath, jobID, workerInfo, restartCount, WorkerState.RESTARTED);
        }
        // if this worker is started with scaling up, or
        // if it is coming from failure
        // we need to handle past events
        numberOfPastEvents = ZKEventsManager.getNumberOfPastEvents(client, rootPath, jobID);
        pastEvents = new TreeMap<>(Collections.reverseOrder());
        int wID = workerInfo.getWorkerID();
        if (isRestarted()) {
            // delete ephemeral worker znode from previous run, if there is any
            ZKEphemStateManager.removeEphemZNode(client, rootPath, jobID, wID);
            // worker may have crashed during barrier operation
            if (ZKBarrierManager.existWorkerZNodeAtDefault(client, rootPath, jobID, wID)) {
                ZKBarrierManager.deleteWorkerZNodeFromDefault(client, rootPath, jobID, wID);
            }
            if (ZKBarrierManager.existWorkerZNodeAtInit(client, rootPath, jobID, wID)) {
                ZKBarrierManager.deleteWorkerZNodeFromInit(client, rootPath, jobID, wID);
            }
        }
        String eventsDir = ZKUtils.eventsDir(rootPath, jobID);
        eventsChildrenCache = new PathChildrenCache(client, eventsDir, true);
        addEventsChildrenCacheListener(eventsChildrenCache);
        eventsChildrenCache.start();
        // update numberOfWorkers from jobZnode
        // with scaling up/down, it may have been changed
        JobWithState jobWithState = JobZNodeManager.readJobZNode(client, rootPath, jobID);
        if (numberOfWorkers != jobWithState.getJob().getNumberOfWorkers()) {
            numberOfWorkers = jobWithState.getJob().getNumberOfWorkers();
            LOG.info("numberOfWorkers updated from persJobZnode as: " + numberOfWorkers);
        }
        createWorkerZnode();
        LOG.info("This worker: " + workerInfo.getWorkerID() + " initialized successfully.");
    } catch (Exception e) {
        LOG.log(Level.SEVERE, "Exception when initializing ZKWorkerController", e);
        throw e;
    }
}
Also used : PathChildrenCache(org.apache.curator.framework.recipes.cache.PathChildrenCache) JobFaultyException(edu.iu.dsc.tws.api.exceptions.JobFaultyException) Twister2Exception(edu.iu.dsc.tws.api.exceptions.Twister2Exception) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) TimeoutException(edu.iu.dsc.tws.api.exceptions.TimeoutException)

Example 75 with PathChildrenCache

use of org.apache.flink.shaded.curator5.org.apache.curator.framework.recipes.cache.PathChildrenCache in project twister2 by DSC-SPIDAL.

the class ZKBarrierHandler method initialize.

/**
 * initialize ZKBarrierHandler,
 * create znode children caches for job master to watch barrier events
 */
public void initialize(JobMasterAPI.JobMasterState initialState) throws Twister2Exception {
    if (!(initialState == JobMasterAPI.JobMasterState.JM_STARTED || initialState == JobMasterAPI.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 == JobMasterAPI.JobMasterState.JM_RESTARTED) {
            // do not get previous events on barriers
            // get current snapshots of both barriers at the restart
            String defaultBarrierDir = ZKUtils.defaultBarrierDir(rootPath, jobID);
            defaultBarrierCache = new PathChildrenCache(client, defaultBarrierDir, true);
            addBarrierChildrenCacheListener(defaultBarrierCache, JobMasterAPI.BarrierType.DEFAULT);
            defaultBarrierCache.start(PathChildrenCache.StartMode.BUILD_INITIAL_CACHE);
            TreeSet<Integer> existingWorkers = new TreeSet<>();
            long timeout = getInitialWorkersAtBarrier(defaultBarrierCache, existingWorkers);
            if (!existingWorkers.isEmpty()) {
                barrierMonitor.initDefaultAfterRestart(existingWorkers, timeout, numberOfWorkers);
                LOG.info("Existing workers at default barrier: " + existingWorkers.size());
                existingWorkers.clear();
            }
            // do not get previous events on barriers
            // get current snapshots of both barriers at restart
            String initBarrierDir = ZKUtils.initBarrierDir(rootPath, jobID);
            initBarrierCache = new PathChildrenCache(client, initBarrierDir, true);
            addBarrierChildrenCacheListener(initBarrierCache, JobMasterAPI.BarrierType.INIT);
            initBarrierCache.start(PathChildrenCache.StartMode.BUILD_INITIAL_CACHE);
            timeout = getInitialWorkersAtBarrier(initBarrierCache, existingWorkers);
            if (!existingWorkers.isEmpty()) {
                barrierMonitor.initInitAfterRestart(existingWorkers, timeout, numberOfWorkers);
                LOG.info("Existing workers at init barrier: " + existingWorkers);
            }
        } else {
            // We listen for status updates for the default barrier path
            String defaultBarrierDir = ZKUtils.defaultBarrierDir(rootPath, jobID);
            defaultBarrierCache = new PathChildrenCache(client, defaultBarrierDir, true);
            addBarrierChildrenCacheListener(defaultBarrierCache, JobMasterAPI.BarrierType.DEFAULT);
            defaultBarrierCache.start();
            // We listen for status updates for the init barrier path
            String initBarrierDir = ZKUtils.initBarrierDir(rootPath, jobID);
            initBarrierCache = new PathChildrenCache(client, initBarrierDir, true);
            addBarrierChildrenCacheListener(initBarrierCache, JobMasterAPI.BarrierType.INIT);
            initBarrierCache.start();
        }
    } catch (Twister2Exception e) {
        throw e;
    } catch (Exception e) {
        throw new Twister2Exception("Exception when initializing ZKMasterController.", e);
    }
}
Also used : Twister2Exception(edu.iu.dsc.tws.api.exceptions.Twister2Exception) PathChildrenCache(org.apache.curator.framework.recipes.cache.PathChildrenCache) TreeSet(java.util.TreeSet) Twister2RuntimeException(edu.iu.dsc.tws.api.exceptions.Twister2RuntimeException) Twister2Exception(edu.iu.dsc.tws.api.exceptions.Twister2Exception)

Aggregations

PathChildrenCache (org.apache.curator.framework.recipes.cache.PathChildrenCache)73 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)11 AtomicReference (java.util.concurrent.atomic.AtomicReference)8 ChildData (org.apache.curator.framework.recipes.cache.ChildData)8 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