Search in sources :

Example 1 with LifecycleStop

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.");
}
Also used : ISE(org.apache.druid.java.util.common.ISE) HashMap(java.util.HashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) AbstractMap(java.util.AbstractMap) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) LifecycleStop(org.apache.druid.java.util.common.lifecycle.LifecycleStop)

Example 2 with LifecycleStop

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);
}
Also used : Closer(org.apache.druid.java.util.common.io.Closer) ISE(org.apache.druid.java.util.common.ISE) LifecycleStop(org.apache.druid.java.util.common.lifecycle.LifecycleStop)

Example 3 with LifecycleStop

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!");
    }
}
Also used : DateTime(org.joda.time.DateTime) Interval(org.joda.time.Interval) LifecycleStop(org.apache.druid.java.util.common.lifecycle.LifecycleStop)

Example 4 with LifecycleStop

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!");
        }
    }
}
Also used : Task(org.apache.druid.indexing.common.task.Task) ServiceMetricEvent(org.apache.druid.java.util.emitter.service.ServiceMetricEvent) TaskStatus(org.apache.druid.indexer.TaskStatus) Interval(org.joda.time.Interval) LifecycleStop(org.apache.druid.java.util.common.lifecycle.LifecycleStop)

Example 5 with LifecycleStop

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.");
}
Also used : SupervisorTaskAutoScaler(org.apache.druid.indexing.overlord.supervisor.autoscaler.SupervisorTaskAutoScaler) LifecycleStop(org.apache.druid.java.util.common.lifecycle.LifecycleStop)

Aggregations

LifecycleStop (org.apache.druid.java.util.common.lifecycle.LifecycleStop)8 ISE (org.apache.druid.java.util.common.ISE)4 IOException (java.io.IOException)3 ExecutionException (java.util.concurrent.ExecutionException)3 Closer (org.apache.druid.java.util.common.io.Closer)2 KeeperException (org.apache.zookeeper.KeeperException)2 Interval (org.joda.time.Interval)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 AbstractMap (java.util.AbstractMap)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 TimeoutException (java.util.concurrent.TimeoutException)1 BaseNodeRoleWatcher (org.apache.druid.discovery.BaseNodeRoleWatcher)1 DruidNodeDiscovery (org.apache.druid.discovery.DruidNodeDiscovery)1 TaskStatus (org.apache.druid.indexer.TaskStatus)1 Task (org.apache.druid.indexing.common.task.Task)1 SupervisorTaskAutoScaler (org.apache.druid.indexing.overlord.supervisor.autoscaler.SupervisorTaskAutoScaler)1 ServiceMetricEvent (org.apache.druid.java.util.emitter.service.ServiceMetricEvent)1 DateTime (org.joda.time.DateTime)1