use of org.apache.curator.retry.ExponentialBackoffRetry in project alluxio by Alluxio.
the class ZkMasterInquireClientTest method testSingleLeader.
@Test
public void testSingleLeader() throws Exception {
// Create zk inquire client.
MasterInquireClient zkInquirer = ZkMasterInquireClient.getClient(mZkServer.getConnectString(), ELECTION_PATH, LEADER_PATH, INQUIRE_RETRY_COUNT, ZOOKEEPER_AUTH_ENABLED);
// Create curator client for manipulating the leader path.
CuratorFramework client = CuratorFrameworkFactory.newClient(mZkServer.getConnectString(), new ExponentialBackoffRetry(Constants.SECOND_MS, INQUIRE_RETRY_COUNT));
// Create the leader path with single(localhost) participant.
InetSocketAddress localLeader = InetSocketAddress.createUnresolved(LOOPBACK_IP, 12345);
client.start();
client.create().forPath(LEADER_PATH);
client.create().forPath(PathUtils.concatPath(LEADER_PATH, localLeader));
client.close();
// Verify that leader is fetched.
Assert.assertEquals(localLeader, zkInquirer.getPrimaryRpcAddress());
}
use of org.apache.curator.retry.ExponentialBackoffRetry in project druid by druid-io.
the class BatchServerInventoryViewTest method setUp.
@Before
public void setUp() throws Exception {
testingCluster = new TestingCluster(1);
testingCluster.start();
cf = CuratorFrameworkFactory.builder().connectString(testingCluster.getConnectString()).retryPolicy(new ExponentialBackoffRetry(1, 10)).compressionProvider(new PotentiallyGzippedCompressionProvider(true)).build();
cf.start();
cf.blockUntilConnected();
cf.create().creatingParentsIfNeeded().forPath(TEST_BASE_PATH);
jsonMapper = TestHelper.makeJsonMapper();
announcer = new Announcer(cf, Execs.directExecutor());
announcer.start();
DruidServerMetadata serverMetadata = new DruidServerMetadata("id", "host", null, Long.MAX_VALUE, ServerType.HISTORICAL, "tier", 0);
ZkPathsConfig zkPathsConfig = new ZkPathsConfig() {
@Override
public String getBase() {
return TEST_BASE_PATH;
}
};
serverAnnouncer = new CuratorDataSegmentServerAnnouncer(serverMetadata, zkPathsConfig, announcer, jsonMapper);
serverAnnouncer.announce();
segmentAnnouncer = new BatchDataSegmentAnnouncer(serverMetadata, new BatchDataSegmentAnnouncerConfig() {
@Override
public int getSegmentsPerNode() {
return 50;
}
}, zkPathsConfig, announcer, jsonMapper);
testSegments = Sets.newConcurrentHashSet();
for (int i = 0; i < INITIAL_SEGMENTS; i++) {
testSegments.add(makeSegment(i));
}
batchServerInventoryView = new BatchServerInventoryView(new ZkPathsConfig() {
@Override
public String getBase() {
return TEST_BASE_PATH;
}
}, cf, jsonMapper, Predicates.alwaysTrue(), "test");
batchServerInventoryView.start();
inventoryUpdateCounter.set(0);
filteredBatchServerInventoryView = new BatchServerInventoryView(new ZkPathsConfig() {
@Override
public String getBase() {
return TEST_BASE_PATH;
}
}, cf, jsonMapper, new Predicate<Pair<DruidServerMetadata, DataSegment>>() {
@Override
public boolean apply(@Nullable Pair<DruidServerMetadata, DataSegment> input) {
return input.rhs.getInterval().getStart().isBefore(SEGMENT_INTERVAL_START.plusDays(INITIAL_SEGMENTS));
}
}, "test") {
@Override
protected DruidServer addInnerInventory(DruidServer container, String inventoryKey, Set<DataSegment> inventory) {
DruidServer server = super.addInnerInventory(container, inventoryKey, inventory);
inventoryUpdateCounter.incrementAndGet();
return server;
}
};
filteredBatchServerInventoryView.start();
}
use of org.apache.curator.retry.ExponentialBackoffRetry in project druid by druid-io.
the class RemoteTaskRunnerTestUtils method setUp.
void setUp() throws Exception {
testingCluster = new TestingCluster(1);
testingCluster.start();
cf = CuratorFrameworkFactory.builder().connectString(testingCluster.getConnectString()).retryPolicy(new ExponentialBackoffRetry(1, 10)).compressionProvider(new PotentiallyGzippedCompressionProvider(false)).build();
cf.start();
cf.blockUntilConnected();
cf.create().creatingParentsIfNeeded().forPath(BASE_PATH);
cf.create().creatingParentsIfNeeded().forPath(TASKS_PATH);
}
use of org.apache.curator.retry.ExponentialBackoffRetry in project druid by druid-io.
the class WorkerResourceTest method setUp.
@Before
public void setUp() throws Exception {
testingCluster = new TestingCluster(1);
testingCluster.start();
cf = CuratorFrameworkFactory.builder().connectString(testingCluster.getConnectString()).retryPolicy(new ExponentialBackoffRetry(1, 10)).compressionProvider(new PotentiallyGzippedCompressionProvider(false)).build();
cf.start();
cf.blockUntilConnected();
cf.create().creatingParentsIfNeeded().forPath(BASE_PATH);
worker = new Worker("http", "host", "ip", 3, "v1", WorkerConfig.DEFAULT_CATEGORY);
curatorCoordinator = new WorkerCuratorCoordinator(JSON_MAPPER, new IndexerZkConfig(new ZkPathsConfig() {
@Override
public String getBase() {
return BASE_PATH;
}
}, null, null, null, null), new RemoteTaskRunnerConfig(), cf, worker);
curatorCoordinator.start();
workerResource = new WorkerResource(worker, () -> curatorCoordinator, null, EasyMock.createNiceMock(WorkerTaskMonitor.class), ZkEnablementConfig.ENABLED);
}
use of org.apache.curator.retry.ExponentialBackoffRetry in project Mycat-Server by MyCATApache.
the class DistributedSequenceHandler method initializeZK.
public void initializeZK(String zkAddress) {
this.client = CuratorFrameworkFactory.newClient(zkAddress, new ExponentialBackoffRetry(1000, 3));
this.client.start();
try {
if (client.checkExists().forPath(PATH.concat(INSTANCE_PATH)) == null) {
client.create().creatingParentContainersIfNeeded().forPath(PATH.concat(INSTANCE_PATH));
}
} catch (Exception e) {
// do nothing
}
this.leaderSelector = new LeaderSelector(client, PATH.concat(LEADER_PATH), this);
this.leaderSelector.autoRequeue();
this.leaderSelector.start();
Runnable runnable = new Runnable() {
@Override
public void run() {
try {
while (leaderSelector.getLeader() == null) {
Thread.currentThread().yield();
}
if (!leaderSelector.hasLeadership()) {
isLeader = false;
if (slavePath != null && client.checkExists().forPath(slavePath) != null) {
return;
}
slavePath = client.create().creatingParentsIfNeeded().withMode(CreateMode.EPHEMERAL_SEQUENTIAL).forPath(PATH.concat("/instance/node"), "ready".getBytes());
while ("ready".equals(new String(client.getData().forPath(slavePath)))) {
Thread.currentThread().yield();
}
instanceId = Long.parseLong(new String(client.getData().forPath(slavePath)));
ready = true;
}
} catch (Exception e) {
LOGGER.warn("Caught exception while handling zk!", e);
}
}
};
timerExecutor.scheduleAtFixedRate(runnable, 1L, 10L, TimeUnit.SECONDS);
}
Aggregations