@AfterClass public void tearDownClass() throws Exception { executor.shutdown(); cachedExecutor.shutdown(); }
@BeforeClass void setup() throws Exception { OrderedScheduler executor = OrderedScheduler.newSchedulerBuilder().numThreads(1).build(); ml1 = mock(ManagedLedgerImpl.class); when(ml1.getScheduledExecutor()).thenReturn(executor); when(ml1.getName()).thenReturn("cache1"); ml2 = mock(ManagedLedgerImpl.class); when(ml2.getScheduledExecutor()).thenReturn(executor); when(ml2.getName()).thenReturn("cache2"); }
/** * Start cluster * * @throws Exception */ protected void startBookKeeper() throws Exception { zkc = MockZooKeeper.newInstance(); for (int i = 0; i < numBookies; i++) { ZkUtils.createFullPathOptimistic(zkc, "/ledgers/available/192.168.1.1:" + (5000 + i), "".getBytes(), null, null); } zkc.create("/ledgers/LAYOUT", "1\nflat:1".getBytes(), null, null); bkc = new PulsarMockBookKeeper(zkc, executor.chooseThread(this)); }
private ManagedLedgerFactoryImpl(BookKeeper bookKeeper, boolean isBookkeeperManaged, ZooKeeper zooKeeper, ManagedLedgerFactoryConfig config) throws Exception { scheduledExecutor = OrderedScheduler.newSchedulerBuilder() .numThreads(config.getNumManagedLedgerSchedulerThreads()) .name("bookkeeper-ml-scheduler") .build(); orderedExecutor = OrderedExecutor.newBuilder() .numThreads(config.getNumManagedLedgerWorkerThreads()) .name("bookkeeper-ml-workers") .build(); this.bookKeeper = bookKeeper; this.isBookkeeperManaged = isBookkeeperManaged; this.zookeeper = isBookkeeperManaged ? zooKeeper : null; this.store = new MetaStoreImplZookeeper(zooKeeper, orderedExecutor); this.config = config; this.mbean = new ManagedLedgerFactoryMBeanImpl(this); this.entryCacheManager = new EntryCacheManager(this); this.statsTask = scheduledExecutor.scheduleAtFixedRate(() -> refreshStats(), 0, StatsPeriodSeconds, TimeUnit.SECONDS); }
new ThreadFactoryBuilder().setNameFormat("compaction-%d").setDaemon(true).build()); OrderedScheduler executor = OrderedScheduler.newSchedulerBuilder().build(); ZooKeeperClientFactory zkClientFactory = new ZookeeperBkClientFactoryImpl(executor); zk.close(); scheduler.shutdownNow(); executor.shutdown();
/** * {@inheritDoc} */ @Override public ScheduledFuture<?> scheduleWithFixedDelay(Runnable command, long initialDelay, long delay, TimeUnit unit) { return chooseThread().scheduleWithFixedDelay(timedRunnable(command), initialDelay, delay, unit); }
scheduler.shutdown(); if (!scheduler.awaitTermination(10, TimeUnit.SECONDS)) { LOG.warn("The scheduler did not shutdown cleanly");
private void scheduleDeferredTrimming(CompletableFuture<?> promise) { scheduledExecutor.schedule(safeRun(() -> trimConsumedLedgersInBackground(promise)), 100, TimeUnit.MILLISECONDS); }
executor.submit(safeRun(() -> { try { cursor.asyncDelete(addedEntries.get(iteration.getAndIncrement()), new DeleteCallback() {
@Override public CompletableFuture<Void> asyncClose() { final CompletableFuture<Void> closePromise; synchronized (this) { if (closed) { return closeFuture; } closed = true; closeFuture = closePromise = new CompletableFuture<Void>(); } final CompletableFuture<Void> closeWaiterFuture = new CompletableFuture<Void>(); closeWaiterFuture.whenCompleteAsync(new FutureEventListener<Void>() { @Override public void onSuccess(Void value) { complete(); } @Override public void onFailure(Throwable cause) { complete(); } private void complete() { FutureUtils.complete(closePromise, null); } }, lockStateExecutor.chooseThread(lockPath)); lockStateExecutor.executeOrdered( lockPath, () -> closeWaiter(lockWaiter, closeWaiterFuture)); return closePromise; }
/** * {@inheritDoc} */ @Override public <V> ScheduledFuture<V> schedule(Callable<V> callable, long delay, TimeUnit unit) { return chooseThread().schedule(timedCallable(callable), delay, unit); }
@Override public void processResult(final int rc, final String path, Object ctx) { lockStateExecutor.executeOrdered(lockPath, new SafeRunnable() { @Override public void safeRun() { if (KeeperException.Code.OK.intValue() == rc) { LOG.info("Deleted lock node {} for {} successfully.", path, lockId); } else if (KeeperException.Code.NONODE.intValue() == rc || KeeperException.Code.SESSIONEXPIRED.intValue() == rc) { LOG.info("Delete node failed. Node already gone for node {} id {}, rc = {}", new Object[] { path, lockId, KeeperException.Code.get(rc) }); } else { LOG.error("Failed on deleting lock node {} for {} : {}", new Object[] { path, lockId, KeeperException.Code.get(rc) }); } FailpointUtils.checkFailPointNoThrow(FailpointUtils.FailPointName.FP_LockUnlockCleanup); promise.complete(null); } }); } }, null);
private void scheduleTimeoutTask() { long timeoutSec = config.getAddEntryTimeoutSeconds(); // disable timeout task checker if timeout <= 0 if (timeoutSec > 0) { this.timeoutTask = this.scheduledExecutor.scheduleAtFixedRate(() -> { OpAddEntry opAddEntry = pendingAddEntries.peek(); if (opAddEntry != null) { boolean isTimedOut = opAddEntry.lastInitTime != -1 && TimeUnit.NANOSECONDS.toSeconds(System.nanoTime() - opAddEntry.lastInitTime) >= timeoutSec && opAddEntry.completed == FALSE; if (isTimedOut) { log.error("Failed to add entry for ledger {} in time-out {} sec", (opAddEntry.ledger != null ? opAddEntry.ledger.getId() : -1), timeoutSec); opAddEntry.handleAddFailure(opAddEntry.ledger); } } }, config.getAddEntryTimeoutSeconds(), config.getAddEntryTimeoutSeconds(), TimeUnit.SECONDS); } }
/** * {@inheritDoc} */ @Override public ScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit) { return chooseThread().schedule(timedRunnable(command), delay, unit); }
private ManagedLedgerFactoryImpl(BookKeeper bookKeeper, boolean isBookkeeperManaged, ZooKeeper zooKeeper, ManagedLedgerFactoryConfig config) throws Exception { scheduledExecutor = OrderedScheduler.newSchedulerBuilder() .numThreads(config.getNumManagedLedgerSchedulerThreads()) .name("bookkeeper-ml-scheduler") .build(); orderedExecutor = OrderedExecutor.newBuilder() .numThreads(config.getNumManagedLedgerWorkerThreads()) .name("bookkeeper-ml-workers") .build(); this.bookKeeper = bookKeeper; this.isBookkeeperManaged = isBookkeeperManaged; this.zookeeper = isBookkeeperManaged ? zooKeeper : null; this.store = new MetaStoreImplZookeeper(zooKeeper, orderedExecutor); this.config = config; this.mbean = new ManagedLedgerFactoryMBeanImpl(this); this.entryCacheManager = new EntryCacheManager(this); this.statsTask = scheduledExecutor.scheduleAtFixedRate(() -> refreshStats(), 0, StatsPeriodSeconds, TimeUnit.SECONDS); }
private void updateLedgersListAfterRollover(MetaStoreCallback<Void> callback) { if (!ledgersListMutex.tryLock()) { // Defer update for later scheduledExecutor.schedule(() -> updateLedgersListAfterRollover(callback), 100, TimeUnit.MILLISECONDS); return; } if (log.isDebugEnabled()) { log.debug("[{}] Updating ledgers ids with new ledger. version={}", name, ledgersStat); } store.asyncUpdateLedgerIds(name, getManagedLedgerInfo(), ledgersStat, callback); }
final CompletableFuture<URI> createPromise) { scheduler.submit(new Runnable() { @Override public void run() {
private void orderedSubmit(SafeRunnable runnable) { synchronized (this) { if (null != closePromise) { return; } } try { scheduler.executeOrdered(streamName, runnable); } catch (RejectedExecutionException ree) { logger.debug("Failed to submit and execute an operation for readhead entry reader of {}", streamName, ree); } }
void scheduleBookieHealthCheckIfEnabled(ClientConfiguration conf) { if (conf.isBookieHealthCheckEnabled()) { scheduler.scheduleAtFixedRate(new SafeRunnable() { @Override public void safeRun() { checkForFaultyBookies(); } }, conf.getBookieHealthCheckIntervalSeconds(), conf.getBookieHealthCheckIntervalSeconds(), TimeUnit.SECONDS); } }
scheduledExecutor.shutdown(); orderedExecutor.shutdown();