Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shutdown server threads on server close #11496

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkState;
import static com.google.common.util.concurrent.Futures.immediateVoidFuture;
import static io.airlift.concurrent.Threads.threadsNamed;
import static io.airlift.concurrent.Threads.daemonThreadsNamed;
import static io.trino.spi.StandardErrorCode.GENERIC_INSUFFICIENT_RESOURCES;
import static java.lang.String.format;
import static java.util.Comparator.comparing;
Expand Down Expand Up @@ -73,7 +73,7 @@ public ClusterSizeMonitor(
{
this.nodeManager = requireNonNull(nodeManager, "nodeManager is null");
this.includeCoordinator = includeCoordinator;
this.executor = newSingleThreadScheduledExecutor(threadsNamed("node-monitor-%s"));
this.executor = newSingleThreadScheduledExecutor(daemonThreadsNamed("node-monitor-%s"));
}

@PostConstruct
Expand All @@ -87,6 +87,7 @@ public void start()
public void stop()
{
nodeManager.removeNodeChangeListener(listener);
executor.shutdown();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
import static com.google.common.base.Preconditions.checkState;
import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static com.google.common.collect.Sets.difference;
import static io.airlift.concurrent.Threads.threadsNamed;
import static io.airlift.concurrent.Threads.daemonThreadsNamed;
import static io.airlift.http.client.HttpUriBuilder.uriBuilderFrom;
import static io.trino.metadata.NodeState.ACTIVE;
import static io.trino.metadata.NodeState.INACTIVE;
Expand Down Expand Up @@ -106,8 +106,8 @@ public DiscoveryNodeManager(
this.failureDetector = requireNonNull(failureDetector, "failureDetector is null");
this.expectedNodeVersion = requireNonNull(expectedNodeVersion, "expectedNodeVersion is null");
this.httpClient = requireNonNull(httpClient, "httpClient is null");
this.nodeStateUpdateExecutor = newSingleThreadScheduledExecutor(threadsNamed("node-state-poller-%s"));
this.nodeStateEventExecutor = newCachedThreadPool(threadsNamed("node-state-events-%s"));
this.nodeStateUpdateExecutor = newSingleThreadScheduledExecutor(daemonThreadsNamed("node-state-poller-%s"));
this.nodeStateEventExecutor = newCachedThreadPool(daemonThreadsNamed("node-state-events-%s"));
this.httpsRequired = internalCommunicationConfig.isHttpsRequired();

this.currentNode = findCurrentNode(
Expand Down Expand Up @@ -154,6 +154,13 @@ public void startPollingNodeStates()
pollWorkers();
}

@PreDestroy
public void destroy()
{
nodeStateUpdateExecutor.shutdown();
nodeStateEventExecutor.shutdown();
}

private void pollWorkers()
{
AllNodes allNodes = getAllNodes();
Expand Down