Search in sources :

Example 1 with BKNamespaceDriver

use of org.apache.distributedlog.impl.BKNamespaceDriver in project bookkeeper by apache.

the class TestBKDistributedLogManager method testDeleteLog.

@Test(timeout = 60000)
public void testDeleteLog() throws Exception {
    String name = "delete-log-should-delete-ledgers";
    DistributedLogManager dlm = createNewDLM(conf, name);
    long txid = 1;
    // Create the log and write some records
    BKSyncLogWriter writer = (BKSyncLogWriter) dlm.startLogSegmentNonPartitioned();
    for (long j = 1; j <= DEFAULT_SEGMENT_SIZE; j++) {
        writer.write(DLMTestUtil.getLogRecordInstance(txid++));
    }
    BKLogSegmentWriter perStreamLogWriter = writer.getCachedLogWriter();
    writer.closeAndComplete();
    BKLogWriteHandler blplm = ((BKDistributedLogManager) (dlm)).createWriteHandler(true);
    assertNotNull(zkc.exists(blplm.completedLedgerZNode(txid, txid - 1, perStreamLogWriter.getLogSegmentSequenceNumber()), false));
    Utils.ioResult(blplm.asyncClose());
    // Should be able to open the underline ledger using BK client
    long ledgerId = perStreamLogWriter.getLogSegmentId();
    BKNamespaceDriver driver = (BKNamespaceDriver) dlm.getNamespaceDriver();
    driver.getReaderBKC().get().openLedgerNoRecovery(ledgerId, BookKeeper.DigestType.CRC32, conf.getBKDigestPW().getBytes(UTF_8));
    // Delete the log and we shouldn't be able the open the ledger
    dlm.delete();
    try {
        driver.getReaderBKC().get().openLedgerNoRecovery(ledgerId, BookKeeper.DigestType.CRC32, conf.getBKDigestPW().getBytes(UTF_8));
        fail("Should fail to open ledger after we delete the log");
    } catch (BKException.BKNoSuchLedgerExistsException e) {
    // ignore
    }
    // delete again should not throw any exception
    try {
        dlm.delete();
    } catch (IOException ioe) {
        fail("Delete log twice should not throw any exception");
    }
}
Also used : DistributedLogManager(org.apache.distributedlog.api.DistributedLogManager) BKNamespaceDriver(org.apache.distributedlog.impl.BKNamespaceDriver) BKException(org.apache.bookkeeper.client.BKException) IOException(java.io.IOException) Test(org.junit.Test)

Example 2 with BKNamespaceDriver

use of org.apache.distributedlog.impl.BKNamespaceDriver in project bookkeeper by apache.

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);
    Namespace namespace = NamespaceBuilder.newBuilder().conf(confLocal).uri(uri).build();
    // use the pool
    DistributedLogManager dlm = namespace.openLog(name + "-pool");
    AsyncLogWriter writer = dlm.startAsyncLogSegmentNonPartitioned();
    Utils.ioResult(writer.write(DLMTestUtil.getLogRecordInstance(1L)));
    List<LogSegmentMetadata> segments = dlm.getLogSegments();
    assertEquals(1, segments.size());
    long ledgerId = segments.get(0).getLogSegmentId();
    LedgerHandle lh = ((BKNamespaceDriver) namespace.getNamespaceDriver()).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", java.util.Optional.empty(), java.util.Optional.of(dynConf), java.util.Optional.empty());
    writer = dlm.startAsyncLogSegmentNonPartitioned();
    Utils.ioResult(writer.write(DLMTestUtil.getLogRecordInstance(1L)));
    segments = dlm.getLogSegments();
    assertEquals(1, segments.size());
    ledgerId = segments.get(0).getLogSegmentId();
    lh = ((BKNamespaceDriver) namespace.getNamespaceDriver()).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) AsyncLogWriter(org.apache.distributedlog.api.AsyncLogWriter) ConcurrentConstConfiguration(org.apache.distributedlog.common.config.ConcurrentConstConfiguration) DynamicDistributedLogConfiguration(org.apache.distributedlog.config.DynamicDistributedLogConfiguration) URI(java.net.URI) Namespace(org.apache.distributedlog.api.namespace.Namespace) ConcurrentBaseConfiguration(org.apache.distributedlog.common.config.ConcurrentBaseConfiguration) DynamicDistributedLogConfiguration(org.apache.distributedlog.config.DynamicDistributedLogConfiguration) LedgerMetadata(org.apache.bookkeeper.client.LedgerMetadata) DistributedLogManager(org.apache.distributedlog.api.DistributedLogManager) BKNamespaceDriver(org.apache.distributedlog.impl.BKNamespaceDriver) Test(org.junit.Test)

Example 3 with BKNamespaceDriver

use of org.apache.distributedlog.impl.BKNamespaceDriver in project bookkeeper by apache.

the class TestAsyncReaderWriter method testCloseAndCompleteLogSegmentWhenCloseFailed.

@Test(timeout = 60000)
public void testCloseAndCompleteLogSegmentWhenCloseFailed() throws Exception {
    String name = "distrlog-close-and-complete-logsegment-when-close-failed";
    DistributedLogConfiguration confLocal = new DistributedLogConfiguration();
    confLocal.loadConf(testConf);
    confLocal.setOutputBufferSize(0);
    confLocal.setImmediateFlushEnabled(true);
    BKDistributedLogManager dlm = (BKDistributedLogManager) createNewDLM(confLocal, name);
    BKAsyncLogWriter writer = (BKAsyncLogWriter) (dlm.startAsyncLogSegmentNonPartitioned());
    long txId = 1L;
    for (int i = 0; i < 5; i++) {
        Utils.ioResult(writer.write(DLMTestUtil.getLogRecordInstance(txId++)));
    }
    BKLogSegmentWriter logWriter = writer.getCachedLogWriter();
    BKNamespaceDriver driver = (BKNamespaceDriver) dlm.getNamespaceDriver();
    // fence the ledger
    driver.getReaderBKC().get().openLedger(logWriter.getLogSegmentId(), BookKeeper.DigestType.CRC32, confLocal.getBKDigestPW().getBytes(UTF_8));
    try {
        // insert a write to detect the fencing state, to make test more robust.
        writer.write(DLMTestUtil.getLogRecordInstance(txId++));
        writer.closeAndComplete();
        fail("Should fail to complete a log segment when its ledger is fenced");
    } catch (IOException ioe) {
        // expected
        LOG.error("Failed to close and complete log segment {} : ", logWriter.getFullyQualifiedLogSegment(), ioe);
    }
    List<LogSegmentMetadata> segments = dlm.getLogSegments();
    assertEquals(1, segments.size());
    assertTrue(segments.get(0).isInProgress());
    dlm.close();
}
Also used : DynamicDistributedLogConfiguration(org.apache.distributedlog.config.DynamicDistributedLogConfiguration) BKNamespaceDriver(org.apache.distributedlog.impl.BKNamespaceDriver) IOException(java.io.IOException) Test(org.junit.Test)

Example 4 with BKNamespaceDriver

use of org.apache.distributedlog.impl.BKNamespaceDriver in project bookkeeper by apache.

the class TestDistributedLogBase method getBookKeeperClient.

@SuppressWarnings("deprecation")
protected BookKeeperClient getBookKeeperClient(Namespace namespace) throws Exception {
    NamespaceDriver driver = namespace.getNamespaceDriver();
    assertTrue(driver instanceof BKNamespaceDriver);
    return ((BKNamespaceDriver) driver).getReaderBKC();
}
Also used : BKNamespaceDriver(org.apache.distributedlog.impl.BKNamespaceDriver) NamespaceDriver(org.apache.distributedlog.namespace.NamespaceDriver) BKNamespaceDriver(org.apache.distributedlog.impl.BKNamespaceDriver)

Example 5 with BKNamespaceDriver

use of org.apache.distributedlog.impl.BKNamespaceDriver in project bookkeeper by apache.

the class TestDistributedLogBase method getZooKeeperClient.

protected ZooKeeperClient getZooKeeperClient(Namespace namespace) throws Exception {
    NamespaceDriver driver = namespace.getNamespaceDriver();
    assertTrue(driver instanceof BKNamespaceDriver);
    return ((BKNamespaceDriver) driver).getWriterZKC();
}
Also used : BKNamespaceDriver(org.apache.distributedlog.impl.BKNamespaceDriver) NamespaceDriver(org.apache.distributedlog.namespace.NamespaceDriver) BKNamespaceDriver(org.apache.distributedlog.impl.BKNamespaceDriver)

Aggregations

BKNamespaceDriver (org.apache.distributedlog.impl.BKNamespaceDriver)8 Test (org.junit.Test)6 DistributedLogManager (org.apache.distributedlog.api.DistributedLogManager)4 IOException (java.io.IOException)3 DynamicDistributedLogConfiguration (org.apache.distributedlog.config.DynamicDistributedLogConfiguration)3 NamespaceDriver (org.apache.distributedlog.namespace.NamespaceDriver)3 URI (java.net.URI)2 AsyncLogWriter (org.apache.distributedlog.api.AsyncLogWriter)2 BKException (org.apache.bookkeeper.client.BKException)1 LedgerHandle (org.apache.bookkeeper.client.LedgerHandle)1 LedgerMetadata (org.apache.bookkeeper.client.LedgerMetadata)1 AsyncLogReader (org.apache.distributedlog.api.AsyncLogReader)1 Namespace (org.apache.distributedlog.api.namespace.Namespace)1 LedgerAllocator (org.apache.distributedlog.bk.LedgerAllocator)1 LedgerAllocatorPool (org.apache.distributedlog.bk.LedgerAllocatorPool)1 ConcurrentBaseConfiguration (org.apache.distributedlog.common.config.ConcurrentBaseConfiguration)1 ConcurrentConstConfiguration (org.apache.distributedlog.common.config.ConcurrentConstConfiguration)1 BKTransmitException (org.apache.distributedlog.exceptions.BKTransmitException)1