use of io.druid.java.util.common.lifecycle.LifecycleStop in project druid by druid-io.
the class QuotableWhiteSpaceSplitter method stop.
@LifecycleStop
public void stop() {
stopping = true;
exec.shutdown();
synchronized (tasks) {
for (ForkingTaskRunnerWorkItem taskWorkItem : tasks.values()) {
if (taskWorkItem.processHolder != null) {
log.info("Closing output stream to task[%s].", taskWorkItem.getTask().getId());
try {
taskWorkItem.processHolder.process.getOutputStream().close();
} catch (Exception e) {
log.warn(e, "Failed to close stdout to task[%s]. Destroying task.", taskWorkItem.getTask().getId());
taskWorkItem.processHolder.process.destroy();
}
}
}
}
final DateTime start = new DateTime();
final long timeout = new Interval(start, taskConfig.getGracefulShutdownTimeout()).toDurationMillis();
// Things should be terminating now. Wait for it to happen so logs can be uploaded and all that good stuff.
log.info("Waiting up to %,dms for shutdown.", timeout);
if (timeout > 0) {
try {
final boolean terminated = exec.awaitTermination(timeout, TimeUnit.MILLISECONDS);
final long elapsed = System.currentTimeMillis() - start.getMillis();
if (terminated) {
log.info("Finished stopping in %,dms.", elapsed);
} else {
final Set<String> stillRunning;
synchronized (tasks) {
stillRunning = ImmutableSet.copyOf(tasks.keySet());
}
log.makeAlert("Failed to stop forked tasks").addData("stillRunning", stillRunning).addData("elapsed", elapsed).emit();
log.warn("Executor failed to stop after %,dms, not waiting for it! Tasks still running: [%s]", elapsed, Joiner.on("; ").join(stillRunning));
}
} catch (InterruptedException e) {
log.warn(e, "Interrupted while waiting for executor to finish.");
Thread.currentThread().interrupt();
}
} else {
log.warn("Ran out of time, not waiting for executor to finish!");
}
}
use of io.druid.java.util.common.lifecycle.LifecycleStop in project druid by druid-io.
the class RemoteTaskRunner method stop.
@Override
@LifecycleStop
public void stop() {
try {
if (!started) {
return;
}
started = false;
resourceManagement.stopManagement();
Closer closer = Closer.create();
for (ZkWorker zkWorker : zkWorkers.values()) {
closer.register(zkWorker);
}
closer.register(workerPathCache);
try {
closer.close();
} finally {
workerStatusPathChildrenCacheExecutor.shutdown();
}
if (runPendingTasksExec != null) {
runPendingTasksExec.shutdown();
}
} catch (Exception e) {
throw Throwables.propagate(e);
}
}
use of io.druid.java.util.common.lifecycle.LifecycleStop in project druid by druid-io.
the class Announcer method stop.
@LifecycleStop
public void stop() {
synchronized (toAnnounce) {
if (!started) {
return;
}
started = false;
Closer closer = Closer.create();
for (PathChildrenCache cache : listeners.values()) {
closer.register(cache);
}
try {
CloseQuietly.close(closer);
} finally {
pathChildrenCacheExecutor.shutdown();
}
for (Map.Entry<String, ConcurrentMap<String, byte[]>> entry : announcements.entrySet()) {
String basePath = entry.getKey();
for (String announcementPath : entry.getValue().keySet()) {
unannounce(ZKPaths.makePath(basePath, announcementPath));
}
}
if (!parentsIBuilt.isEmpty()) {
CuratorTransaction transaction = curator.inTransaction();
for (String parent : parentsIBuilt) {
try {
transaction = transaction.delete().forPath(parent).and();
} catch (Exception e) {
log.info(e, "Unable to delete parent[%s], boooo.", parent);
}
}
try {
((CuratorTransactionFinal) transaction).commit();
} catch (Exception e) {
log.info(e, "Unable to commit transaction. Please feed the hamsters");
}
}
}
}
use of io.druid.java.util.common.lifecycle.LifecycleStop in project druid by druid-io.
the class CuratorInventoryManager method stop.
@LifecycleStop
public void stop() throws IOException {
synchronized (lock) {
if (childrenCache == null) {
return;
}
// This close() call actually calls shutdownNow() on the executor registered with the Cache object...
childrenCache.close();
childrenCache = null;
}
Closer closer = Closer.create();
for (ContainerHolder containerHolder : containers.values()) {
closer.register(containerHolder.getCache());
}
try {
closer.close();
} finally {
pathChildrenCacheExecutor.shutdown();
}
}
use of io.druid.java.util.common.lifecycle.LifecycleStop in project druid by druid-io.
the class LookupCoordinatorManager method stop.
@LifecycleStop
public void stop() {
synchronized (startStopSync) {
if (!started) {
LOG.warn("Not started, ignoring stop request");
return;
}
started = false;
executorService.shutdownNow();
final ListenableScheduledFuture backgroundManagerFuture = this.backgroundManagerFuture;
this.backgroundManagerFuture = null;
if (backgroundManagerFuture != null && !backgroundManagerFuture.cancel(true)) {
LOG.warn("Background lookup manager thread could not be cancelled");
}
// NOTE: we can't un-watch the configuration key
LOG.debug("Stopped");
}
}
Aggregations