use of org.apache.druid.java.util.common.lifecycle.LifecycleStop in project druid by druid-io.
the class LookupReferencesManager method stop.
@LifecycleStop
public void stop() {
if (!lifecycleLock.canStop()) {
throw new ISE("can't stop.");
}
LOG.debug("LookupExtractorFactoryContainerProvider is stopping.");
if (!testMode) {
mainThread.interrupt();
try {
mainThread.join();
} catch (InterruptedException ex) {
throw new ISE("failed to stop, mainThread couldn't finish.");
}
}
for (Map.Entry<String, LookupExtractorFactoryContainer> e : stateRef.get().lookupMap.entrySet()) {
try {
if (e.getValue().getLookupExtractorFactory().close()) {
LOG.info("Closed lookup [%s].", e.getKey());
} else {
LOG.error("Failed to close lookup [%s].", e.getKey());
}
} catch (Exception ex) {
LOG.error(ex, "Failed to close lookup [%s].", e.getKey());
}
}
LOG.debug("LookupExtractorFactoryContainerProvider is stopped.");
}
use of org.apache.druid.java.util.common.lifecycle.LifecycleStop in project druid by druid-io.
the class CuratorDruidNodeDiscoveryProvider method stop.
@LifecycleStop
public void stop() throws IOException {
if (!lifecycleLock.canStop()) {
throw new ISE("can't stop.");
}
log.debug("Stopping.");
Closer closer = Closer.create();
closer.registerAll(nodeRoleWatchers.values());
closer.registerAll(nodeDiscoverers);
CloseableUtils.closeAll(closer, listenerExecutor::shutdownNow);
}
use of org.apache.druid.java.util.common.lifecycle.LifecycleStop in project druid by druid-io.
the class QuotableWhiteSpaceSplitter method stop.
@Override
@LifecycleStop
public void stop() {
stopping = true;
exec.shutdown();
synchronized (tasks) {
for (ForkingTaskRunnerWorkItem taskWorkItem : tasks.values()) {
shutdownTaskProcess(taskWorkItem);
}
}
final DateTime start = DateTimes.nowUtc();
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.
LOGGER.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) {
LOGGER.info("Finished stopping in %,dms.", elapsed);
} else {
final Set<String> stillRunning;
synchronized (tasks) {
stillRunning = ImmutableSet.copyOf(tasks.keySet());
}
LOGGER.makeAlert("Failed to stop forked tasks").addData("stillRunning", stillRunning).addData("elapsed", elapsed).emit();
LOGGER.warn("Executor failed to stop after %,dms, not waiting for it! Tasks still running: [%s]", elapsed, Joiner.on("; ").join(stillRunning));
}
} catch (InterruptedException e) {
LOGGER.warn(e, "Interrupted while waiting for executor to finish.");
Thread.currentThread().interrupt();
}
} else {
LOGGER.warn("Ran out of time, not waiting for executor to finish!");
}
}
use of org.apache.druid.java.util.common.lifecycle.LifecycleStop in project druid by druid-io.
the class SingleTaskBackgroundRunner method stop.
@Override
@LifecycleStop
public void stop() {
stopping = true;
if (executorService != null) {
try {
executorService.shutdown();
} catch (SecurityException ex) {
log.error(ex, "I can't control my own threads!");
}
}
if (runningItem != null) {
final Task task = runningItem.getTask();
final long start = System.currentTimeMillis();
final long elapsed;
boolean error = false;
// stopGracefully for resource cleaning
log.info("Starting graceful shutdown of task[%s].", task.getId());
task.stopGracefully(taskConfig);
if (taskConfig.isRestoreTasksOnRestart() && task.canRestore()) {
try {
final TaskStatus taskStatus = runningItem.getResult().get(new Interval(DateTimes.utc(start), taskConfig.getGracefulShutdownTimeout()).toDurationMillis(), TimeUnit.MILLISECONDS);
// Ignore status, it doesn't matter for graceful shutdowns.
log.info("Graceful shutdown of task[%s] finished in %,dms.", task.getId(), System.currentTimeMillis() - start);
TaskRunnerUtils.notifyStatusChanged(listeners, task.getId(), taskStatus);
} catch (Exception e) {
log.makeAlert(e, "Graceful task shutdown failed: %s", task.getDataSource()).addData("taskId", task.getId()).addData("dataSource", task.getDataSource()).emit();
log.warn(e, "Graceful shutdown of task[%s] aborted with exception.", task.getId());
error = true;
// Creating a new status to only feed listeners seems quite strange.
// This is currently OK because we have no listeners yet registered in peon.
// However, we should fix this in the near future by always retrieving task status
// from one single source of truth that is also propagated to the overlord.
// See https://github.com/apache/druid/issues/11445.
TaskRunnerUtils.notifyStatusChanged(listeners, task.getId(), TaskStatus.failure(task.getId(), "Failed to stop gracefully with exception. See task logs for more details."));
}
} else {
// Creating a new status to only feed listeners seems quite strange.
// This is currently OK because we have no listeners yet registered in peon.
// However, we should fix this in the near future by always retrieving task status
// from one single source of truth that is also propagated to the overlord.
// See https://github.com/apache/druid/issues/11445.
TaskRunnerUtils.notifyStatusChanged(listeners, task.getId(), TaskStatus.failure(task.getId(), "Canceled as task execution process stopped"));
}
elapsed = System.currentTimeMillis() - start;
final ServiceMetricEvent.Builder metricBuilder = ServiceMetricEvent.builder().setDimension("task", task.getId()).setDimension("dataSource", task.getDataSource()).setDimension("graceful", // for backward compatibility
"true").setDimension("error", String.valueOf(error));
emitter.emit(metricBuilder.build("task/interrupt/count", 1L));
emitter.emit(metricBuilder.build("task/interrupt/elapsed", elapsed));
}
// Ok, now interrupt everything.
if (executorService != null) {
try {
executorService.shutdownNow();
} catch (SecurityException ex) {
log.error(ex, "I can't control my own threads!");
}
}
}
use of org.apache.druid.java.util.common.lifecycle.LifecycleStop in project druid by druid-io.
the class SupervisorManager method stop.
@LifecycleStop
public void stop() {
Preconditions.checkState(started, "SupervisorManager not started");
synchronized (lock) {
for (String id : supervisors.keySet()) {
try {
supervisors.get(id).lhs.stop(false);
SupervisorTaskAutoScaler autoscaler = autoscalers.get(id);
if (autoscaler != null) {
autoscaler.stop();
}
} catch (Exception e) {
log.warn(e, "Caught exception while stopping supervisor [%s]", id);
}
}
supervisors.clear();
autoscalers.clear();
started = false;
}
log.info("SupervisorManager stopped.");
}
Aggregations