Search in sources :

Example 1 with NodeState

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;
}
Also used : NodeState(io.prestosql.metadata.NodeState)

Example 2 with NodeState

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();
}
Also used : NodeState(io.prestosql.metadata.NodeState) HttpRequestSessionContext(io.prestosql.server.HttpRequestSessionContext) SessionContext(io.prestosql.server.SessionContext) HttpRequestSessionContext(io.prestosql.server.HttpRequestSessionContext) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces)

Aggregations

NodeState (io.prestosql.metadata.NodeState)2 HttpRequestSessionContext (io.prestosql.server.HttpRequestSessionContext)1 SessionContext (io.prestosql.server.SessionContext)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1