void complete(ReadEntryListener listener) { listener.onEntryComplete(rc, lh, entry, null); }
@Override public void run() { try { bookie.suspendProcessing(); l.await(); bookie.resumeProcessing(); } catch (Exception e) { LOG.error("Error suspending bookie", e); } } };
@Override public void readComplete(int rc, LedgerHandle lh, Enumeration<LedgerEntry> entries, Object ctx) { if (BKException.Code.NoSuchEntryException == rc) { callback.operationComplete(BKException.Code.OK, resultList); } else if (BKException.Code.OK == rc) { while (entries.hasMoreElements()) { resultList.add(entries.nextElement()); } long entryId = (Long) ctx; ++entryId; PendingReadOp readOp = new PendingReadOp(lh, lh.bk.scheduler, entryId, entryId, this, entryId); readOp.initiate(); } else { callback.operationComplete(rc, resultList); } } };
/** * Start a bookie with the given bookie instance. Also, starts the auto recovery for this bookie, if * isAutoRecoveryEnabled is true. */ protected BookieServer startBookie(ServerConfiguration conf, final Bookie b) throws Exception { BookieServer server = new BookieServer(conf) { @Override protected Bookie newBookie(ServerConfiguration conf) throws IOException, KeeperException, InterruptedException, BookieException { return b; } }; server.start(); int port = conf.getBookiePort(); while (bkc.getZkHandle().exists( "/ledgers/available/" + InetAddress.getLocalHost().getHostAddress() + ":" + port, false) == null) { Thread.sleep(500); } bkc.readBookiesBlocking(); LOG.info("New bookie on port " + port + " has been created."); return server; }
/** * Kill a bookie by its socket address. Also, stops the autorecovery process for the corresponding bookie server, if * isAutoRecoveryEnabled is true. * * @param addr * Socket Address * @return the configuration of killed bookie * @throws InterruptedException */ public ServerConfiguration killBookie(InetSocketAddress addr) throws Exception { BookieServer toRemove = null; int toRemoveIndex = 0; for (BookieServer server : bs) { if (server.getLocalAddress().equals(addr)) { server.shutdown(); toRemove = server; break; } ++toRemoveIndex; } if (toRemove != null) { stopAutoRecoveryService(toRemove); bs.remove(toRemove); return bsConfs.remove(toRemoveIndex); } return null; }
/** * Kill a bookie by index. Also, stops the respective auto recovery process for this bookie, if * isAutoRecoveryEnabled is true. * * @param index * Bookie Index * @return the configuration of killed bookie * @throws InterruptedException * @throws IOException */ public ServerConfiguration killBookie(int index) throws Exception { if (index >= bs.size()) { throw new IOException("Bookie does not exist"); } BookieServer server = bs.get(index); server.shutdown(); stopAutoRecoveryService(server); bs.remove(server); return bsConfs.remove(index); }
/** * Get bookie address for bookie at index */ public BookieSocketAddress getBookie(int index) throws Exception { if (bs.size() <= index || index < 0) { throw new IllegalArgumentException( "Invalid index, there are only " + bs.size() + " bookies. Asked for " + index); } return bs.get(index).getLocalAddress(); }
/** * Helper method to startup a bookie server using a configuration object. Also, starts the auto recovery process if * isAutoRecoveryEnabled is true. * * @param conf * Server Configuration Object * */ protected BookieServer startBookie(ServerConfiguration conf) throws Exception { BookieServer server = new BookieServer(conf); bsConfs.add(conf); bs.add(server); server.start(); if (bkc == null) { bkc = new BookKeeperTestClient(baseClientConf); } int port = conf.getBookiePort(); while (bkc.getZkHandle().exists( "/ledgers/available/" + InetAddress.getLocalHost().getHostAddress() + ":" + port, false) == null) { Thread.sleep(500); } bkc.readBookiesBlocking(); LOG.info("New bookie on port " + port + " has been created."); return server; }
/** * Stop cluster. Also, stops all the auto recovery processes for the bookie cluster, if isAutoRecoveryEnabled is * true. * * @throws Exception */ protected void stopBKCluster() throws Exception { if (bkc != null) { bkc.close(); } for (BookieServer server : bs) { server.shutdown(); AutoRecoveryMain autoRecovery = autoRecoveryProcesses.get(server); if (autoRecovery != null && isAutoRecoveryEnabled()) { autoRecovery.shutdown(); LOG.debug("Shutdown auto recovery for bookieserver:" + server.getLocalAddress()); } } bs.clear(); for (File f : tmpDirs) { FileUtils.deleteDirectory(f); } }
/** * Restart bookie servers using new configuration settings. Also restart the respective auto recovery process, if * isAutoRecoveryEnabled is true. * * @param newConf * New Configuration Settings * @throws InterruptedException * @throws IOException * @throws KeeperException * @throws BookieException */ public void restartBookies(ServerConfiguration newConf) throws Exception { // shut down bookie server for (BookieServer server : bs) { server.shutdown(); stopAutoRecoveryService(server); } bs.clear(); Thread.sleep(1000); // restart them to ensure we can't List<ServerConfiguration> bsConfsCopy = new ArrayList<ServerConfiguration>(bsConfs); bsConfs.clear(); for (ServerConfiguration conf : bsConfsCopy) { if (null != newConf) { conf.loadConf(newConf); } startBookie(conf); } }
@Override public void readLastConfirmedDataComplete(int rc, DigestManager.RecoveryData recoveryData) { if (BKException.Code.OK != rc) { callback.operationComplete(rc, resultList); return; } if (LedgerHandle.INVALID_ENTRY_ID >= recoveryData.lastAddConfirmed) { callback.operationComplete(BKException.Code.OK, resultList); return; } long entryId = recoveryData.lastAddConfirmed; PendingReadOp readOp = new PendingReadOp(lh, lh.bk.scheduler, entryId, entryId, readCallback, entryId); try { readOp.initiate(); } catch (Throwable t) { logger.error("Failed to initialize pending read entry {} for ledger {} : ", new Object[] { entryId, lh.getLedgerMetadata(), t }); } } };
readEntryListener.onEntryComplete(BKException.Code.OK, lh, entry, null);
@Override public void run() { try { bookie.suspendProcessing(); l.countDown(); Thread.sleep(seconds * 1000); bookie.resumeProcessing(); } catch (Exception e) { LOG.error("Error suspending bookie", e); } } };
private void stopAutoRecoveryService(BookieServer toRemove) throws Exception { AutoRecoveryMain autoRecoveryMain = autoRecoveryProcesses.remove(toRemove); if (null != autoRecoveryMain && isAutoRecoveryEnabled()) { autoRecoveryMain.shutdown(); LOG.debug("Shutdown auto recovery for bookieserver:" + toRemove.getLocalAddress()); } }
@Override public void operationComplete(int rc, List<LogSegmentMetadata> result) { long elapsedMicros = stopwatch.stop().elapsed(TimeUnit.MICROSECONDS); if (KeeperException.Code.OK.intValue() != rc) { getListStat.registerFailedEvent(elapsedMicros); } else { if (LogSegmentFilter.DEFAULT_FILTER == segmentFilter) { isFullListFetched.set(true); } getListStat.registerSuccessfulEvent(elapsedMicros); } finalCallback.operationComplete(rc, result); } };
/** * Will stops all the auto recovery processes for the bookie cluster, if isAutoRecoveryEnabled is true. */ public void stopReplicationService() throws Exception { if (false == isAutoRecoveryEnabled()) { return; } for (Entry<BookieServer, AutoRecoveryMain> autoRecoveryProcess : autoRecoveryProcesses.entrySet()) { autoRecoveryProcess.getValue().shutdown(); LOG.debug("Shutdown Auditor Recovery for the bookie:" + autoRecoveryProcess.getKey().getLocalAddress()); } } }
@Override public void readEntryComplete(int rc, long lid, long eid, ChannelBuffer buffer, Object ctx) { InetSocketAddress bookieAddress = (InetSocketAddress) ctx; ReadResult<Long> rr; if (BKException.Code.OK != rc) { rr = new ReadResult<Long>(eid, rc, null, bookieAddress); } else { try { DigestManager.RecoveryData data = lh.macManager.verifyDigestAndReturnLastConfirmed(buffer); rr = new ReadResult<Long>(eid, BKException.Code.OK, data.lastAddConfirmed, bookieAddress); } catch (BKException.BKDigestMatchException e) { rr = new ReadResult<Long>(eid, BKException.Code.DigestMatchException, null, bookieAddress); } } readResults.add(rr); if (numBookies.decrementAndGet() == 0) { callback.operationComplete(BKException.Code.OK, readResults); } } };
if (bookie.getLocalAddress().equals(addr)) { Thread sleeper = new Thread() { @Override
@Override public void readEntryComplete(int rc, long lid, long eid, ChannelBuffer buffer, Object ctx) { BookieSocketAddress bookieAddress = (BookieSocketAddress) ctx; ReadResult<InputStream> rr; if (BKException.Code.OK != rc) { rr = new ReadResult<InputStream>(eid, rc, null, bookieAddress.getSocketAddress()); } else { try { ChannelBufferInputStream is = lh.macManager.verifyDigestAndReturnData(eid, buffer); rr = new ReadResult<InputStream>(eid, BKException.Code.OK, is, bookieAddress.getSocketAddress()); } catch (BKException.BKDigestMatchException e) { rr = new ReadResult<InputStream>(eid, BKException.Code.DigestMatchException, null, bookieAddress.getSocketAddress()); } } readResults.add(rr); if (numBookies.decrementAndGet() == 0) { callback.operationComplete(BKException.Code.OK, readResults); } } };
if (bookie.getLocalAddress().equals(addr)) { final CountDownLatch l = new CountDownLatch(1); Thread sleeper = new Thread() {