use of org.apache.distributedlog.ZooKeeperClient in project bookkeeper by apache.
the class DLAuditor method calculateLedgerSpaceUsage.
public long calculateLedgerSpaceUsage(URI uri) throws IOException {
List<URI> uris = Lists.newArrayList(uri);
String zkServers = validateAndGetZKServers(uris);
RetryPolicy retryPolicy = new BoundExponentialBackoffRetryPolicy(conf.getZKRetryBackoffStartMillis(), conf.getZKRetryBackoffMaxMillis(), Integer.MAX_VALUE);
ZooKeeperClient zkc = ZooKeeperClientBuilder.newBuilder().name("DLAuditor-ZK").zkServers(zkServers).sessionTimeoutMs(conf.getZKSessionTimeoutMilliseconds()).retryPolicy(retryPolicy).zkAclId(conf.getZkAclId()).build();
ExecutorService executorService = Executors.newCachedThreadPool();
try {
BKDLConfig bkdlConfig = resolveBKDLConfig(zkc, uris);
logger.info("Resolved bookkeeper config : {}", bkdlConfig);
BookKeeperClient bkc = BookKeeperClientBuilder.newBuilder().name("DLAuditor-BK").dlConfig(conf).zkServers(bkdlConfig.getBkZkServersForWriter()).ledgersPath(bkdlConfig.getBkLedgersPath()).build();
try {
return calculateLedgerSpaceUsage(bkc, executorService);
} finally {
bkc.close();
}
} finally {
zkc.close();
executorService.shutdown();
}
}
use of org.apache.distributedlog.ZooKeeperClient in project bookkeeper by apache.
the class DLAuditor method collectLedgers.
public Pair<Set<Long>, Set<Long>> collectLedgers(List<URI> uris, List<List<String>> allocationPaths) throws IOException {
checkArgument(uris.size() > 0, "No uri provided to audit");
String zkServers = validateAndGetZKServers(uris);
RetryPolicy retryPolicy = new BoundExponentialBackoffRetryPolicy(conf.getZKRetryBackoffStartMillis(), conf.getZKRetryBackoffMaxMillis(), Integer.MAX_VALUE);
ZooKeeperClient zkc = ZooKeeperClientBuilder.newBuilder().name("DLAuditor-ZK").zkServers(zkServers).sessionTimeoutMs(conf.getZKSessionTimeoutMilliseconds()).retryPolicy(retryPolicy).zkAclId(conf.getZkAclId()).build();
ExecutorService executorService = Executors.newCachedThreadPool();
try {
BKDLConfig bkdlConfig = resolveBKDLConfig(zkc, uris);
logger.info("Resolved bookkeeper config : {}", bkdlConfig);
BookKeeperClient bkc = BookKeeperClientBuilder.newBuilder().name("DLAuditor-BK").dlConfig(conf).zkServers(bkdlConfig.getBkZkServersForWriter()).ledgersPath(bkdlConfig.getBkLedgersPath()).build();
try {
Set<Long> bkLedgers = collectLedgersFromBK(bkc, executorService);
Set<Long> dlLedgers = collectLedgersFromDL(uris, allocationPaths);
return Pair.of(bkLedgers, dlLedgers);
} finally {
bkc.close();
}
} finally {
zkc.close();
executorService.shutdown();
}
}
use of org.apache.distributedlog.ZooKeeperClient in project bookkeeper by apache.
the class DLMetadata method create.
public void create(URI uri) throws IOException {
DistributedLogConfiguration conf = new DistributedLogConfiguration();
ZooKeeperClient zkc = ZooKeeperClientBuilder.newBuilder().sessionTimeoutMs(conf.getZKSessionTimeoutMilliseconds()).retryThreadCount(conf.getZKClientNumberRetryThreads()).requestRateLimit(conf.getZKRequestRateLimit()).zkAclId(conf.getZkAclId()).uri(uri).build();
byte[] data = serialize();
try {
Utils.zkCreateFullPathOptimistic(zkc, uri.getPath(), data, zkc.getDefaultACL(), CreateMode.PERSISTENT);
} catch (KeeperException ke) {
throw new ZKException("Encountered zookeeper exception on creating dl metadata", ke);
} finally {
zkc.close();
}
}
use of org.apache.distributedlog.ZooKeeperClient in project bookkeeper by apache.
the class DLMetadata method update.
public void update(URI uri) throws IOException {
DistributedLogConfiguration conf = new DistributedLogConfiguration();
ZooKeeperClient zkc = ZooKeeperClientBuilder.newBuilder().sessionTimeoutMs(conf.getZKSessionTimeoutMilliseconds()).retryThreadCount(conf.getZKClientNumberRetryThreads()).requestRateLimit(conf.getZKRequestRateLimit()).zkAclId(conf.getZkAclId()).uri(uri).build();
byte[] data = serialize();
try {
zkc.get().setData(uri.getPath(), data, -1);
} catch (KeeperException e) {
throw new IOException("Fail to update dl metadata " + new String(data, UTF_8) + " to uri " + uri, e);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new IOException("Interrupted when updating dl metadata " + new String(data, UTF_8) + " to uri " + uri, e);
} finally {
zkc.close();
}
}
use of org.apache.distributedlog.ZooKeeperClient in project bookkeeper by apache.
the class DLMetadata method unbind.
public static void unbind(URI uri) throws IOException {
DistributedLogConfiguration conf = new DistributedLogConfiguration();
ZooKeeperClient zkc = ZooKeeperClientBuilder.newBuilder().sessionTimeoutMs(conf.getZKSessionTimeoutMilliseconds()).retryThreadCount(conf.getZKClientNumberRetryThreads()).requestRateLimit(conf.getZKRequestRateLimit()).zkAclId(conf.getZkAclId()).uri(uri).build();
byte[] data = new byte[0];
try {
zkc.get().setData(uri.getPath(), data, -1);
} catch (KeeperException ke) {
throw new IOException("Fail to unbound dl metadata on uri " + uri, ke);
} catch (InterruptedException ie) {
Thread.currentThread().interrupt();
throw new IOException("Interrupted when unbinding dl metadata on uri " + uri, ie);
} finally {
zkc.close();
}
}
Aggregations