Search in sources :

Example 16 with DLSN

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

the class DLOutputStream method write.

private synchronized void write(ByteBuf buf) throws IOException {
    Throwable cause = exceptionUpdater.get(this);
    if (null != cause) {
        if (cause instanceof IOException) {
            throw (IOException) cause;
        } else {
            throw new UnexpectedException("Encountered unknown issue", cause);
        }
    }
    writePos += buf.readableBytes();
    LogRecord record = new LogRecord(writePos, buf);
    writer.write(record).whenComplete(new FutureEventListener<DLSN>() {

        @Override
        public void onSuccess(DLSN value) {
            synchronized (syncPos) {
                syncPos[0] = record.getTransactionId();
            }
        }

        @Override
        public void onFailure(Throwable cause) {
            exceptionUpdater.compareAndSet(DLOutputStream.this, null, cause);
        }
    });
}
Also used : UnexpectedException(org.apache.distributedlog.exceptions.UnexpectedException) DLSN(org.apache.distributedlog.DLSN) LogRecord(org.apache.distributedlog.LogRecord) IOException(java.io.IOException)

Example 17 with DLSN

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

the class ZKSubscriptionStateStore method getLastCommitPositionFromZK.

CompletableFuture<DLSN> getLastCommitPositionFromZK() {
    final CompletableFuture<DLSN> result = new CompletableFuture<DLSN>();
    try {
        logger.debug("Reading last commit position from path {}", zkPath);
        zooKeeperClient.get().getData(zkPath, false, new AsyncCallback.DataCallback() {

            @Override
            public void processResult(int rc, String path, Object ctx, byte[] data, Stat stat) {
                logger.debug("Read last commit position from path {}: rc = {}", zkPath, rc);
                if (KeeperException.Code.NONODE.intValue() == rc) {
                    result.complete(DLSN.NonInclusiveLowerBound);
                } else if (KeeperException.Code.OK.intValue() != rc) {
                    result.completeExceptionally(KeeperException.create(KeeperException.Code.get(rc), path));
                } else {
                    try {
                        DLSN dlsn = DLSN.deserialize(new String(data, Charsets.UTF_8));
                        result.complete(dlsn);
                    } catch (Exception t) {
                        logger.warn("Invalid last commit position found from path {}", zkPath, t);
                        // invalid dlsn recorded in subscription state store
                        result.complete(DLSN.NonInclusiveLowerBound);
                    }
                }
            }
        }, null);
    } catch (ZooKeeperClient.ZooKeeperConnectionException zkce) {
        result.completeExceptionally(zkce);
    } catch (InterruptedException ie) {
        Thread.currentThread().interrupt();
        result.completeExceptionally(new DLInterruptedException("getLastCommitPosition was interrupted", ie));
    }
    return result;
}
Also used : DLSN(org.apache.distributedlog.DLSN) AsyncCallback(org.apache.zookeeper.AsyncCallback) DLInterruptedException(org.apache.distributedlog.exceptions.DLInterruptedException) KeeperException(org.apache.zookeeper.KeeperException) DLInterruptedException(org.apache.distributedlog.exceptions.DLInterruptedException) IOException(java.io.IOException) CompletableFuture(java.util.concurrent.CompletableFuture) Stat(org.apache.zookeeper.data.Stat) ZooKeeperClient(org.apache.distributedlog.ZooKeeperClient) DLInterruptedException(org.apache.distributedlog.exceptions.DLInterruptedException)

Example 18 with DLSN

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

the class MVCCStoreFactoryImplTest method setup.

@Before
public void setup() throws IOException {
    this.namespace = mock(Namespace.class);
    DistributedLogManager dlm = mock(DistributedLogManager.class);
    when(dlm.asyncClose()).thenReturn(FutureUtils.Void());
    when(namespace.openLog(anyString())).thenReturn(dlm);
    AsyncLogWriter logWriter = mock(AsyncLogWriter.class);
    when(dlm.openAsyncLogWriter()).thenReturn(FutureUtils.value(logWriter));
    when(logWriter.getLastTxId()).thenReturn(-1L);
    DLSN dlsn = new DLSN(0L, 0L, 0L);
    when(logWriter.write(any(LogRecord.class))).thenReturn(FutureUtils.value(dlsn));
    when(logWriter.asyncClose()).thenReturn(FutureUtils.Void());
    AsyncLogReader logReader = mock(AsyncLogReader.class);
    when(dlm.openAsyncLogReader(anyLong())).thenReturn(FutureUtils.value(logReader));
    when(logReader.asyncClose()).thenReturn(FutureUtils.Void());
    LogRecordWithDLSN record = new LogRecordWithDLSN(dlsn, 0L, NOP_CMD.toByteArray(), 0L);
    when(logReader.readNext()).thenReturn(FutureUtils.value(record));
    int numDirs = 3;
    this.storeDirs = new File[numDirs];
    for (int i = 0; i < numDirs; i++) {
        storeDirs[i] = testDir.newFolder("test-" + i);
    }
    this.resources = StorageResources.create(StorageResourcesSpec.builder().numCheckpointThreads(3).numIOReadThreads(3).numIOWriteThreads(3).build());
    this.factory = new MVCCStoreFactoryImpl(() -> namespace, storeDirs, resources, false);
}
Also used : LogRecordWithDLSN(org.apache.distributedlog.LogRecordWithDLSN) DLSN(org.apache.distributedlog.DLSN) LogRecordWithDLSN(org.apache.distributedlog.LogRecordWithDLSN) LogRecord(org.apache.distributedlog.LogRecord) AsyncLogReader(org.apache.distributedlog.api.AsyncLogReader) DistributedLogManager(org.apache.distributedlog.api.DistributedLogManager) AsyncLogWriter(org.apache.distributedlog.api.AsyncLogWriter) Namespace(org.apache.distributedlog.api.namespace.Namespace) Before(org.junit.Before)

Example 19 with DLSN

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

the class MVCCAsyncStoreTestBase method mockNamespace.

private static Namespace mockNamespace() throws Exception {
    Namespace namespace = mock(Namespace.class);
    DistributedLogManager dlm = mock(DistributedLogManager.class);
    when(dlm.asyncClose()).thenReturn(FutureUtils.Void());
    when(namespace.openLog(anyString())).thenReturn(dlm);
    AsyncLogWriter logWriter = mock(AsyncLogWriter.class);
    when(dlm.openAsyncLogWriter()).thenReturn(FutureUtils.value(logWriter));
    when(logWriter.getLastTxId()).thenReturn(-1L);
    DLSN dlsn = new DLSN(0L, 0L, 0L);
    when(logWriter.write(any(LogRecord.class))).thenReturn(FutureUtils.value(dlsn));
    when(logWriter.asyncClose()).thenReturn(FutureUtils.Void());
    AsyncLogReader logReader = mock(AsyncLogReader.class);
    when(dlm.openAsyncLogReader(anyLong())).thenReturn(FutureUtils.value(logReader));
    when(logReader.asyncClose()).thenReturn(FutureUtils.Void());
    LogRecordWithDLSN record = new LogRecordWithDLSN(dlsn, 0L, NOP_CMD.toByteArray(), 0L);
    when(logReader.readNext()).thenReturn(FutureUtils.value(record));
    return namespace;
}
Also used : LogRecordWithDLSN(org.apache.distributedlog.LogRecordWithDLSN) DLSN(org.apache.distributedlog.DLSN) LogRecordWithDLSN(org.apache.distributedlog.LogRecordWithDLSN) LogRecord(org.apache.distributedlog.LogRecord) AsyncLogReader(org.apache.distributedlog.api.AsyncLogReader) DistributedLogManager(org.apache.distributedlog.api.DistributedLogManager) AsyncLogWriter(org.apache.distributedlog.api.AsyncLogWriter) Namespace(org.apache.distributedlog.api.namespace.Namespace)

Aggregations

DLSN (org.apache.distributedlog.DLSN)19 LogRecordWithDLSN (org.apache.distributedlog.LogRecordWithDLSN)13 Test (org.junit.Test)13 DistributedLogManager (org.apache.distributedlog.api.DistributedLogManager)11 DistributedLogConfiguration (org.apache.distributedlog.DistributedLogConfiguration)9 LogSegmentMetadata (org.apache.distributedlog.LogSegmentMetadata)9 Entry (org.apache.distributedlog.Entry)6 LogRecord (org.apache.distributedlog.LogRecord)4 AsyncLogWriter (org.apache.distributedlog.api.AsyncLogWriter)4 Namespace (org.apache.distributedlog.api.namespace.Namespace)4 IOException (java.io.IOException)3 AsyncLogReader (org.apache.distributedlog.api.AsyncLogReader)3 URI (java.net.URI)2 List (java.util.List)2 EndOfLogSegmentException (org.apache.distributedlog.exceptions.EndOfLogSegmentException)2 UnexpectedException (org.apache.distributedlog.exceptions.UnexpectedException)2 DryrunLogSegmentMetadataStoreUpdater (org.apache.distributedlog.metadata.DryrunLogSegmentMetadataStoreUpdater)2 CompletableFuture (java.util.concurrent.CompletableFuture)1 ExecutorService (java.util.concurrent.ExecutorService)1 OrderedScheduler (org.apache.bookkeeper.common.util.OrderedScheduler)1