Search in sources :

Example 1 with WriteTooLongException

use of io.pravega.segmentstore.storage.WriteTooLongException in project pravega by pravega.

the class BookKeeperLog method append.

@Override
public CompletableFuture<LogAddress> append(ArrayView data, Duration timeout) {
    ensurePreconditions();
    long traceId = LoggerHelpers.traceEnterWithContext(log, this.traceObjectId, "append", data.getLength());
    if (data.getLength() > getMaxAppendLength()) {
        return Futures.failedFuture(new WriteTooLongException(data.getLength(), getMaxAppendLength()));
    }
    Timer timer = new Timer();
    // Queue up the write.
    CompletableFuture<LogAddress> result = new CompletableFuture<>();
    this.writes.add(new Write(data, getWriteLedger(), result));
    // Trigger Write Processor.
    this.writeProcessor.runAsync();
    // Post append tasks. We do not need to wait for these to happen before returning the call.
    result.whenCompleteAsync((address, ex) -> {
        if (ex != null) {
            handleWriteException(ex);
        } else {
            // Update metrics and take care of other logging tasks.
            this.metrics.writeCompleted(timer.getElapsed());
            LoggerHelpers.traceLeave(log, this.traceObjectId, "append", traceId, data.getLength(), address);
        }
    }, this.executorService);
    return result;
}
Also used : LogAddress(io.pravega.segmentstore.storage.LogAddress) CompletableFuture(java.util.concurrent.CompletableFuture) Timer(io.pravega.common.Timer) WriteTooLongException(io.pravega.segmentstore.storage.WriteTooLongException)

Example 2 with WriteTooLongException

use of io.pravega.segmentstore.storage.WriteTooLongException in project pravega by pravega.

the class InMemoryDurableDataLog method append.

@Override
public CompletableFuture<LogAddress> append(CompositeArrayView data, Duration timeout) {
    ensurePreconditions();
    if (data.getLength() > getWriteSettings().getMaxWriteLength()) {
        return Futures.failedFuture(new WriteTooLongException(data.getLength(), getWriteSettings().getMaxWriteLength()));
    }
    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) ThrottleSourceListener(io.pravega.segmentstore.storage.ThrottleSourceListener) 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) 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) LinkedList(java.util.LinkedList) 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) WriteSettings(io.pravega.segmentstore.storage.WriteSettings) Futures(io.pravega.common.concurrent.Futures) CompositeArrayView(io.pravega.common.util.CompositeArrayView) WriteTooLongException(io.pravega.segmentstore.storage.WriteTooLongException) InputStream(java.io.InputStream) LogAddress(io.pravega.segmentstore.storage.LogAddress) WriteTooLongException(io.pravega.segmentstore.storage.WriteTooLongException) Duration(java.time.Duration)

Example 3 with WriteTooLongException

use of io.pravega.segmentstore.storage.WriteTooLongException in project pravega by pravega.

the class BookKeeperLog method append.

@Override
public CompletableFuture<LogAddress> append(CompositeArrayView data, Duration timeout) {
    ensurePreconditions();
    long traceId = LoggerHelpers.traceEnterWithContext(log, this.traceObjectId, "append", data.getLength());
    if (data.getLength() > BookKeeperConfig.MAX_APPEND_LENGTH) {
        return Futures.failedFuture(new WriteTooLongException(data.getLength(), BookKeeperConfig.MAX_APPEND_LENGTH));
    }
    Timer timer = new Timer();
    // Queue up the write.
    CompletableFuture<LogAddress> result = new CompletableFuture<>();
    this.writes.add(new Write(data, getWriteLedger(), result));
    // Trigger Write Processor.
    this.writeProcessor.runAsync();
    // Post append tasks. We do not need to wait for these to happen before returning the call.
    result.whenCompleteAsync((address, ex) -> {
        if (ex != null) {
            handleWriteException(ex);
        } else {
            // Update metrics and take care of other logging tasks.
            this.metrics.writeCompleted(timer.getElapsed());
            LoggerHelpers.traceLeave(log, this.traceObjectId, "append", traceId, data.getLength(), address);
        }
    }, this.executorService);
    return result;
}
Also used : LogAddress(io.pravega.segmentstore.storage.LogAddress) CompletableFuture(java.util.concurrent.CompletableFuture) Timer(io.pravega.common.Timer) WriteTooLongException(io.pravega.segmentstore.storage.WriteTooLongException)

Aggregations

LogAddress (io.pravega.segmentstore.storage.LogAddress)3 WriteTooLongException (io.pravega.segmentstore.storage.WriteTooLongException)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 Timer (io.pravega.common.Timer)2 Preconditions (com.google.common.base.Preconditions)1 Exceptions (io.pravega.common.Exceptions)1 Futures (io.pravega.common.concurrent.Futures)1 CloseableIterator (io.pravega.common.util.CloseableIterator)1 CompositeArrayView (io.pravega.common.util.CompositeArrayView)1 DataLogDisabledException (io.pravega.segmentstore.storage.DataLogDisabledException)1 DataLogInitializationException (io.pravega.segmentstore.storage.DataLogInitializationException)1 DataLogWriterNotPrimaryException (io.pravega.segmentstore.storage.DataLogWriterNotPrimaryException)1 DurableDataLog (io.pravega.segmentstore.storage.DurableDataLog)1 DurableDataLogException (io.pravega.segmentstore.storage.DurableDataLogException)1 QueueStats (io.pravega.segmentstore.storage.QueueStats)1 ThrottleSourceListener (io.pravega.segmentstore.storage.ThrottleSourceListener)1 WriteSettings (io.pravega.segmentstore.storage.WriteSettings)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 Duration (java.time.Duration)1