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());
}
}
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);
}
}
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;
}
}
Aggregations