Search in sources :

Example 6 with ArrayView

use of io.pravega.common.util.ArrayView in project pravega by pravega.

the class SegmentStoreAdapter method append.

@Override
public CompletableFuture<Void> append(String streamName, Event event, Duration timeout) {
    ensureRunning();
    ArrayView s = event.getSerialization();
    byte[] payload = s.arrayOffset() == 0 ? s.array() : Arrays.copyOfRange(s.array(), s.arrayOffset(), s.getLength());
    return this.streamSegmentStore.append(streamName, payload, null, timeout).exceptionally(ex -> attemptReconcile(ex, streamName, timeout));
}
Also used : ArrayView(io.pravega.common.util.ArrayView)

Example 7 with ArrayView

use of io.pravega.common.util.ArrayView in project pravega by pravega.

the class InMemoryDurableDataLog method append.

@Override
public CompletableFuture<LogAddress> append(ArrayView data, Duration timeout) {
    ensurePreconditions();
    CompletableFuture<LogAddress> result;
    try {
        Entry entry = new Entry(data);
        synchronized (this.entries) {
            entry.sequenceNumber = this.offset;
            this.entries.add(entry, clientId);
            // Only update internals after a successful add.
            this.offset += entry.data.length;
        }
        result = CompletableFuture.completedFuture(new InMemoryLogAddress(entry.sequenceNumber));
    } catch (Throwable ex) {
        return Futures.failedFuture(ex);
    }
    Duration delay = this.appendDelayProvider.get();
    if (delay.compareTo(Duration.ZERO) <= 0) {
        // No delay, execute right away.
        return result;
    } else {
        // Schedule the append after the given delay.
        return result.thenComposeAsync(logAddress -> Futures.delayedFuture(delay, this.executorService).thenApply(ignored -> logAddress), this.executorService);
    }
}
Also used : Getter(lombok.Getter) Exceptions(io.pravega.common.Exceptions) RequiredArgsConstructor(lombok.RequiredArgsConstructor) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CompletableFuture(java.util.concurrent.CompletableFuture) LogAddress(io.pravega.segmentstore.storage.LogAddress) AtomicReference(java.util.concurrent.atomic.AtomicReference) Supplier(java.util.function.Supplier) ArrayView(io.pravega.common.util.ArrayView) SequencedItemList(io.pravega.common.util.SequencedItemList) ByteArrayInputStream(java.io.ByteArrayInputStream) Duration(java.time.Duration) DataLogInitializationException(io.pravega.segmentstore.storage.DataLogInitializationException) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) DurableDataLogException(io.pravega.segmentstore.storage.DurableDataLogException) CloseableIterator(io.pravega.common.util.CloseableIterator) DataLogDisabledException(io.pravega.segmentstore.storage.DataLogDisabledException) DurableDataLog(io.pravega.segmentstore.storage.DurableDataLog) Iterator(java.util.Iterator) CompletionException(java.util.concurrent.CompletionException) ThreadSafe(javax.annotation.concurrent.ThreadSafe) UUID(java.util.UUID) DataLogWriterNotPrimaryException(io.pravega.segmentstore.storage.DataLogWriterNotPrimaryException) GuardedBy(javax.annotation.concurrent.GuardedBy) AtomicLong(java.util.concurrent.atomic.AtomicLong) QueueStats(io.pravega.segmentstore.storage.QueueStats) Preconditions(com.google.common.base.Preconditions) Futures(io.pravega.common.concurrent.Futures) InputStream(java.io.InputStream) LogAddress(io.pravega.segmentstore.storage.LogAddress) Duration(java.time.Duration)

Aggregations

ArrayView (io.pravega.common.util.ArrayView)7 StreamSegmentNotExistsException (io.pravega.segmentstore.contracts.StreamSegmentNotExistsException)4 CompletionException (java.util.concurrent.CompletionException)4 Preconditions (com.google.common.base.Preconditions)2 Exceptions (io.pravega.common.Exceptions)2 DataCorruptionException (io.pravega.segmentstore.server.DataCorruptionException)2 DataLogDisabledException (io.pravega.segmentstore.storage.DataLogDisabledException)2 DataLogWriterNotPrimaryException (io.pravega.segmentstore.storage.DataLogWriterNotPrimaryException)2 DurableDataLog (io.pravega.segmentstore.storage.DurableDataLog)2 DurableDataLogException (io.pravega.segmentstore.storage.DurableDataLogException)2 Storage (io.pravega.segmentstore.storage.Storage)2 IOException (java.io.IOException)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 TxnFailedException (io.pravega.client.stream.TxnFailedException)1 TimeoutTimer (io.pravega.common.TimeoutTimer)1 Futures (io.pravega.common.concurrent.Futures)1 SerializationException (io.pravega.common.io.SerializationException)1 AsyncMap (io.pravega.common.util.AsyncMap)1 CloseableIterator (io.pravega.common.util.CloseableIterator)1 SequencedItemList (io.pravega.common.util.SequencedItemList)1