Search in sources :

Example 1 with BKDLConfig

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;
}
Also used : BKDLConfig(org.apache.distributedlog.impl.metadata.BKDLConfig) URI(java.net.URI)

Example 2 with 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();
    }
}
Also used : ZooKeeperClient(org.apache.distributedlog.ZooKeeperClient) BookKeeperClient(org.apache.distributedlog.BookKeeperClient) ExecutorService(java.util.concurrent.ExecutorService) BKDLConfig(org.apache.distributedlog.impl.metadata.BKDLConfig) BoundExponentialBackoffRetryPolicy(org.apache.bookkeeper.zookeeper.BoundExponentialBackoffRetryPolicy) URI(java.net.URI) RetryPolicy(org.apache.bookkeeper.zookeeper.RetryPolicy) BoundExponentialBackoffRetryPolicy(org.apache.bookkeeper.zookeeper.BoundExponentialBackoffRetryPolicy)

Example 3 with BKDLConfig

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();
    }
}
Also used : ZooKeeperClient(org.apache.distributedlog.ZooKeeperClient) BookKeeperClient(org.apache.distributedlog.BookKeeperClient) ExecutorService(java.util.concurrent.ExecutorService) AtomicLong(java.util.concurrent.atomic.AtomicLong) BKDLConfig(org.apache.distributedlog.impl.metadata.BKDLConfig) BoundExponentialBackoffRetryPolicy(org.apache.bookkeeper.zookeeper.BoundExponentialBackoffRetryPolicy) RetryPolicy(org.apache.bookkeeper.zookeeper.RetryPolicy) BoundExponentialBackoffRetryPolicy(org.apache.bookkeeper.zookeeper.BoundExponentialBackoffRetryPolicy)

Example 4 with BKDLConfig

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;
}
Also used : ZKException(org.apache.distributedlog.exceptions.ZKException) BKDLConfig(org.apache.distributedlog.impl.metadata.BKDLConfig) DLMetadata(org.apache.distributedlog.metadata.DLMetadata) URI(java.net.URI)

Example 5 with BKDLConfig

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;
}
Also used : ZKException(org.apache.distributedlog.exceptions.ZKException) BKDLConfig(org.apache.distributedlog.impl.metadata.BKDLConfig) DLMetadata(org.apache.distributedlog.metadata.DLMetadata)

Aggregations

BKDLConfig (org.apache.distributedlog.impl.metadata.BKDLConfig)9 URI (java.net.URI)6 IOException (java.io.IOException)2 ExecutorService (java.util.concurrent.ExecutorService)2 BoundExponentialBackoffRetryPolicy (org.apache.bookkeeper.zookeeper.BoundExponentialBackoffRetryPolicy)2 RetryPolicy (org.apache.bookkeeper.zookeeper.RetryPolicy)2 BookKeeperClient (org.apache.distributedlog.BookKeeperClient)2 ZooKeeperClient (org.apache.distributedlog.ZooKeeperClient)2 ZKException (org.apache.distributedlog.exceptions.ZKException)2 DLMetadata (org.apache.distributedlog.metadata.DLMetadata)2 Stat (org.apache.zookeeper.data.Stat)2 BufferedReader (java.io.BufferedReader)1 StringReader (java.io.StringReader)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 Before (org.junit.Before)1 Test (org.junit.Test)1