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;
}
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);
}
}
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;
}
Aggregations