Search in sources :

Example 1 with DistributedLogConfiguration

use of org.apache.distributedlog.DistributedLogConfiguration 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();
    }
}
Also used : DistributedLogConfiguration(org.apache.distributedlog.DistributedLogConfiguration) ZKException(org.apache.distributedlog.exceptions.ZKException) ZooKeeperClient(org.apache.distributedlog.ZooKeeperClient) KeeperException(org.apache.zookeeper.KeeperException)

Example 2 with DistributedLogConfiguration

use of org.apache.distributedlog.DistributedLogConfiguration 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();
    }
}
Also used : DistributedLogConfiguration(org.apache.distributedlog.DistributedLogConfiguration) ZooKeeperClient(org.apache.distributedlog.ZooKeeperClient) IOException(java.io.IOException) KeeperException(org.apache.zookeeper.KeeperException)

Example 3 with DistributedLogConfiguration

use of org.apache.distributedlog.DistributedLogConfiguration 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();
    }
}
Also used : DistributedLogConfiguration(org.apache.distributedlog.DistributedLogConfiguration) ZooKeeperClient(org.apache.distributedlog.ZooKeeperClient) IOException(java.io.IOException) KeeperException(org.apache.zookeeper.KeeperException)

Example 4 with DistributedLogConfiguration

use of org.apache.distributedlog.DistributedLogConfiguration in project bookkeeper by apache.

the class AbstractFeatureProvider method getFeatureProvider.

public static FeatureProvider getFeatureProvider(String rootScope, DistributedLogConfiguration conf, StatsLogger statsLogger) throws IOException {
    Class<? extends FeatureProvider> featureProviderClass;
    try {
        featureProviderClass = conf.getFeatureProviderClass();
    } catch (ConfigurationException e) {
        throw new IOException("Can't initialize the feature provider : ", e);
    }
    // create feature provider
    Constructor<? extends FeatureProvider> constructor;
    try {
        constructor = featureProviderClass.getDeclaredConstructor(String.class, DistributedLogConfiguration.class, StatsLogger.class);
    } catch (NoSuchMethodException e) {
        throw new IOException("No constructor found for feature provider class " + featureProviderClass + " : ", e);
    }
    try {
        return constructor.newInstance(rootScope, conf, statsLogger);
    } catch (InstantiationException e) {
        throw new IOException("Failed to instantiate feature provider : ", e);
    } catch (IllegalAccessException e) {
        throw new IOException("Encountered illegal access when instantiating feature provider : ", e);
    } catch (InvocationTargetException e) {
        Throwable targetException = e.getTargetException();
        if (targetException instanceof IOException) {
            throw (IOException) targetException;
        } else {
            throw new IOException("Encountered invocation target" + " exception while instantiating feature provider : ", e);
        }
    }
}
Also used : DistributedLogConfiguration(org.apache.distributedlog.DistributedLogConfiguration) StatsLogger(org.apache.bookkeeper.stats.StatsLogger) ConfigurationException(org.apache.commons.configuration.ConfigurationException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 5 with DistributedLogConfiguration

use of org.apache.distributedlog.DistributedLogConfiguration in project bookkeeper by apache.

the class TestBKLogSegmentEntryReader method testMaxPrefetchEntriesSmallBatch.

@Test(timeout = 60000)
public void testMaxPrefetchEntriesSmallBatch() throws Exception {
    DistributedLogConfiguration confLocal = new DistributedLogConfiguration();
    confLocal.addConfiguration(conf);
    confLocal.setOutputBufferSize(0);
    confLocal.setPeriodicFlushFrequencyMilliSeconds(0);
    confLocal.setImmediateFlushEnabled(false);
    confLocal.setNumPrefetchEntriesPerLogSegment(2);
    confLocal.setMaxPrefetchEntriesPerLogSegment(10);
    DistributedLogManager dlm = createNewDLM(confLocal, runtime.getMethodName());
    generateCompletedLogSegments(dlm, confLocal, 1, 20);
    List<LogSegmentMetadata> segments = dlm.getLogSegments();
    assertEquals(segments.size() + " log segments found, expected to be only one", 1, segments.size());
    BKLogSegmentEntryReader reader = createEntryReader(segments.get(0), 0, confLocal);
    reader.start();
    // wait for the read ahead entries to become available
    while (reader.readAheadEntries.size() < 10) {
        TimeUnit.MILLISECONDS.sleep(10);
    }
    long txId = 1L;
    long entryId = 0L;
    assertEquals(10, reader.readAheadEntries.size());
    assertEquals(10, reader.getNextEntryId());
    assertFalse(reader.hasCaughtUpOnInprogress());
    // read first entry
    Entry.Reader entryReader = Utils.ioResult(reader.readNext(1)).get(0);
    LogRecordWithDLSN record = entryReader.nextRecord();
    while (null != record) {
        if (!record.isControl()) {
            DLMTestUtil.verifyLogRecord(record);
            assertEquals(txId, record.getTransactionId());
            ++txId;
        }
        DLSN dlsn = record.getDlsn();
        assertEquals(1L, dlsn.getLogSegmentSequenceNo());
        assertEquals(entryId, dlsn.getEntryId());
        record = entryReader.nextRecord();
    }
    ++entryId;
    assertEquals(2L, txId);
    // wait for the read ahead entries to become 10 again
    while (reader.readAheadEntries.size() < 10) {
        TimeUnit.MILLISECONDS.sleep(10);
    }
    assertEquals(10, reader.readAheadEntries.size());
    assertEquals(11, reader.getNextEntryId());
    assertFalse(reader.hasCaughtUpOnInprogress());
    Utils.close(reader);
}
Also used : DistributedLogConfiguration(org.apache.distributedlog.DistributedLogConfiguration) Entry(org.apache.distributedlog.Entry) LogRecordWithDLSN(org.apache.distributedlog.LogRecordWithDLSN) LogRecordWithDLSN(org.apache.distributedlog.LogRecordWithDLSN) DLSN(org.apache.distributedlog.DLSN) DistributedLogManager(org.apache.distributedlog.api.DistributedLogManager) LogSegmentMetadata(org.apache.distributedlog.LogSegmentMetadata) Test(org.junit.Test)

Aggregations

DistributedLogConfiguration (org.apache.distributedlog.DistributedLogConfiguration)39 Test (org.junit.Test)25 URI (java.net.URI)10 DistributedLogManager (org.apache.distributedlog.api.DistributedLogManager)10 DLSN (org.apache.distributedlog.DLSN)9 LogRecordWithDLSN (org.apache.distributedlog.LogRecordWithDLSN)8 LogSegmentMetadata (org.apache.distributedlog.LogSegmentMetadata)8 Entry (org.apache.distributedlog.Entry)7 IOException (java.io.IOException)6 ZooKeeperClient (org.apache.distributedlog.ZooKeeperClient)5 Before (org.junit.Before)4 List (java.util.List)3 Feature (org.apache.bookkeeper.feature.Feature)3 Namespace (org.apache.distributedlog.api.namespace.Namespace)3 KeeperException (org.apache.zookeeper.KeeperException)3 Set (java.util.Set)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 AsyncLogWriter (org.apache.distributedlog.api.AsyncLogWriter)2