Search in sources :

Example 1 with AbstractSqlResult

use of com.hazelcast.sql.impl.AbstractSqlResult in project hazelcast by hazelcast.

the class QueryClientStateRegistry method update.

public void update(Set<UUID> activeClientIds) {
    long currentTimeNano = System.nanoTime();
    List<QueryClientState> victims = new ArrayList<>();
    for (QueryClientState clientCursor : clientCursors.values()) {
        // Close cursors that were opened by disconnected clients.
        if (!activeClientIds.contains(clientCursor.getClientId())) {
            victims.add(clientCursor);
        }
        // condition between the query cancellation on a client and the query completion on a server.
        if (clientCursor.isClosed() && clientCursor.getCreatedAtNano() + closedCursorCleanupTimeoutNs < currentTimeNano) {
            victims.add(clientCursor);
        }
    }
    for (QueryClientState victim : victims) {
        QueryException error = QueryException.clientMemberConnection(victim.getClientId());
        AbstractSqlResult result = victim.getSqlResult();
        if (result != null) {
            result.close(error);
        }
        deleteClientCursor(victim.getQueryId());
    }
}
Also used : QueryException(com.hazelcast.sql.impl.QueryException) ArrayList(java.util.ArrayList) AbstractSqlResult(com.hazelcast.sql.impl.AbstractSqlResult)

Example 2 with AbstractSqlResult

use of com.hazelcast.sql.impl.AbstractSqlResult in project hazelcast by hazelcast.

the class SqlExecuteMessageTask method encodeResponse.

@Override
protected ClientMessage encodeResponse(Object response) {
    AbstractSqlResult result = (AbstractSqlResult) response;
    if (result.updateCount() >= 0) {
        return SqlExecuteCodec.encodeResponse(null, null, result.updateCount(), null);
    } else {
        SqlServiceImpl sqlService = nodeEngine.getSqlService();
        SqlPage page = sqlService.getInternalService().getClientStateRegistry().registerAndFetch(endpoint.getUuid(), result, parameters.cursorBufferSize, serializationService);
        return SqlExecuteCodec.encodeResponse(result.getRowMetadata().getColumns(), page, -1, null);
    }
}
Also used : SqlServiceImpl(com.hazelcast.sql.impl.SqlServiceImpl) AbstractSqlResult(com.hazelcast.sql.impl.AbstractSqlResult)

Example 3 with AbstractSqlResult

use of com.hazelcast.sql.impl.AbstractSqlResult in project hazelcast by hazelcast.

the class QueryClientStateRegistry method fetchInternal.

private SqlPage fetchInternal(QueryClientState clientCursor, int cursorBufferSize, InternalSerializationService serializationService, boolean respondImmediately) {
    List<SqlColumnMetadata> columns = clientCursor.getSqlResult().getRowMetadata().getColumns();
    List<SqlColumnType> columnTypes = new ArrayList<>(columns.size());
    for (SqlColumnMetadata column : columns) {
        columnTypes.add(column.getType());
    }
    if (respondImmediately) {
        return SqlPage.fromRows(columnTypes, Collections.emptyList(), false, serializationService);
    }
    ResultIterator<SqlRow> iterator = clientCursor.getIterator();
    try {
        List<SqlRow> rows = new ArrayList<>(cursorBufferSize);
        boolean last = fetchPage(iterator, rows, cursorBufferSize);
        return SqlPage.fromRows(columnTypes, rows, last, serializationService);
    } catch (HazelcastSqlException e) {
        // it happens, the cursor is already closed with the error, so we just re-throw.
        throw e;
    } catch (Exception e) {
        // Any other exception indicates that something has happened outside of the internal query state. For example,
        // we may fail to serialize a specific column value to Data. We have to close the cursor in this case.
        AbstractSqlResult result = clientCursor.getSqlResult();
        QueryException error = QueryException.error("Failed to prepare the SQL result for the client: " + e.getMessage(), e);
        result.close(error);
        throw error;
    }
}
Also used : SqlRow(com.hazelcast.sql.SqlRow) ArrayList(java.util.ArrayList) SqlColumnType(com.hazelcast.sql.SqlColumnType) HazelcastSqlException(com.hazelcast.sql.HazelcastSqlException) QueryException(com.hazelcast.sql.impl.QueryException) QueryException(com.hazelcast.sql.impl.QueryException) AbstractSqlResult(com.hazelcast.sql.impl.AbstractSqlResult) SqlColumnMetadata(com.hazelcast.sql.SqlColumnMetadata) HazelcastSqlException(com.hazelcast.sql.HazelcastSqlException)

Aggregations

AbstractSqlResult (com.hazelcast.sql.impl.AbstractSqlResult)3 QueryException (com.hazelcast.sql.impl.QueryException)2 ArrayList (java.util.ArrayList)2 HazelcastSqlException (com.hazelcast.sql.HazelcastSqlException)1 SqlColumnMetadata (com.hazelcast.sql.SqlColumnMetadata)1 SqlColumnType (com.hazelcast.sql.SqlColumnType)1 SqlRow (com.hazelcast.sql.SqlRow)1 SqlServiceImpl (com.hazelcast.sql.impl.SqlServiceImpl)1