Search in sources :

Example 1 with ZooKeeperClient

use of com.twitter.distributedlog.ZooKeeperClient in project distributedlog by twitter.

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 e) {
        throw new IOException("Fail to write dl metadata " + new String(data, UTF_8) + " to uri " + uri, e);
    } catch (InterruptedException e) {
        throw new IOException("Interrupted when writing dl metadata " + new String(data, UTF_8) + " to uri " + uri, e);
    } finally {
        zkc.close();
    }
}
Also used : DistributedLogConfiguration(com.twitter.distributedlog.DistributedLogConfiguration) ZooKeeperClient(com.twitter.distributedlog.ZooKeeperClient) IOException(java.io.IOException) KeeperException(org.apache.zookeeper.KeeperException)

Example 2 with ZooKeeperClient

use of com.twitter.distributedlog.ZooKeeperClient in project distributedlog by twitter.

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) {
        throw new IOException("Interrupted when unbinding dl metadata on uri " + uri, ie);
    } finally {
        zkc.close();
    }
}
Also used : DistributedLogConfiguration(com.twitter.distributedlog.DistributedLogConfiguration) ZooKeeperClient(com.twitter.distributedlog.ZooKeeperClient) IOException(java.io.IOException) KeeperException(org.apache.zookeeper.KeeperException)

Example 3 with ZooKeeperClient

use of com.twitter.distributedlog.ZooKeeperClient in project distributedlog by twitter.

the class TestDistributedLogServer method testRequestDenied.

@Test(timeout = 60000)
public void testRequestDenied() throws Exception {
    String name = "request-denied";
    dlClient.routingService.addHost(name, dlServer.getAddress());
    AccessControlEntry ace = new AccessControlEntry();
    ace.setDenyWrite(true);
    ZooKeeperClient zkc = TestZooKeeperClientBuilder.newBuilder().uri(getUri()).connectionTimeoutMs(60000).sessionTimeoutMs(60000).build();
    DistributedLogNamespace dlNamespace = dlServer.dlServer.getLeft().getDistributedLogNamespace();
    BKDLConfig bkdlConfig = BKDLConfig.resolveDLConfig(zkc, getUri());
    String zkPath = getUri().getPath() + "/" + bkdlConfig.getACLRootPath() + "/" + name;
    ZKAccessControl accessControl = new ZKAccessControl(ace, zkPath);
    accessControl.create(zkc);
    AccessControlManager acm = dlNamespace.createAccessControlManager();
    while (acm.allowWrite(name)) {
        Thread.sleep(100);
    }
    try {
        Await.result(dlClient.dlClient.write(name, ByteBuffer.wrap("1".getBytes(UTF_8))));
        fail("Should fail with request denied exception");
    } catch (DLException dle) {
        assertEquals(StatusCode.REQUEST_DENIED, dle.getCode());
    }
}
Also used : AccessControlManager(com.twitter.distributedlog.acl.AccessControlManager) ZooKeeperClient(com.twitter.distributedlog.ZooKeeperClient) DistributedLogNamespace(com.twitter.distributedlog.namespace.DistributedLogNamespace) DLException(com.twitter.distributedlog.exceptions.DLException) AccessControlEntry(com.twitter.distributedlog.thrift.AccessControlEntry) BKDLConfig(com.twitter.distributedlog.metadata.BKDLConfig) ZKAccessControl(com.twitter.distributedlog.acl.ZKAccessControl) Test(org.junit.Test)

Example 4 with ZooKeeperClient

use of com.twitter.distributedlog.ZooKeeperClient in project distributedlog by twitter.

the class TestZKTransaction method testProcessNullResults.

@Test(timeout = 60000)
public void testProcessNullResults() throws Exception {
    ZooKeeperClient zkc = mock(ZooKeeperClient.class);
    ZKTransaction transaction = new ZKTransaction(zkc);
    int numOps = 3;
    final CountDownLatch commitLatch = new CountDownLatch(numOps);
    final CountDownLatch abortLatch = new CountDownLatch(numOps);
    for (int i = 0; i < numOps; i++) {
        transaction.addOp(new CountDownZKOp(commitLatch, abortLatch));
    }
    transaction.processResult(KeeperException.Code.CONNECTIONLOSS.intValue(), "test-path", null, null);
    abortLatch.await();
    assertEquals(0, abortLatch.getCount());
    assertEquals(numOps, commitLatch.getCount());
}
Also used : ZooKeeperClient(com.twitter.distributedlog.ZooKeeperClient) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 5 with ZooKeeperClient

use of com.twitter.distributedlog.ZooKeeperClient in project distributedlog by twitter.

the class TestFederatedZKLogMetadataStore method testCreateLog.

@Test(timeout = 60000)
public void testCreateLog() throws Exception {
    DistributedLogConfiguration conf = new DistributedLogConfiguration();
    conf.addConfiguration(baseConf);
    ZooKeeperClient anotherZkc = TestZooKeeperClientBuilder.newBuilder().uri(uri).sessionTimeoutMs(zkSessionTimeoutMs).build();
    FederatedZKLogMetadataStore anotherMetadataStore = new FederatedZKLogMetadataStore(conf, uri, anotherZkc, scheduler);
    for (int i = 0; i < 2 * maxLogsPerSubnamespace; i++) {
        LogMetadataStore createStore, checkStore;
        if (i % 2 == 0) {
            createStore = metadataStore;
            checkStore = anotherMetadataStore;
        } else {
            createStore = anotherMetadataStore;
            checkStore = metadataStore;
        }
        String logName = "test-create-log-" + i;
        URI logUri = FutureUtils.result(createStore.createLog(logName));
        Optional<URI> logLocation = FutureUtils.result(checkStore.getLogLocation(logName));
        assertTrue("Log " + logName + " doesn't exist", logLocation.isPresent());
        assertEquals("Different log location " + logLocation.get() + " is found", logUri, logLocation.get());
    }
    assertEquals(2, metadataStore.getSubnamespaces().size());
    assertEquals(2, anotherMetadataStore.getSubnamespaces().size());
}
Also used : DistributedLogConfiguration(com.twitter.distributedlog.DistributedLogConfiguration) LogMetadataStore(com.twitter.distributedlog.metadata.LogMetadataStore) ZooKeeperClient(com.twitter.distributedlog.ZooKeeperClient) URI(java.net.URI) Test(org.junit.Test)

Aggregations

ZooKeeperClient (com.twitter.distributedlog.ZooKeeperClient)12 DistributedLogConfiguration (com.twitter.distributedlog.DistributedLogConfiguration)5 Test (org.junit.Test)5 BKDLConfig (com.twitter.distributedlog.metadata.BKDLConfig)4 IOException (java.io.IOException)4 KeeperException (org.apache.zookeeper.KeeperException)3 BookKeeperClient (com.twitter.distributedlog.BookKeeperClient)2 URI (java.net.URI)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 ExecutorService (java.util.concurrent.ExecutorService)2 BoundExponentialBackoffRetryPolicy (org.apache.bookkeeper.zookeeper.BoundExponentialBackoffRetryPolicy)2 RetryPolicy (org.apache.bookkeeper.zookeeper.RetryPolicy)2 Stopwatch (com.google.common.base.Stopwatch)1 DistributedLogManager (com.twitter.distributedlog.DistributedLogManager)1 LogSegmentMetadata (com.twitter.distributedlog.LogSegmentMetadata)1 AccessControlManager (com.twitter.distributedlog.acl.AccessControlManager)1 ZKAccessControl (com.twitter.distributedlog.acl.ZKAccessControl)1 DLException (com.twitter.distributedlog.exceptions.DLException)1 DLIllegalStateException (com.twitter.distributedlog.exceptions.DLIllegalStateException)1 LogMetadataStore (com.twitter.distributedlog.metadata.LogMetadataStore)1