Search in sources :

Example 1 with LedgerMetadata

use of org.apache.bookkeeper.client.LedgerMetadata in project distributedlog by twitter.

the class TestAsyncReaderWriter method testCreateLogStreamWithDifferentReplicationFactor.

@Test(timeout = 60000)
public void testCreateLogStreamWithDifferentReplicationFactor() throws Exception {
    String name = runtime.getMethodName();
    DistributedLogConfiguration confLocal = new DistributedLogConfiguration();
    confLocal.addConfiguration(testConf);
    confLocal.setOutputBufferSize(0);
    confLocal.setImmediateFlushEnabled(false);
    confLocal.setPeriodicFlushFrequencyMilliSeconds(0);
    ConcurrentBaseConfiguration baseConf = new ConcurrentConstConfiguration(confLocal);
    DynamicDistributedLogConfiguration dynConf = new DynamicDistributedLogConfiguration(baseConf);
    dynConf.setProperty(DistributedLogConfiguration.BKDL_BOOKKEEPER_ENSEMBLE_SIZE, DistributedLogConfiguration.BKDL_BOOKKEEPER_ENSEMBLE_SIZE_DEFAULT - 1);
    URI uri = createDLMURI("/" + name);
    ensureURICreated(uri);
    DistributedLogNamespace namespace = DistributedLogNamespaceBuilder.newBuilder().conf(confLocal).uri(uri).build();
    // use the pool
    DistributedLogManager dlm = namespace.openLog(name + "-pool");
    AsyncLogWriter writer = dlm.startAsyncLogSegmentNonPartitioned();
    FutureUtils.result(writer.write(DLMTestUtil.getLogRecordInstance(1L)));
    List<LogSegmentMetadata> segments = dlm.getLogSegments();
    assertEquals(1, segments.size());
    long ledgerId = segments.get(0).getLedgerId();
    LedgerHandle lh = ((BKDistributedLogNamespace) namespace).getReaderBKC().get().openLedgerNoRecovery(ledgerId, BookKeeper.DigestType.CRC32, confLocal.getBKDigestPW().getBytes(UTF_8));
    LedgerMetadata metadata = BookKeeperAccessor.getLedgerMetadata(lh);
    assertEquals(DistributedLogConfiguration.BKDL_BOOKKEEPER_ENSEMBLE_SIZE_DEFAULT, metadata.getEnsembleSize());
    lh.close();
    Utils.close(writer);
    dlm.close();
    // use customized configuration
    dlm = namespace.openLog(name + "-custom", Optional.<DistributedLogConfiguration>absent(), Optional.of(dynConf));
    writer = dlm.startAsyncLogSegmentNonPartitioned();
    FutureUtils.result(writer.write(DLMTestUtil.getLogRecordInstance(1L)));
    segments = dlm.getLogSegments();
    assertEquals(1, segments.size());
    ledgerId = segments.get(0).getLedgerId();
    lh = ((BKDistributedLogNamespace) namespace).getReaderBKC().get().openLedgerNoRecovery(ledgerId, BookKeeper.DigestType.CRC32, confLocal.getBKDigestPW().getBytes(UTF_8));
    metadata = BookKeeperAccessor.getLedgerMetadata(lh);
    assertEquals(DistributedLogConfiguration.BKDL_BOOKKEEPER_ENSEMBLE_SIZE_DEFAULT - 1, metadata.getEnsembleSize());
    lh.close();
    Utils.close(writer);
    dlm.close();
    namespace.close();
}
Also used : LedgerHandle(org.apache.bookkeeper.client.LedgerHandle) DistributedLogNamespace(com.twitter.distributedlog.namespace.DistributedLogNamespace) ConcurrentConstConfiguration(com.twitter.distributedlog.config.ConcurrentConstConfiguration) DynamicDistributedLogConfiguration(com.twitter.distributedlog.config.DynamicDistributedLogConfiguration) URI(java.net.URI) ConcurrentBaseConfiguration(com.twitter.distributedlog.config.ConcurrentBaseConfiguration) DynamicDistributedLogConfiguration(com.twitter.distributedlog.config.DynamicDistributedLogConfiguration) LedgerMetadata(org.apache.bookkeeper.client.LedgerMetadata) Test(org.junit.Test)

Example 2 with LedgerMetadata

use of org.apache.bookkeeper.client.LedgerMetadata in project distributedlog by twitter.

the class DistributedLogInputFormat method getSplits.

@Override
public List<InputSplit> getSplits(JobContext jobContext) throws IOException, InterruptedException {
    List<LogSegmentMetadata> segments = dlm.getLogSegments();
    List<InputSplit> inputSplits = Lists.newArrayListWithCapacity(segments.size());
    BookKeeper bk = namespace.getReaderBKC().get();
    LedgerManager lm = BookKeeperAccessor.getLedgerManager(bk);
    final AtomicInteger rcHolder = new AtomicInteger(0);
    final AtomicReference<LedgerMetadata> metadataHolder = new AtomicReference<LedgerMetadata>(null);
    for (LogSegmentMetadata segment : segments) {
        final CountDownLatch latch = new CountDownLatch(1);
        lm.readLedgerMetadata(segment.getLedgerId(), new BookkeeperInternalCallbacks.GenericCallback<LedgerMetadata>() {

            @Override
            public void operationComplete(int rc, LedgerMetadata ledgerMetadata) {
                metadataHolder.set(ledgerMetadata);
                rcHolder.set(rc);
                latch.countDown();
            }
        });
        latch.await();
        if (BKException.Code.OK != rcHolder.get()) {
            throw new IOException("Faild to get log segment metadata for " + segment + " : " + BKException.getMessage(rcHolder.get()));
        }
        inputSplits.add(new LogSegmentSplit(segment, metadataHolder.get()));
    }
    return inputSplits;
}
Also used : LedgerManager(org.apache.bookkeeper.meta.LedgerManager) LogSegmentMetadata(com.twitter.distributedlog.LogSegmentMetadata) BookKeeper(org.apache.bookkeeper.client.BookKeeper) AtomicReference(java.util.concurrent.atomic.AtomicReference) IOException(java.io.IOException) CountDownLatch(java.util.concurrent.CountDownLatch) LedgerMetadata(org.apache.bookkeeper.client.LedgerMetadata) BookkeeperInternalCallbacks(org.apache.bookkeeper.proto.BookkeeperInternalCallbacks) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) InputSplit(org.apache.hadoop.mapreduce.InputSplit)

Aggregations

LedgerMetadata (org.apache.bookkeeper.client.LedgerMetadata)2 LogSegmentMetadata (com.twitter.distributedlog.LogSegmentMetadata)1 ConcurrentBaseConfiguration (com.twitter.distributedlog.config.ConcurrentBaseConfiguration)1 ConcurrentConstConfiguration (com.twitter.distributedlog.config.ConcurrentConstConfiguration)1 DynamicDistributedLogConfiguration (com.twitter.distributedlog.config.DynamicDistributedLogConfiguration)1 DistributedLogNamespace (com.twitter.distributedlog.namespace.DistributedLogNamespace)1 IOException (java.io.IOException)1 URI (java.net.URI)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 BookKeeper (org.apache.bookkeeper.client.BookKeeper)1 LedgerHandle (org.apache.bookkeeper.client.LedgerHandle)1 LedgerManager (org.apache.bookkeeper.meta.LedgerManager)1 BookkeeperInternalCallbacks (org.apache.bookkeeper.proto.BookkeeperInternalCallbacks)1 InputSplit (org.apache.hadoop.mapreduce.InputSplit)1 Test (org.junit.Test)1