/** * Write Processor main loop. This method is not thread safe and should only be invoked as part of the Write Processor. */ private void processWritesSync() { if (this.closed.get()) { // BookKeeperLog is closed. No point in trying anything else. return; } if (getWriteLedger().ledger.isClosed()) { // Current ledger is closed. Execute the rollover processor to safely create a new ledger. This will reinvoke // the write processor upon finish, so the writes can be reattempted. this.rolloverProcessor.runAsync(); } else if (!processPendingWrites() && !this.closed.get()) { // We were not able to complete execution of all writes. Try again. this.writeProcessor.runAsync(); } }
this.rolloverProcessor.runAsync();
this.writeProcessor.runAsync(); } catch (ObjectClosedException ex) {
@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; }