/** * Return the bk exception return code for a <i>throwable</i>. * * @param throwable the cause of the exception * @return the bk exception return code. if the exception isn't bk exceptions, * it would return bk exception code. */ public static int bkResultCode(Throwable throwable) { if (throwable instanceof BKException) { return ((BKException)throwable).getCode(); } return BKException.Code.UnexpectedConditionException; }
@Override public void run() { while (!ledgers.isEmpty()) { long lid = -1L; try { lid = ledgers.take(); System.out.println("Recovering ledger " + lid); bkAdmin.recoverBookieData(lid, bookieAddrs, dryrun, skipOpenLedgers); System.out.println("Recovered ledger completed : " + lid + ", " + numPendings.decrementAndGet() + " left"); } catch (InterruptedException e) { Thread.currentThread().interrupt(); doneLatch.countDown(); break; } catch (BKException ke) { System.out.println("Recovered ledger failed : " + lid + ", rc = " + BKException.getMessage(ke.getCode())); } } doneLatch.countDown(); } };
private boolean closeCurrentLedgerHandle() { if (currentLH == null) { return true; } boolean retVal = false; LedgerDescriptor ld = currentLH; try { handleCache.closeLedger(ld); currentLH = null; retVal = true; } catch (BKException bke) { LOG.debug("BK Exception during closing {} : ", ld, bke); handleException(ReadAheadPhase.CLOSE_LEDGER, bke.getCode()); } return retVal; }
static int getExceptionCode(Throwable t) { if (t instanceof BKException) { return ((BKException) t).getCode(); } else if (t.getCause() != null) { return getExceptionCode(t.getCause()); } else { return BKException.Code.UnexpectedConditionException; } }
/** * Wait for the result for a given <i>duration</i>. * <p>If the result is not ready within `duration`, an IOException will thrown wrapping with * corresponding {@link com.twitter.util.TimeoutException}. * * @param result result to wait * @param duration duration to wait * @return the result * @throws IOException when encountered exceptions on the result or waiting for the result. */ public static <T> T result(Future<T> result, Duration duration) throws IOException { try { return Await.result(result, duration); } catch (KeeperException ke) { throw new ZKException("Encountered zookeeper exception on waiting result", ke); } catch (BKException bke) { throw new BKTransmitException("Encountered bookkeeper exception on waiting result", bke.getCode()); } catch (IOException ioe) { throw ioe; } catch (InterruptedException ie) { throw new DLInterruptedException("Interrupted on waiting result", ie); } catch (Exception e) { throw new IOException("Encountered exception on waiting result", e); } }
@Override void process(int rc) { if (!running) { setReadAheadStopped(); return; } tracker.enterPhase(ReadAheadPhase.READ_ENTRIES); cacheFull = false; lastAddConfirmed = -1; if (null != currentLH) { try { lastAddConfirmed = handleCache.getLastAddConfirmed(currentLH); } catch (BKException bke) { handleException(ReadAheadPhase.READ_LAST_CONFIRMED, bke.getCode()); return; } read(); } else { complete(); } }
/** * Extract an exception code from an BKException, or use a default if it's another type. * The throwable is null, assume that no exception took place and return * {@link BKException.Code.OK}. */ public static int getExceptionCode(Throwable t, int defaultCode) { if (t == null) { return BKException.Code.OK; } else if (t instanceof BKException) { return ((BKException) t).getCode(); } else if (t.getCause() != null) { return getExceptionCode(t.getCause(), defaultCode); } else { return defaultCode; } }
@Override public void onFailure(Throwable cause) { if (cause instanceof BKException) { BKException bke = (BKException) cause; cb.readComplete(bke.getCode(), LedgerHandle.this, null, ctx); } else { cb.readComplete(Code.UnexpectedConditionException, LedgerHandle.this, null, ctx); } } }, clientCtx.getMainWorkerPool().chooseThread(ledgerId));
@Override public void onFailure(Throwable throwable) { if (throwable instanceof BKNoSuchEntryException) { callback.operationComplete(Code.OK, resultList); } else { int retCode; if (throwable instanceof BKException) { retCode = ((BKException) throwable).getCode(); } else { retCode = Code.UnexpectedConditionException; } callback.operationComplete(retCode, resultList); } } };
/** * A specific version of {@link FutureUtils#result(CompletableFuture)} to handle known exception issues. */ public static <T> T ioResult(CompletableFuture<T> result) throws IOException { return FutureUtils.result( result, (cause) -> { if (cause instanceof IOException) { return (IOException) cause; } else if (cause instanceof KeeperException) { return new ZKException("Encountered zookeeper exception on waiting result", (KeeperException) cause); } else if (cause instanceof BKException) { return new BKTransmitException("Encountered bookkeeper exception on waiting result", ((BKException) cause).getCode()); } else if (cause instanceof InterruptedException) { return new DLInterruptedException("Interrupted on waiting result", cause); } else { return new IOException("Encountered exception on waiting result", cause); } }); }
/** * A specific version of {@link FutureUtils#result(CompletableFuture, long, TimeUnit)} * to handle known exception issues. */ public static <T> T ioResult(CompletableFuture<T> result, long timeout, TimeUnit timeUnit) throws IOException, TimeoutException { return FutureUtils.result( result, (cause) -> { if (cause instanceof IOException) { return (IOException) cause; } else if (cause instanceof KeeperException) { return new ZKException("Encountered zookeeper exception on waiting result", (KeeperException) cause); } else if (cause instanceof BKException) { return new BKTransmitException("Encountered bookkeeper exception on waiting result", ((BKException) cause).getCode()); } else if (cause instanceof InterruptedException) { return new DLInterruptedException("Interrupted on waiting result", cause); } else { return new IOException("Encountered exception on waiting result", cause); } }, timeout, timeUnit); }
private void replicateLedgerFragment(LedgerHandle lh, final LedgerFragment ledgerFragment, final Map<Integer, BookieSocketAddress> targetBookieAddresses) throws InterruptedException, BKException { CompletableFuture<Void> result = new CompletableFuture<>(); ResultCallBack resultCallBack = new ResultCallBack(result); SingleFragmentCallback cb = new SingleFragmentCallback( resultCallBack, lh, bkc.getLedgerManager(), ledgerFragment.getFirstEntryId(), getReplacementBookiesMap(ledgerFragment, targetBookieAddresses)); Set<BookieSocketAddress> targetBookieSet = Sets.newHashSet(); targetBookieSet.addAll(targetBookieAddresses.values()); asyncRecoverLedgerFragment(lh, ledgerFragment, cb, targetBookieSet); try { SyncCallbackUtils.waitForResult(result); } catch (BKException err) { throw BKException.create(bkc.getReturnRc(err.getCode())); } }
result(ledgerManager.readLedgerMetadata(bkLid)); } catch (BKException e) { rc = e.getCode();