use of org.apache.distributedlog.impl.metadata.BKDLConfig in project bookkeeper by apache.
the class DLAuditor method resolveBKDLConfig.
private BKDLConfig resolveBKDLConfig(ZooKeeperClient zkc, List<URI> uris) throws IOException {
URI firstURI = uris.get(0);
BKDLConfig bkdlConfig = BKDLConfig.resolveDLConfig(zkc, firstURI);
for (URI uri : uris) {
BKDLConfig anotherConfig = BKDLConfig.resolveDLConfig(zkc, uri);
if (!(Objects.equal(bkdlConfig.getBkLedgersPath(), anotherConfig.getBkLedgersPath()) && Objects.equal(bkdlConfig.getBkZkServersForWriter(), anotherConfig.getBkZkServersForWriter()))) {
throw new IllegalArgumentException("Uris don't use same bookkeeper cluster");
}
}
return bkdlConfig;
}
use of org.apache.distributedlog.impl.metadata.BKDLConfig 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.impl.metadata.BKDLConfig 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.impl.metadata.BKDLConfig in project incubator-pulsar by apache.
the class Utils method initializeDlogNamespace.
public static URI initializeDlogNamespace(String zkServers, String ledgersRootPath) throws IOException {
BKDLConfig dlConfig = new BKDLConfig(zkServers, ledgersRootPath);
DLMetadata dlMetadata = DLMetadata.create(dlConfig);
URI dlogUri = URI.create(String.format("distributedlog://%s/pulsar/functions", zkServers));
try {
dlMetadata.create(dlogUri);
} catch (ZKException e) {
if (e.getKeeperExceptionCode() == Code.NODEEXISTS) {
return dlogUri;
}
throw e;
}
return dlogUri;
}
use of org.apache.distributedlog.impl.metadata.BKDLConfig in project bookkeeper by apache.
the class DLNamespaceProviderService method initializeNamespace.
private static URI initializeNamespace(ServerConfiguration bkServerConf, URI dlogUri) throws IOException {
BKDLConfig dlConfig = new BKDLConfig(bkServerConf.getZkServers(), bkServerConf.getZkLedgersRootPath());
DLMetadata dlMetadata = DLMetadata.create(dlConfig);
try {
log.info("Initializing dlog namespace at {}", dlogUri);
dlMetadata.create(dlogUri);
log.info("Initialized dlog namespace at {}", dlogUri);
} catch (ZKException e) {
if (e.getKeeperExceptionCode() == Code.NODEEXISTS) {
if (log.isDebugEnabled()) {
log.debug("Dlog uri is already bound at {}", dlogUri);
}
return dlogUri;
}
log.error("Failed to initialize dlog namespace at {}", dlogUri, e);
throw e;
}
return dlogUri;
}
Aggregations