use of io.prestosql.metadata.NodeState in project hetu-core by openlookeng.
the class NodeStateChangeHandler method doStateTransition.
public synchronized boolean doStateTransition(NodeState newState) throws IllegalStateException {
NodeState oldState = getState();
if (!isValidStateTransition(oldState, newState)) {
throw new IllegalStateException(format("Invalid state transition from %s to %s", oldState, newState));
}
if (oldState == newState) {
return false;
}
if (oldState == ISOLATING) {
abortIsolation();
}
switch(newState) {
case SHUTTING_DOWN:
requestShutdown();
break;
case ISOLATING:
requestIsolation(false);
break;
case ISOLATED:
requestIsolation(true);
break;
default:
break;
}
LOG.info(String.format("Updating node state from %s to %s", state, newState));
state = newState;
return true;
}
use of io.prestosql.metadata.NodeState in project hetu-core by openlookeng.
the class QueuedStatementResource method postStatement.
@POST
@Path("/v1/statement")
@Produces(APPLICATION_JSON)
public Response postStatement(String statement, @HeaderParam(X_FORWARDED_PROTO) String xForwardedProto, @Context HttpServletRequest servletRequest, @Context UriInfo uriInfo) {
if (isNullOrEmpty(statement)) {
throw badRequest(BAD_REQUEST, "SQL statement is empty");
}
// only active coordinator is ready to accept new queries
NodeState state = nodeStateChangeHandler.getState();
if (state != ACTIVE) {
throw badRequest(SERVICE_UNAVAILABLE, "This coordinator is not active so can not accept queries");
}
SessionContext sessionContext = new HttpRequestSessionContext(servletRequest, groupProvider);
Query query = new Query(statement, sessionContext, dispatchManager);
queries.put(query.getQueryId(), query);
return Response.ok(query.getQueryResults(query.getLastToken(), uriInfo, xForwardedProto)).build();
}
Aggregations