Java Code Examples for org.apache.bookkeeper.client.BookKeeper#asyncDeleteLedger()

The following examples show how to use org.apache.bookkeeper.client.BookKeeper#asyncDeleteLedger() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BookKeeperClient.java    From distributedlog with Apache License 2.0 5 votes vote down vote up
public CompletableFuture<Void> deleteLedger(long lid,
                                 final boolean ignoreNonExistentLedger) {
    BookKeeper bk;
    try {
        bk = get();
    } catch (IOException ioe) {
        return FutureUtils.exception(ioe);
    }
    final CompletableFuture<Void> promise = new CompletableFuture<Void>();
    bk.asyncDeleteLedger(lid, new AsyncCallback.DeleteCallback() {
        @Override
        public void deleteComplete(int rc, Object ctx) {
            if (BKException.Code.OK == rc) {
                promise.complete(null);
            } else if (BKException.Code.NoSuchLedgerExistsException == rc) {
                if (ignoreNonExistentLedger) {
                    promise.complete(null);
                } else {
                    promise.completeExceptionally(BKException.create(rc));
                }
            } else {
                promise.completeExceptionally(BKException.create(rc));
            }
        }
    }, null);
    return promise;
}
 
Example 2
Source File: BKLogSegmentEntryStore.java    From distributedlog with Apache License 2.0 5 votes vote down vote up
@Override
public CompletableFuture<LogSegmentMetadata> deleteLogSegment(LogSegmentMetadata segment) {
    DeleteLogSegmentRequest request = new DeleteLogSegmentRequest(segment);
    BookKeeper bk;
    try {
        bk = this.bkc.get();
    } catch (IOException e) {
        return FutureUtils.exception(e);
    }
    bk.asyncDeleteLedger(segment.getLogSegmentId(), this, request);
    return request.deletePromise;
}
 
Example 3
Source File: BookKeeperClient.java    From distributedlog with Apache License 2.0 5 votes vote down vote up
public Future<Void> deleteLedger(long lid,
                                 final boolean ignoreNonExistentLedger) {
    BookKeeper bk;
    try {
        bk = get();
    } catch (IOException ioe) {
        return Future.exception(ioe);
    }
    final Promise<Void> promise = new Promise<Void>();
    bk.asyncDeleteLedger(lid, new AsyncCallback.DeleteCallback() {
        @Override
        public void deleteComplete(int rc, Object ctx) {
            if (BKException.Code.OK == rc) {
                promise.updateIfEmpty(new Return<Void>(null));
            } else if (BKException.Code.NoSuchLedgerExistsException == rc) {
                if (ignoreNonExistentLedger) {
                    promise.updateIfEmpty(new Return<Void>(null));
                } else {
                    promise.updateIfEmpty(new Throw<Void>(BKException.create(rc)));
                }
            } else {
                promise.updateIfEmpty(new Throw<Void>(BKException.create(rc)));
            }
        }
    }, null);
    return promise;
}
 
Example 4
Source File: TwoPhaseCompactor.java    From pulsar with Apache License 2.0 5 votes vote down vote up
private CompletableFuture<Void> deleteLedger(BookKeeper bk, LedgerHandle lh) {
    CompletableFuture<Void> bkf = new CompletableFuture<>();
    bk.asyncDeleteLedger(lh.getId(),
                         (rc, ctx) -> {
                             if (rc != BKException.Code.OK) {
                                 bkf.completeExceptionally(BKException.create(rc));
                             } else {
                                 bkf.complete(null);
                             }
                         }, null);
    return bkf;
}
 
Example 5
Source File: CompactedTopicImpl.java    From pulsar with Apache License 2.0 5 votes vote down vote up
private static CompletableFuture<Void> tryDeleteCompactedLedger(BookKeeper bk, long id) {
    CompletableFuture<Void> promise = new CompletableFuture<>();
    bk.asyncDeleteLedger(id,
                         (rc, ctx) -> {
                             if (rc != BKException.Code.OK) {
                                 log.warn("Error deleting compacted topic ledger {}",
                                          id, BKException.create(rc));
                             } else {
                                 log.debug("Compacted topic ledger deleted successfully");
                             }
                             promise.complete(null); // don't propagate any error
                         }, null);
    return promise;
}