use of org.apache.distributedlog.util.Transaction.OpListener in project bookkeeper by apache.
the class SimpleLedgerAllocator method cleanupAndClose.
private void cleanupAndClose(final CompletableFuture<Void> closePromise) {
LOG.info("Closing ledger allocator on {}.", allocatePath);
final ZKTransaction txn = new ZKTransaction(zkc);
// try obtain ledger handle
tryObtain(txn, new OpListener<LedgerHandle>() {
@Override
public void onCommit(LedgerHandle r) {
// no-op
complete();
}
@Override
public void onAbort(Throwable t) {
// no-op
complete();
}
private void complete() {
closePromise.complete(null);
LOG.info("Closed ledger allocator on {}.", allocatePath);
}
}).whenComplete(new FutureEventListener<LedgerHandle>() {
@Override
public void onSuccess(LedgerHandle lh) {
// try obtain succeed
// if we could obtain the ledger handle, we have the responsibility to close it
deleteLedger(lh.getId());
// wait for deletion to be completed
List<CompletableFuture<Void>> outstandingDeletions;
synchronized (ledgerDeletions) {
outstandingDeletions = Lists.newArrayList(ledgerDeletions);
}
FutureUtils.collect(outstandingDeletions).whenComplete(new FutureEventListener<List<Void>>() {
@Override
public void onSuccess(List<Void> values) {
txn.execute();
}
@Override
public void onFailure(Throwable cause) {
LOG.debug("Fail to obtain the allocated ledger handle when closing the allocator : ", cause);
closePromise.complete(null);
}
});
}
@Override
public void onFailure(Throwable cause) {
LOG.debug("Fail to obtain the allocated ledger handle when closing the allocator : ", cause);
closePromise.complete(null);
}
});
}
use of org.apache.distributedlog.util.Transaction.OpListener in project bookkeeper by apache.
the class ZKLogSegmentMetadataStore method deleteLogSegment.
@Override
public void deleteLogSegment(Transaction<Object> txn, final LogSegmentMetadata segment, final OpListener<Void> listener) {
Op deleteOp = Op.delete(segment.getZkPath(), -1);
logger.info("Delete segment : {}", segment);
txn.addOp(DefaultZKOp.of(deleteOp, new OpListener<Void>() {
@Override
public void onCommit(Void r) {
if (null != listener) {
listener.onCommit(r);
}
}
@Override
public void onAbort(Throwable t) {
logger.info("Aborted transaction on deleting segment {}", segment);
KeeperException.Code kc;
if (t instanceof KeeperException) {
kc = ((KeeperException) t).code();
} else if (t instanceof ZKException) {
kc = ((ZKException) t).getKeeperExceptionCode();
} else {
abortListener(t);
return;
}
if (KeeperException.Code.NONODE == kc) {
abortListener(new LogSegmentNotFoundException(segment.getZkPath()));
return;
}
abortListener(t);
}
private void abortListener(Throwable t) {
if (null != listener) {
listener.onAbort(t);
}
}
}));
}
Aggregations