} catch (ZooKeeperClient.ZooKeeperConnectionException e) { getListStat.registerFailedEvent(stopwatch.stop().elapsed(TimeUnit.MICROSECONDS)); finalCallback.operationComplete(KeeperException.Code.CONNECTIONLOSS.intValue(), null); } catch (InterruptedException e) { getListStat.registerFailedEvent(stopwatch.stop().elapsed(TimeUnit.MICROSECONDS)); finalCallback.operationComplete(KeeperException.Code.CONNECTIONLOSS.intValue(), null);
pendingOp.operationComplete(rc, PerChannelBookieClient.this);
callback.operationComplete(rc, resultList); return; callback.operationComplete(BKException.Code.OK, resultList); return;
throw new InvalidFragmentException(); cb.operationComplete(BKException.Code.OK, fragment); } else if (firstStored == lastStored) { ReadManyEntriesCallback manycb = new ReadManyEntriesCallback(1, } else { if (lastStored <= firstStored) { cb.operationComplete(Code.IncorrectParameterException, null); return;
pendingOp.operationComplete(rc, PerChannelBookieClient.this);
.whenComplete((ignore, ex) -> { if (ex != null) { cb.operationComplete( BKException.getExceptionCode(ex, BKException.Code.UnexpectedConditionException), null); } else { cb.operationComplete(BKException.Code.OK, null);
cb.operationComplete(BKException.Code.ZKException, null); } catch (InterruptedException e) { Thread.currentThread().interrupt(); LOG.error("Failed to create long ledger ID path", e); cb.operationComplete(BKException.Code.InterruptedException, null); } catch (IOException e) { LOG.error("Failed to create long ledger ID path", e); cb.operationComplete(BKException.Code.IllegalOpException, null);
LOG.info("LedgerReplication is enabled externally through Zookeeper, " + "since DISABLE_NODE ZNode is deleted"); cb.operationComplete(0, null); return;
LOG.error("Could not generate new ledger id", KeeperException.create(KeeperException.Code.get(rc), path)); cb.operationComplete(BKException.Code.ZKException, null); return; ledgerId = getLedgerIdFromGenPath(idPathName, ledgerPrefix); if (ledgerId < 0 || ledgerId >= Integer.MAX_VALUE) { cb.operationComplete(BKException.Code.LedgerIdOverflowException, null); } else { cb.operationComplete(BKException.Code.OK, ledgerId); cb.operationComplete(BKException.Code.ZKException, null); return;
callback.operationComplete(BKException.Code.OK, readResults);
/** * Verify a ledger fragment to collect bad bookies. * * @param fragment * fragment to verify * @param cb * callback * @throws InvalidFragmentException */ private void verifyLedgerFragment(LedgerFragment fragment, GenericCallback<LedgerFragment> cb, Long percentageOfLedgerFragmentToBeVerified) throws InvalidFragmentException, BKException { Set<Integer> bookiesToCheck = fragment.getBookiesIndexes(); if (bookiesToCheck.isEmpty()) { cb.operationComplete(BKException.Code.OK, fragment); return; } AtomicInteger numBookies = new AtomicInteger(bookiesToCheck.size()); Map<Integer, Integer> badBookies = new HashMap<Integer, Integer>(); for (Integer bookieIndex : bookiesToCheck) { LedgerFragmentCallback lfCb = new LedgerFragmentCallback( fragment, bookieIndex, cb, badBookies, numBookies); verifyLedgerFragment(fragment, bookieIndex, lfCb, percentageOfLedgerFragmentToBeVerified); } }
@Override public void readEntryComplete(int rc, long lid, long eid, ByteBuf buffer, Object ctx) { BookieSocketAddress bookieAddress = (BookieSocketAddress) ctx; ReadResult<ByteBuf> rr; if (BKException.Code.OK != rc) { rr = new ReadResult<>(eid, rc, null, bookieAddress.getSocketAddress()); } else { ByteBuf content; try { content = lh.macManager.verifyDigestAndReturnData(eid, buffer); ByteBuf toRet = Unpooled.copiedBuffer(content); rr = new ReadResult<>(eid, BKException.Code.OK, toRet, bookieAddress.getSocketAddress()); } catch (BKException.BKDigestMatchException e) { rr = new ReadResult<>( eid, BKException.Code.DigestMatchException, null, bookieAddress.getSocketAddress()); } finally { buffer.release(); } } readResults.add(rr); if (numBookies.decrementAndGet() == 0) { callback.operationComplete(BKException.Code.OK, readResults); } } };
private void checkFragments(Set<LedgerFragment> fragments, GenericCallback<Set<LedgerFragment>> cb, long percentageOfLedgerFragmentToBeVerified) { if (fragments.size() == 0) { // no fragments to verify cb.operationComplete(BKException.Code.OK, fragments); return; } // verify all the collected fragment replicas FullLedgerCallback allFragmentsCb = new FullLedgerCallback(fragments .size(), cb); for (LedgerFragment r : fragments) { LOG.debug("Checking fragment {}", r); try { verifyLedgerFragment(r, allFragmentsCb, percentageOfLedgerFragmentToBeVerified); } catch (InvalidFragmentException ife) { LOG.error("Invalid fragment found : {}", r); allFragmentsCb.operationComplete( BKException.Code.IncorrectParameterException, r); } catch (BKException e) { LOG.error("BKException when checking fragment : {}", r, e); } } }
@Override public void notifyLostBookieRecoveryDelayChanged(GenericCallback<Void> cb) throws UnavailableException { LOG.debug("notifyLostBookieRecoveryDelayChanged()"); Watcher w = new Watcher() { public void process(WatchedEvent e) { if (e.getType() == Watcher.Event.EventType.NodeDataChanged) { cb.operationComplete(0, null); } } }; try { if (null == zkc.exists(lostBookieRecoveryDelayZnode, w)) { cb.operationComplete(0, null); return; } } catch (KeeperException ke) { LOG.error("Error while checking the state of lostBookieRecoveryDelay", ke); throw new ReplicationException.UnavailableException("Error contacting zookeeper", ke); } catch (InterruptedException ie) { Thread.currentThread().interrupt(); throw new ReplicationException.UnavailableException("Interrupted while contacting zookeeper", ie); } }
@Override public void operationComplete(int rc, Long result) { if (rc == BKException.Code.OK) { assert((highBits & 0xFFFFFFFF00000000L) == 0); assert((result & 0xFFFFFFFF00000000L) == 0); cb.operationComplete(rc, (highBits << 32) | result); } else if (rc == BKException.Code.LedgerIdOverflowException) { // Lower bits are full. Need to expand and create another HOB node. try { Long newHighBits = highBits + 1; createHOBPathAndGenerateId(ledgerPrefix, newHighBits.intValue(), cb); } catch (KeeperException e) { LOG.error("Failed to create long ledger ID path", e); cb.operationComplete(BKException.Code.ZKException, null); } catch (InterruptedException e) { Thread.currentThread().interrupt(); LOG.error("Failed to create long ledger ID path", e); cb.operationComplete(BKException.Code.InterruptedException, null); } catch (IOException e) { LOG.error("Failed to create long ledger ID path", e); cb.operationComplete(BKException.Code.IllegalOpException, null); } } else { LOG.error("Failed to create long ledger ID path", KeeperException.create(KeeperException.Code.get(rc))); cb.operationComplete(BKException.Code.ZKException, null); } }
@Override public void processResult(int rc, String path, Object ctx) { if (rc != Code.OK.intValue()) { LOG.error("ZK error syncing nodes when getting children: ", KeeperException .create(KeeperException.Code.get(rc), path)); cb.operationComplete(rc, null); return; } zk.getChildren(node, false, new AsyncCallback.ChildrenCallback() { @Override public void processResult(int rc, String path, Object ctx, List<String> nodes) { if (rc != Code.OK.intValue()) { LOG.error("Error polling ZK for the available nodes: ", KeeperException .create(KeeperException.Code.get(rc), path)); cb.operationComplete(rc, null); return; } cb.operationComplete(rc, nodes); } }, null); } }, null);
@Override @SuppressWarnings("unchecked") public void close() throws IOException { Set<GenericCallback> keys; closeLock.writeLock().lock(); try { if (closed) { return; } closed = true; keys = new HashSet<GenericCallback>(callbacks.keySet()); } finally { closeLock.writeLock().unlock(); } for (GenericCallback key : keys) { GenericCallback callback = callbacks.remove(key); if (null != callback) { callback.operationComplete(BKException.Code.ClientClosedException, null); } } BKException exception = new BKException.BKClientClosedException(); futures.forEach((f) -> f.completeExceptionally(exception)); futures.clear(); underlying.close(); }
@Override public void operationComplete(int rc, LedgerFragment lf) { if (BKException.Code.OK != rc) { synchronized (badBookies) { badBookies.put(bookieIndex, rc); } } if (numBookies.decrementAndGet() == 0) { if (badBookies.isEmpty()) { cb.operationComplete(BKException.Code.OK, fragment); } else { int rcToReturn = BKException.Code.NoBookieAvailableException; for (Map.Entry<Integer, Integer> entry : badBookies.entrySet()) { rcToReturn = entry.getValue(); if (entry.getValue() == BKException.Code.ClientClosedException) { break; } } cb.operationComplete(rcToReturn, fragment.subset(badBookies.keySet())); } } } }
@Override public void processResult(int rc, String path, Object ctx, String name) { try { setLedgerIdGenPathStatus(HighOrderLedgerIdGenPathStatus.PRESENT); generateLongLedgerId(cb); } catch (KeeperException e) { LOG.error("Failed to create long ledger ID path", e); setLedgerIdGenPathStatus(HighOrderLedgerIdGenPathStatus.UNKNOWN); cb.operationComplete(BKException.Code.ZKException, null); } catch (InterruptedException e) { Thread.currentThread().interrupt(); LOG.error("Failed to create long ledger ID path", e); setLedgerIdGenPathStatus(HighOrderLedgerIdGenPathStatus.UNKNOWN); cb.operationComplete(BKException.Code.InterruptedException, null); } catch (IOException e) { LOG.error("Failed to create long ledger ID path", e); setLedgerIdGenPathStatus(HighOrderLedgerIdGenPathStatus.UNKNOWN); cb.operationComplete(BKException.Code.IllegalOpException, null); } } }, null);
/** * Errors out pending ops from per channel bookie client. As the channel * is being closed, all the operations waiting on the connection * will be sent to completion with error. */ void errorOutPendingOps(int rc) { Queue<GenericCallback<PerChannelBookieClient>> oldPendingOps; synchronized (this) { oldPendingOps = pendingOps; pendingOps = new ArrayDeque<>(); } for (GenericCallback<PerChannelBookieClient> pendingOp : oldPendingOps) { pendingOp.operationComplete(rc, PerChannelBookieClient.this); } }