Search in sources :

Example 6 with Namespace

use of org.apache.distributedlog.api.namespace.Namespace in project bookkeeper by apache.

the class TestBKDistributedLogNamespace method testCreateIfNotExists.

@Test(timeout = 60000)
public void testCreateIfNotExists() throws Exception {
    URI uri = createDLMURI("/" + runtime.getMethodName());
    ensureURICreated(zooKeeperClient.get(), uri);
    DistributedLogConfiguration newConf = new DistributedLogConfiguration();
    newConf.addConfiguration(conf);
    newConf.setCreateStreamIfNotExists(false);
    String streamName = "test-stream";
    Namespace namespace = NamespaceBuilder.newBuilder().conf(newConf).uri(uri).build();
    DistributedLogManager dlm = namespace.openLog(streamName);
    LogWriter writer;
    try {
        writer = dlm.startLogSegmentNonPartitioned();
        writer.write(DLMTestUtil.getLogRecordInstance(1L));
        fail("Should fail to write data if stream doesn't exist.");
    } catch (IOException ioe) {
    // expected
    }
    dlm.close();
    // create the stream
    namespace.createLog(streamName);
    DistributedLogManager newDLM = namespace.openLog(streamName);
    LogWriter newWriter = newDLM.startLogSegmentNonPartitioned();
    newWriter.write(DLMTestUtil.getLogRecordInstance(1L));
    newWriter.close();
    newDLM.close();
}
Also used : LogWriter(org.apache.distributedlog.api.LogWriter) DistributedLogManager(org.apache.distributedlog.api.DistributedLogManager) IOException(java.io.IOException) URI(java.net.URI) Namespace(org.apache.distributedlog.api.namespace.Namespace) Test(org.junit.Test)

Example 7 with Namespace

use of org.apache.distributedlog.api.namespace.Namespace in project bookkeeper by apache.

the class TestBKDistributedLogNamespace method createLogPathTest.

private void createLogPathTest(String logName) throws Exception {
    URI uri = createDLMURI("/" + runtime.getMethodName());
    ensureURICreated(zooKeeperClient.get(), uri);
    DistributedLogConfiguration newConf = new DistributedLogConfiguration();
    newConf.addConfiguration(conf);
    newConf.setCreateStreamIfNotExists(false);
    Namespace namespace = NamespaceBuilder.newBuilder().conf(newConf).uri(uri).build();
    DistributedLogManager dlm = namespace.openLog(logName);
    LogWriter writer;
    try {
        writer = dlm.startLogSegmentNonPartitioned();
        writer.write(DLMTestUtil.getLogRecordInstance(1L));
        writer.commit();
        fail("Should fail to write data if stream doesn't exist.");
    } catch (IOException ioe) {
    // expected
    }
    dlm.close();
}
Also used : LogWriter(org.apache.distributedlog.api.LogWriter) DistributedLogManager(org.apache.distributedlog.api.DistributedLogManager) IOException(java.io.IOException) URI(java.net.URI) Namespace(org.apache.distributedlog.api.namespace.Namespace)

Example 8 with Namespace

use of org.apache.distributedlog.api.namespace.Namespace in project bookkeeper by apache.

the class TestZKLogStreamMetadataStore method testCreateLogMetadataWithCustomMetadata.

@SuppressWarnings("deprecation")
@Test(timeout = 60000)
public void testCreateLogMetadataWithCustomMetadata() throws Exception {
    String logName = testName.getMethodName();
    String logIdentifier = "<default>";
    List<String> pathsToDelete = Lists.newArrayList();
    DLMetadata.create(new BKDLConfig(zkServers, "/ledgers")).update(uri);
    Namespace namespace = NamespaceBuilder.newBuilder().conf(new DistributedLogConfiguration()).uri(uri).build();
    org.apache.distributedlog.api.MetadataAccessor accessor = namespace.getNamespaceDriver().getMetadataAccessor(logName);
    accessor.createOrUpdateMetadata(logName.getBytes("UTF-8"));
    accessor.close();
    testCreateLogMetadataWithMissingPaths(uri, logName, logIdentifier, pathsToDelete, true, false);
}
Also used : DistributedLogConfiguration(org.apache.distributedlog.DistributedLogConfiguration) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Namespace(org.apache.distributedlog.api.namespace.Namespace) Test(org.junit.Test)

Example 9 with Namespace

use of org.apache.distributedlog.api.namespace.Namespace in project bookkeeper by apache.

the class TestDLCK method testCheckAndRepairDLNamespace.

@Test(timeout = 60000)
@SuppressWarnings("deprecation")
public void testCheckAndRepairDLNamespace() throws Exception {
    DistributedLogConfiguration confLocal = new DistributedLogConfiguration();
    confLocal.loadConf(conf);
    confLocal.setImmediateFlushEnabled(true);
    confLocal.setOutputBufferSize(0);
    confLocal.setLogSegmentSequenceNumberValidationEnabled(false);
    confLocal.setLogSegmentCacheEnabled(false);
    URI uri = createDLMURI("/check-and-repair-dl-namespace");
    zkc.get().create(uri.getPath(), new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    Namespace namespace = NamespaceBuilder.newBuilder().conf(confLocal).uri(uri).build();
    OrderedScheduler scheduler = OrderedScheduler.newSchedulerBuilder().name("dlck-tool").numThreads(1).build();
    ExecutorService executorService = Executors.newCachedThreadPool();
    String streamName = "check-and-repair-dl-namespace";
    // Create completed log segments
    DistributedLogManager dlm = namespace.openLog(streamName);
    DLMTestUtil.injectLogSegmentWithLastDLSN(dlm, confLocal, 1L, 1L, 10, false);
    DLMTestUtil.injectLogSegmentWithLastDLSN(dlm, confLocal, 2L, 11L, 10, true);
    DLMTestUtil.injectLogSegmentWithLastDLSN(dlm, confLocal, 3L, 21L, 10, false);
    DLMTestUtil.injectLogSegmentWithLastDLSN(dlm, confLocal, 4L, 31L, 10, true);
    // dryrun
    DistributedLogAdmin.checkAndRepairDLNamespace(uri, namespace, new DryrunLogSegmentMetadataStoreUpdater(confLocal, getLogSegmentMetadataStore(namespace)), scheduler, false, false);
    Map<Long, LogSegmentMetadata> segments = getLogSegments(dlm);
    LOG.info("segments after drynrun {}", segments);
    verifyLogSegment(segments, new DLSN(1L, 18L, 0L), 1L, 10, 10L);
    verifyLogSegment(segments, new DLSN(2L, 16L, 0L), 2L, 9, 19L);
    verifyLogSegment(segments, new DLSN(3L, 18L, 0L), 3L, 10, 30L);
    verifyLogSegment(segments, new DLSN(4L, 16L, 0L), 4L, 9, 39L);
    // check and repair
    DistributedLogAdmin.checkAndRepairDLNamespace(uri, namespace, LogSegmentMetadataStoreUpdater.createMetadataUpdater(confLocal, getLogSegmentMetadataStore(namespace)), scheduler, false, false);
    segments = getLogSegments(dlm);
    LOG.info("segments after repair {}", segments);
    verifyLogSegment(segments, new DLSN(1L, 18L, 0L), 1L, 10, 10L);
    verifyLogSegment(segments, new DLSN(2L, 18L, 0L), 2L, 10, 20L);
    verifyLogSegment(segments, new DLSN(3L, 18L, 0L), 3L, 10, 30L);
    verifyLogSegment(segments, new DLSN(4L, 18L, 0L), 4L, 10, 40L);
    dlm.close();
    SchedulerUtils.shutdownScheduler(executorService, 5, TimeUnit.MINUTES);
    namespace.close();
}
Also used : DistributedLogConfiguration(org.apache.distributedlog.DistributedLogConfiguration) DLSN(org.apache.distributedlog.DLSN) DistributedLogManager(org.apache.distributedlog.api.DistributedLogManager) LogSegmentMetadata(org.apache.distributedlog.LogSegmentMetadata) DryrunLogSegmentMetadataStoreUpdater(org.apache.distributedlog.metadata.DryrunLogSegmentMetadataStoreUpdater) ExecutorService(java.util.concurrent.ExecutorService) URI(java.net.URI) Namespace(org.apache.distributedlog.api.namespace.Namespace) OrderedScheduler(org.apache.bookkeeper.common.util.OrderedScheduler) Test(org.junit.Test)

Example 10 with Namespace

use of org.apache.distributedlog.api.namespace.Namespace in project bookkeeper by apache.

the class TestDistributedLogBase method createNewDLM.

public BKDistributedLogManager createNewDLM(DistributedLogConfiguration conf, String name, PermitLimiter writeLimiter) throws Exception {
    URI uri = createDLMURI("/" + name);
    ensureURICreated(uri);
    final Namespace namespace = NamespaceBuilder.newBuilder().uri(uri).conf(conf).build();
    final OrderedScheduler scheduler = OrderedScheduler.newSchedulerBuilder().numThreads(1).name("test-scheduler").build();
    AsyncCloseable resourcesCloseable = new AsyncCloseable() {

        @Override
        public CompletableFuture<Void> asyncClose() {
            LOG.info("Shutting down the scheduler");
            SchedulerUtils.shutdownScheduler(scheduler, 1, TimeUnit.SECONDS);
            LOG.info("Shut down the scheduler");
            LOG.info("Closing the namespace");
            namespace.close();
            LOG.info("Closed the namespace");
            return FutureUtils.Void();
        }
    };
    AsyncFailureInjector failureInjector = AsyncRandomFailureInjector.newBuilder().injectDelays(conf.getEIInjectReadAheadDelay(), conf.getEIInjectReadAheadDelayPercent(), conf.getEIInjectMaxReadAheadDelayMs()).injectErrors(false, 10).injectStops(conf.getEIInjectReadAheadStall(), 10).injectCorruption(conf.getEIInjectReadAheadBrokenEntries()).build();
    return new BKDistributedLogManager(name, conf, ConfUtils.getConstDynConf(conf), uri, namespace.getNamespaceDriver(), new LogSegmentMetadataCache(conf, Ticker.systemTicker()), scheduler, DistributedLogConstants.UNKNOWN_CLIENT_ID, DistributedLogConstants.LOCAL_REGION_ID, writeLimiter, new SettableFeatureProvider("", 0), failureInjector, NullStatsLogger.INSTANCE, NullStatsLogger.INSTANCE, Optional.of(resourcesCloseable));
}
Also used : AsyncCloseable(org.apache.distributedlog.io.AsyncCloseable) AsyncFailureInjector(org.apache.distributedlog.injector.AsyncFailureInjector) LogSegmentMetadataCache(org.apache.distributedlog.logsegment.LogSegmentMetadataCache) URI(java.net.URI) Namespace(org.apache.distributedlog.api.namespace.Namespace) SettableFeatureProvider(org.apache.bookkeeper.feature.SettableFeatureProvider) OrderedScheduler(org.apache.bookkeeper.common.util.OrderedScheduler)

Aggregations

Namespace (org.apache.distributedlog.api.namespace.Namespace)50 Test (org.junit.Test)31 URI (java.net.URI)26 DistributedLogManager (org.apache.distributedlog.api.DistributedLogManager)25 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)13 InputStream (java.io.InputStream)12 IOException (java.io.IOException)10 Response (javax.ws.rs.core.Response)8 Test (org.testng.annotations.Test)8 FunctionMetaData (org.apache.pulsar.functions.proto.Function.FunctionMetaData)6 RequestResult (org.apache.pulsar.functions.worker.request.RequestResult)6 AsyncLogReader (org.apache.distributedlog.api.AsyncLogReader)5 AsyncLogWriter (org.apache.distributedlog.api.AsyncLogWriter)5 LogWriter (org.apache.distributedlog.api.LogWriter)5 ErrorData (org.apache.pulsar.common.policies.data.ErrorData)5 DLSN (org.apache.distributedlog.DLSN)4 DistributedLogConfiguration (org.apache.distributedlog.DistributedLogConfiguration)4 Matchers.anyString (org.mockito.Matchers.anyString)4 DLInputStream (com.twitter.heron.dlog.DLInputStream)3 OutputStream (java.io.OutputStream)3