Skip to content

Commit

Permalink
Make CliPeon run shutdown hooks properly
Browse files Browse the repository at this point in the history
* Also make jetty threads daemon
  • Loading branch information
drcrallen committed Jul 14, 2015
1 parent 798c332 commit 2b87ad3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ private static Server makeJettyServer(@Self DruidNode node, ServerConfig config)
final QueuedThreadPool threadPool = new QueuedThreadPool();
threadPool.setMinThreads(config.getNumThreads());
threadPool.setMaxThreads(config.getNumThreads());
threadPool.setDaemon(true);

final Server server = new Server(threadPool);

Expand Down
29 changes: 21 additions & 8 deletions services/src/main/java/io/druid/cli/CliPeon.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import io.airlift.command.Arguments;
import io.airlift.command.Command;
import io.airlift.command.Option;
import io.druid.metadata.IndexerSQLMetadataStorageCoordinator;
import io.druid.guice.Binders;
import io.druid.guice.IndexingServiceFirehoseModule;
import io.druid.guice.Jerseys;
Expand All @@ -56,6 +55,7 @@
import io.druid.indexing.overlord.ThreadPoolTaskRunner;
import io.druid.indexing.worker.executor.ExecutorLifecycle;
import io.druid.indexing.worker.executor.ExecutorLifecycleConfig;
import io.druid.metadata.IndexerSQLMetadataStorageCoordinator;
import io.druid.query.QuerySegmentWalker;
import io.druid.segment.loading.DataSegmentArchiver;
import io.druid.segment.loading.DataSegmentKiller;
Expand All @@ -71,7 +71,6 @@
import io.druid.segment.realtime.firehose.ServiceAnnouncingChatHandlerProvider;
import io.druid.server.QueryResource;
import io.druid.server.initialization.jetty.JettyServerInitializer;

import org.eclipse.jetty.server.Server;

import java.io.File;
Expand Down Expand Up @@ -125,7 +124,8 @@ public void configure(Binder binder)
.to(ServiceAnnouncingChatHandlerProvider.class).in(LazySingleton.class);
handlerProviderBinder.addBinding("noop")
.to(NoopChatHandlerProvider.class).in(LazySingleton.class);
binder.bind(ServiceAnnouncingChatHandlerProvider.class).in(LazySingleton.class);;
binder.bind(ServiceAnnouncingChatHandlerProvider.class).in(LazySingleton.class);

binder.bind(NoopChatHandlerProvider.class).in(LazySingleton.class);

binder.bind(TaskToolboxFactory.class).in(LazySingleton.class);
Expand Down Expand Up @@ -190,7 +190,9 @@ private void configureTaskActionClient(Binder binder)
JsonConfigProvider.bind(binder, "druid.indexer.storage", TaskStorageConfig.class);
binder.bind(TaskStorage.class).to(HeapMemoryTaskStorage.class).in(LazySingleton.class);
binder.bind(TaskActionToolbox.class).in(LazySingleton.class);
binder.bind(IndexerMetadataStorageCoordinator.class).to(IndexerSQLMetadataStorageCoordinator.class).in(LazySingleton.class);
binder.bind(IndexerMetadataStorageCoordinator.class).to(IndexerSQLMetadataStorageCoordinator.class).in(
LazySingleton.class
);
taskActionBinder.addBinding("remote")
.to(RemoteTaskActionClientFactory.class).in(LazySingleton.class);

Expand All @@ -205,17 +207,28 @@ public void run()
{
try {
Injector injector = makeInjector();

try {
Lifecycle lifecycle = initLifecycle(injector);

final Lifecycle lifecycle = initLifecycle(injector);
Runtime.getRuntime().addShutdownHook(
new Thread(
new Runnable()
{
@Override
public void run()
{
log.info("Running shutdown hook");
lifecycle.stop();
}
}
)
);
injector.getInstance(ExecutorLifecycle.class).join();
lifecycle.stop();
}
catch (Throwable t) {
log.error(t, "Error when starting up. Failing.");
System.exit(1);
}
log.info("Finished peon task");
}
catch (Exception e) {
throw Throwables.propagate(e);
Expand Down

0 comments on commit 2b87ad3

Please sign in to comment.