sijie commented on a change in pull request #1436: BP-14 force() API - client
side implementation
URL: https://github.com/apache/bookkeeper/pull/1436#discussion_r193180876
##########
File path:
bookkeeper-server/src/main/java/org/apache/bookkeeper/client/LedgerHandle.java
##########
@@ -1100,6 +1100,68 @@ public void asyncAddEntry(final long entryId, final
byte[] data, final int offse
cb.addCompleteWithLatency(BKException.Code.IllegalOpException,
LedgerHandle.this, entryId, 0, ctx);
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public CompletableFuture<Void> force() {
+ CompletableFuture<Void> result = new CompletableFuture<>();
+ ForceLedgerOp op = new ForceLedgerOp(this, result);
+ boolean wasClosed = false;
+ synchronized (this) {
+ // synchronized on this to ensure that
+ // the ledger isn't closed between checking and
+ // updating lastAddPushed
+ if (metadata.isClosed()) {
+ wasClosed = true;
+ }
+ }
+
+ if (wasClosed) {
+ // make sure the callback is triggered in main worker pool
+ try {
+ bk.getMainWorkerPool().submit(new SafeRunnable() {
+ @Override
+ public void safeRun() {
+ LOG.warn("Force() attempted on a closed ledger: {}",
ledgerId);
+ result.completeExceptionally(new
BKException.BKLedgerClosedException());
+ }
+
+ @Override
+ public String toString() {
+ return String.format("force(lid=%d)", ledgerId);
+ }
+ });
+ } catch (RejectedExecutionException e) {
+ result.completeExceptionally(new
BKException.BKInterruptedException());
+ }
+ return result;
+ }
+
+ // early exit: no write has been issued yet
+ if (pendingAddsSequenceHead == INVALID_ENTRY_ID) {
+ bk.getMainWorkerPool().submit(new SafeRunnable() {
Review comment:
better to use `executeOrdered`
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services