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

Extract StartupStatus class #9973

Merged
merged 2 commits into from
Dec 29, 2021
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 @@ -128,13 +128,9 @@ public QueuedStatementResource(
{
this.sessionContextFactory = requireNonNull(sessionContextFactory, "sessionContextFactory is null");
this.dispatchManager = requireNonNull(dispatchManager, "dispatchManager is null");

requireNonNull(dispatchManager, "dispatchManager is null");
this.responseExecutor = requireNonNull(executor, "executor is null").getExecutor();
this.timeoutExecutor = requireNonNull(executor, "executor is null").getScheduledExecutor();

this.queryInfoUrlFactory = requireNonNull(queryInfoUrlTemplate, "queryInfoUrlTemplate is null");

this.compressionEnabled = requireNonNull(serverConfig, "serverConfig is null").isQueryResultsCompressionEnabled();
this.alternateHeaderName = requireNonNull(protocolConfig, "protocolConfig is null").getAlternateHeaderName();

Expand Down
2 changes: 1 addition & 1 deletion core/trino-main/src/main/java/io/trino/server/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ private void doStart(String trinoVersion)

injector.getInstance(Announcer.class).start();

injector.getInstance(ServerInfoResource.class).startupComplete();
injector.getInstance(StartupStatus.class).startupComplete();

log.info("======== SERVER STARTED ========");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@
import javax.ws.rs.core.Response;

import java.util.Optional;
import java.util.concurrent.atomic.AtomicBoolean;

import static com.google.common.base.Preconditions.checkState;
import static io.airlift.units.Duration.nanosSince;
import static io.trino.metadata.NodeState.ACTIVE;
import static io.trino.metadata.NodeState.SHUTTING_DOWN;
Expand All @@ -51,24 +49,25 @@ public class ServerInfoResource
private final String environment;
private final boolean coordinator;
private final GracefulShutdownHandler shutdownHandler;
private final StartupStatus startupStatus;
private final long startTime = System.nanoTime();
private final AtomicBoolean startupComplete = new AtomicBoolean();

@Inject
public ServerInfoResource(NodeVersion nodeVersion, NodeInfo nodeInfo, ServerConfig serverConfig, GracefulShutdownHandler shutdownHandler)
public ServerInfoResource(NodeVersion nodeVersion, NodeInfo nodeInfo, ServerConfig serverConfig, GracefulShutdownHandler shutdownHandler, StartupStatus startupStatus)
{
this.version = requireNonNull(nodeVersion, "nodeVersion is null");
this.environment = requireNonNull(nodeInfo, "nodeInfo is null").getEnvironment();
this.coordinator = requireNonNull(serverConfig, "serverConfig is null").isCoordinator();
this.shutdownHandler = requireNonNull(shutdownHandler, "shutdownHandler is null");
this.startupStatus = requireNonNull(startupStatus, "startupStatus is null");
}

@ResourceSecurity(PUBLIC)
@GET
@Produces(APPLICATION_JSON)
public ServerInfo getInfo()
{
boolean starting = !startupComplete.get();
boolean starting = !startupStatus.isStartupComplete();
return new ServerInfo(version, environment, coordinator, starting, Optional.of(nanosSince(startTime)));
}

Expand Down Expand Up @@ -126,9 +125,4 @@ public Response getServerCoordinator()
// return 404 to allow load balancers to only send traffic to the coordinator
return Response.status(Response.Status.NOT_FOUND).build();
}

public void startupComplete()
{
checkState(startupComplete.compareAndSet(false, true), "Server startup already marked as complete");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ protected void setup(Binder binder)
install(new WorkerModule());
}

binder.bind(StartupStatus.class).in(Scopes.SINGLETON);

configBinder(binder).bindConfigDefaults(HttpServerConfig.class, httpServerConfig -> {
httpServerConfig.setAdminEnabled(false);
});
Expand Down
33 changes: 33 additions & 0 deletions core/trino-main/src/main/java/io/trino/server/StartupStatus.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.trino.server;

import java.util.concurrent.atomic.AtomicBoolean;

import static com.google.common.base.Preconditions.checkState;

public final class StartupStatus
{
private final AtomicBoolean startupComplete = new AtomicBoolean();

public void startupComplete()
{
checkState(startupComplete.compareAndSet(false, true), "Server startup already marked as complete");
}

public boolean isStartupComplete()
{
return startupComplete.get();
}
}