@Override public void close() throws Exception { CloseableSchedulerThreadPool.close(executor, logger); } };
/** * Creates a new scheduler service. * * The underlying executor uses a {@link ThreadPoolExecutor}, with a given pool size. * * @param corePoolSize -- the <b>maximum</b> number of threads used by the underlying {@link ThreadPoolExecutor} */ public LocalSchedulerService(int corePoolSize) { this(new CloseableSchedulerThreadPool(THREAD_NAME_PREFIX, corePoolSize)); }
@SuppressWarnings("resource") public AutoCloseableLock readLock() { return new AutoCloseableLock(readLock).open(); }
/** * Waits until it is safe to exit. Blocks until all currently running fragments have completed. * * <p>This is intended to be used by {@link com.dremio.exec.server.SabotNode#close()}.</p> */ public void waitToExit() { synchronized(this) { if (fragmentExecutors == null || fragmentExecutors.size() == 0) { return; } exitLatch = new ExtendedLatch(); } // Wait for at most 5 seconds or until the latch is released. exitLatch.awaitUninterruptibly(5000); }
public CloseableSchedulerThreadPool(String name, int corePoolSize) { super(corePoolSize, new NamedThreadFactory(name)); this.name = name; }
/** * Await without interruption. In the case of interruption, log a warning and continue to wait. */ public void awaitUninterruptibly() { while (true) { try { await(); return; } catch (final InterruptedException e) { // if we're still not ready, the while loop will cause us to wait again logger.warn("Interrupted while waiting for event latch.", e); } } } }
@Override public void close() { acl.close(); }
public void pause() { if (!injectNow()) { return; } latch.awaitUninterruptibly(); }
public void unpause() { latch.countDown(); } }
/** * schedules a thread that will asynchronously evict expired FragmentHandler from the cache. * First update will be scheduled after refreshDelayMs, and each subsequent update will start after * the previous update finishes + refreshDelayMs * * @param refreshDelayMs delay, in seconds, between successive eviction checks */ private void initEvictionThread(long refreshDelayMs) { scheduler.scheduleWithFixedDelay(new Runnable() { @Override public void run() { for (FragmentHandler handler : handlers.asMap().values()) { try { if (handler.isExpired()) { handlers.invalidate(handler.getHandle()); } } catch (Throwable e) { logger.warn("Failed to evict FragmentHandler for {}", QueryIdHelper.getQueryIdentifier(handler.getHandle()), e); } } } }, refreshDelayMs, refreshDelayMs, TimeUnit.MILLISECONDS); }
@Override public void close() { CloseableSchedulerThreadPool.close(this, logger); }
@SuppressWarnings("resource") AutoCloseableLock writeLock() { return new AutoCloseableLock(writeLock).open(); }
public CloseableThreadPool(String name) { super(0, Integer.MAX_VALUE, 60L, TimeUnit.SECONDS, new SynchronousQueue<Runnable>(), new NamedThreadFactory(name)); }
public void interruptiblePause() throws InterruptedException { if (!injectNow()) { return; } latch.await(); }
/** * If it is safe to exit, and the exitLatch is in use, signals it so that waitToExit() will * unblock. */ private void indicateIfSafeToExit() { synchronized(this) { if (exitLatch != null) { if (externalIdToForeman.isEmpty()) { exitLatch.countDown(); } } } }
@Override public void close() throws Exception { close(this, logger); }
@SuppressWarnings("resource") public AutoCloseableLock writeLock() { return new AutoCloseableLock(writeLock).open(); }
/** * If it is safe to exit, and the exitLatch is in use, signals it so that waitToExit() will * unblock. */ private void indicateIfSafeToExit() { synchronized(this) { if (exitLatch != null) { if (fragmentExecutors.size() == 0) { exitLatch.countDown(); } } } }
@Override public void close() throws Exception { LOGGER.info("Stopping SchedulerService"); executorService.close(); LOGGER.info("Stopped SchedulerService"); }
@SuppressWarnings("resource") AutoCloseableLock readLock() { return new AutoCloseableLock(readLock).open(); }