Search in sources :

Example 1 with LifecycleStop

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

Example 2 with LifecycleStop

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);
    }
}
Also used : Closer(com.google.common.io.Closer) KeeperException(org.apache.zookeeper.KeeperException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) LifecycleStop(io.druid.java.util.common.lifecycle.LifecycleStop)

Example 3 with LifecycleStop

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");
            }
        }
    }
}
Also used : Closer(com.google.common.io.Closer) PathChildrenCache(org.apache.curator.framework.recipes.cache.PathChildrenCache) CuratorTransaction(org.apache.curator.framework.api.transaction.CuratorTransaction) CuratorTransactionFinal(org.apache.curator.framework.api.transaction.CuratorTransactionFinal) ConcurrentMap(java.util.concurrent.ConcurrentMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) KeeperException(org.apache.zookeeper.KeeperException) LifecycleStop(io.druid.java.util.common.lifecycle.LifecycleStop)

Example 4 with LifecycleStop

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

Example 5 with LifecycleStop

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");
    }
}
Also used : ListenableScheduledFuture(com.google.common.util.concurrent.ListenableScheduledFuture) LifecycleStop(io.druid.java.util.common.lifecycle.LifecycleStop)

Aggregations

LifecycleStop (io.druid.java.util.common.lifecycle.LifecycleStop)6 Closer (com.google.common.io.Closer)3 IOException (java.io.IOException)2 Map (java.util.Map)2 ConcurrentMap (java.util.concurrent.ConcurrentMap)2 KeeperException (org.apache.zookeeper.KeeperException)2 DateTime (org.joda.time.DateTime)2 Interval (org.joda.time.Interval)2 ListenableScheduledFuture (com.google.common.util.concurrent.ListenableScheduledFuture)1 ListeningExecutorService (com.google.common.util.concurrent.ListeningExecutorService)1 ServiceMetricEvent (com.metamx.emitter.service.ServiceMetricEvent)1 TaskStatus (io.druid.indexing.common.TaskStatus)1 Task (io.druid.indexing.common.task.Task)1 MalformedURLException (java.net.MalformedURLException)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ExecutionException (java.util.concurrent.ExecutionException)1 CuratorTransaction (org.apache.curator.framework.api.transaction.CuratorTransaction)1 CuratorTransactionFinal (org.apache.curator.framework.api.transaction.CuratorTransactionFinal)1 PathChildrenCache (org.apache.curator.framework.recipes.cache.PathChildrenCache)1