Search in sources :

Example 1 with ProtocolException

use of org.apache.cassandra.transport.ProtocolException in project cassandra by apache.

the class QueryMessage method execute.

public Message.Response execute(QueryState state, long queryStartNanoTime) {
    try {
        if (options.getPageSize() == 0)
            throw new ProtocolException("The page size cannot be 0");
        UUID tracingId = null;
        if (isTracingRequested()) {
            tracingId = UUIDGen.getTimeUUID();
            state.prepareTracingSession(tracingId);
        }
        if (state.traceNextQuery()) {
            state.createTracingSession();
            ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
            builder.put("query", query);
            if (options.getPageSize() > 0)
                builder.put("page_size", Integer.toString(options.getPageSize()));
            if (options.getConsistency() != null)
                builder.put("consistency_level", options.getConsistency().name());
            if (options.getSerialConsistency() != null)
                builder.put("serial_consistency_level", options.getSerialConsistency().name());
            Tracing.instance.begin("Execute CQL3 query", state.getClientAddress(), builder.build());
        }
        Message.Response response = ClientState.getCQLQueryHandler().process(query, state, options, getCustomPayload(), queryStartNanoTime);
        if (options.skipMetadata() && response instanceof ResultMessage.Rows)
            ((ResultMessage.Rows) response).result.metadata.setSkipMetadata();
        if (tracingId != null)
            response.setTracingId(tracingId);
        return response;
    } catch (Exception e) {
        JVMStabilityInspector.inspectThrowable(e);
        if (!((e instanceof RequestValidationException) || (e instanceof RequestExecutionException)))
            logger.error("Unexpected error during query", e);
        return ErrorMessage.fromException(e);
    } finally {
        Tracing.instance.stopSession();
    }
}
Also used : ProtocolException(org.apache.cassandra.transport.ProtocolException) RequestExecutionException(org.apache.cassandra.exceptions.RequestExecutionException) Message(org.apache.cassandra.transport.Message) UUID(java.util.UUID) RequestValidationException(org.apache.cassandra.exceptions.RequestValidationException) ImmutableMap(com.google.common.collect.ImmutableMap) RequestExecutionException(org.apache.cassandra.exceptions.RequestExecutionException) RequestValidationException(org.apache.cassandra.exceptions.RequestValidationException) ProtocolException(org.apache.cassandra.transport.ProtocolException)

Example 2 with ProtocolException

use of org.apache.cassandra.transport.ProtocolException in project cassandra by apache.

the class PagingState method deserialize.

public static PagingState deserialize(ByteBuffer bytes, ProtocolVersion protocolVersion) {
    if (bytes == null)
        return null;
    try (DataInputBuffer in = new DataInputBuffer(bytes, true)) {
        ByteBuffer pk;
        RowMark mark;
        int remaining, remainingInPartition;
        if (protocolVersion.isSmallerOrEqualTo(ProtocolVersion.V3)) {
            pk = ByteBufferUtil.readWithShortLength(in);
            mark = new RowMark(ByteBufferUtil.readWithShortLength(in), protocolVersion);
            remaining = in.readInt();
            // Note that while 'in.available()' is theoretically an estimate of how many bytes are available
            // without blocking, we know that since we're reading a ByteBuffer it will be exactly how many
            // bytes remain to be read. And the reason we want to condition this is for backward compatility
            // as we used to not set this.
            remainingInPartition = in.available() > 0 ? in.readInt() : Integer.MAX_VALUE;
        } else {
            pk = ByteBufferUtil.readWithVIntLength(in);
            mark = new RowMark(ByteBufferUtil.readWithVIntLength(in), protocolVersion);
            remaining = (int) in.readUnsignedVInt();
            remainingInPartition = (int) in.readUnsignedVInt();
        }
        return new PagingState(pk.hasRemaining() ? pk : null, mark.mark.hasRemaining() ? mark : null, remaining, remainingInPartition);
    } catch (IOException e) {
        throw new ProtocolException("Invalid value for the paging state");
    }
}
Also used : ProtocolException(org.apache.cassandra.transport.ProtocolException) DataInputBuffer(org.apache.cassandra.io.util.DataInputBuffer) IOException(java.io.IOException) ByteBuffer(java.nio.ByteBuffer)

Aggregations

ProtocolException (org.apache.cassandra.transport.ProtocolException)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 IOException (java.io.IOException)1 ByteBuffer (java.nio.ByteBuffer)1 UUID (java.util.UUID)1 RequestExecutionException (org.apache.cassandra.exceptions.RequestExecutionException)1 RequestValidationException (org.apache.cassandra.exceptions.RequestValidationException)1 DataInputBuffer (org.apache.cassandra.io.util.DataInputBuffer)1 Message (org.apache.cassandra.transport.Message)1