ReadCommand (apache-cassandra API)
Date: 2018-02-14

org.apache.cassandra.db

## Class ReadCommand

- java.lang.Object
- - org.apache.cassandra.db.monitoring.MonitorableImpl
  - - org.apache.cassandra.db.ReadCommand

- All Implemented Interfaces:
    Monitorable, ReadQuery
  Direct Known Subclasses:
    PartitionRangeReadCommand, SinglePartitionReadCommand

      public abstract class ReadCommand
      extends MonitorableImpl
      implements ReadQuery

  General interface for storage-engine read commands (common to both range and single partition commands).

  This contains all the informations needed to do a local read.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `protected class` | `ReadCommand.CheckForAbort`
    `protected static class` | `ReadCommand.Kind`
    `protected static class` | `ReadCommand.SelectionDeserializer`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static IVersionedSerializer<ReadCommand>` | `legacyPagedRangeCommandSerializer`
    `static IVersionedSerializer<ReadCommand>` | `legacyRangeSliceCommandSerializer`
    `static IVersionedSerializer<ReadCommand>` | `legacyReadCommandSerializer`
    `protected static org.slf4j.Logger` | `logger`
    `static IVersionedSerializer<ReadCommand>` | `pagedRangeSerializer`
    `static IVersionedSerializer<ReadCommand>` | `rangeSliceSerializer`
    `static IVersionedSerializer<ReadCommand>` | `readSerializer`
    `static IVersionedSerializer<ReadCommand>` | `serializer`

    - ### Fields inherited from interface org.apache.cassandra.db.ReadQuery

      `EMPTY`

  - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `ReadCommand(ReadCommand.Kind kind, boolean isDigestQuery, int digestVersion, boolean isForThrift, CFMetaData metadata, int nowInSec, ColumnFilter columnFilter, RowFilter rowFilter, DataLimits limits, IndexMetadata index)`

  - ### Method Summary

    All Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected abstract void` | `appendCQLWhereClause(java.lang.StringBuilder sb)`
    `abstract ClusteringIndexFilter` | `clusteringIndexFilter(DecoratedKey key)` The clustering index filter this command to use for the provided key.
    `ColumnFilter` | `columnFilter()` A filter on which (non-PK) columns must be returned by the query.
    `abstract ReadCommand` | `copy()` Returns a copy of this command.
    `abstract ReadCommand` | `copyAsDigestQuery()` Returns a copy of this command with isDigestQuery set to true.
    `abstract MessageOut<ReadCommand>` | `createMessage(int version)` Creates a message for this command.
    `ReadResponse` | `createResponse(UnfilteredPartitionIterator iterator)`
    `int` | `digestVersion()` If the query is a digest one, the requested digest version.
    `PartitionIterator` | `executeInternal(ReadExecutionController controller)` Execute the query for internal queries (that is, it basically executes the query locally).
    `UnfilteredPartitionIterator` | `executeLocally(ReadExecutionController executionController)` Executes this command on the local host.
    `ReadExecutionController` | `executionController()` Starts a new read operation.
    `Index` | `getIndex(ColumnFamilyStore cfs)`
    `abstract long` | `getTimeout()` The configured timeout for this command.
    `IndexMetadata` | `indexMetadata()` Index (metadata) chosen for this query.
    `boolean` | `isDigestQuery()` Whether this query is a digest one or not.
    `boolean` | `isForThrift()` Whether this query is for thrift or not.
    `abstract boolean` | `isLimitedToOnePartition()`
    `DataLimits` | `limits()` The limits set on this query.
    `void` | `maybeValidateIndex()` If the index manager for the CFS determines that there's an applicable 2i that can be used to execute this command, call its (optional) validation method to check that nothing in this command's parameters violates the implementation specific validation rules.
    `CFMetaData` | `metadata()` The metadata for the table queried.
    `java.lang.String` | `name()`
    `int` | `nowInSec()` The time in seconds to use as "now" for this query.
    `protected abstract int` | `oldestUnrepairedTombstone()`
    `protected abstract UnfilteredPartitionIterator` | `queryStorage(ColumnFamilyStore cfs, ReadExecutionController executionController)`
    `protected abstract void` | `recordLatency(TableMetrics metric, long latencyNanos)`
    `RowFilter` | `rowFilter()` Filters/Resrictions on CQL rows.
    `protected abstract long` | `selectionSerializedSize(int version)`
    `protected abstract void` | `serializeSelection(DataOutputPlus out, int version)`
    `ReadCommand` | `setDigestVersion(int digestVersion)` Sets the digest version, for when digest for that command is requested.
    `java.lang.String` | `toCQLString()` Recreate the CQL string corresponding to this query.
    `protected UnfilteredPartitionIterator` | `withoutPurgeableTombstones(UnfilteredPartitionIterator iterator, ColumnFamilyStore cfs)`
    `protected UnfilteredPartitionIterator` | `withStateTracking(UnfilteredPartitionIterator iter)`
    `abstract ReadCommand` | `withUpdatedLimit(DataLimits newLimits)` Creates a new `ReadCommand` instance with new limits.

    - ### Methods inherited from class org.apache.cassandra.db.monitoring.MonitorableImpl

      `abort, complete, constructionTime, isAborted, isCompleted, isCrossNode, isInProgress, isSlow, setMonitoringTime, slowTimeout, timeout`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

    - ### Methods inherited from interface org.apache.cassandra.db.ReadQuery

      `execute, getPager, selectsClustering, selectsFullPartition, selectsKey`

- - ### Field Detail

    - #### logger

          protected static final org.slf4j.Logger logger

    - #### serializer

          public static final IVersionedSerializer<ReadCommand> serializer

    - #### readSerializer

          public static final IVersionedSerializer<ReadCommand> readSerializer

    - #### rangeSliceSerializer

          public static final IVersionedSerializer<ReadCommand> rangeSliceSerializer

    - #### pagedRangeSerializer

          public static final IVersionedSerializer<ReadCommand> pagedRangeSerializer

    - #### legacyRangeSliceCommandSerializer

          public static final IVersionedSerializer<ReadCommand> legacyRangeSliceCommandSerializer

    - #### legacyPagedRangeCommandSerializer

          public static final IVersionedSerializer<ReadCommand> legacyPagedRangeCommandSerializer

    - #### legacyReadCommandSerializer

          public static final IVersionedSerializer<ReadCommand> legacyReadCommandSerializer

  - ### Constructor Detail

    - #### ReadCommand

          protected ReadCommand(ReadCommand.Kind kind,
                                boolean isDigestQuery,
                                int digestVersion,
                                boolean isForThrift,
                                CFMetaData metadata,
                                int nowInSec,
                                ColumnFilter columnFilter,
                                RowFilter rowFilter,
                                DataLimits limits,
                                IndexMetadata index)

  - ### Method Detail

    - #### serializeSelection

          protected abstract void serializeSelection(DataOutputPlus out,
                                                     int version)
                                              throws java.io.IOException

      Throws:
        `java.io.IOException`

    - #### selectionSerializedSize

          protected abstract long selectionSerializedSize(int version)

    - #### isLimitedToOnePartition

          public abstract boolean isLimitedToOnePartition()

    - #### withUpdatedLimit

          public abstract ReadCommand withUpdatedLimit(DataLimits newLimits)

      Creates a new `ReadCommand` instance with new limits.
      Parameters:
        `newLimits` - the new limits
      Returns:
        a new `ReadCommand` with the updated limits

    - #### metadata

          public CFMetaData metadata()

      The metadata for the table queried.
      Returns:
        the metadata for the table queried.

    - #### nowInSec

          public int nowInSec()

      The time in seconds to use as "now" for this query.

      We use the same time as "now" for the whole query to avoid considering different values as expired during the query, which would be buggy (would throw of counting amongst other things).

      Returns:
        the time (in seconds) to use as "now".

    - #### getTimeout

          public abstract long getTimeout()

      The configured timeout for this command.
      Returns:
        the configured timeout for this command.

    - #### columnFilter

          public ColumnFilter columnFilter()

      A filter on which (non-PK) columns must be returned by the query.
      Returns:
        which columns must be fetched by this query.

    - #### rowFilter

          public RowFilter rowFilter()

      Filters/Resrictions on CQL rows.

      This contains the restrictions that are not directly handled by the `ClusteringIndexFilter`. More specifically, this includes any non-PK column restrictions and can include some PK columns restrictions when those can't be satisfied entirely by the clustering index filter (because not all clustering columns have been restricted for instance). If there is 2ndary indexes on the table, one of this restriction might be handled by a 2ndary index.

      Returns:
        the filter holding the expression that rows must satisfy.

    - #### limits

          public DataLimits limits()

      The limits set on this query.
      Specified by:
        `limits` in interface `ReadQuery`
      Returns:
        the limits set on this query.

    - #### isDigestQuery

          public boolean isDigestQuery()

      Whether this query is a digest one or not.
      Returns:
        Whether this query is a digest query.

    - #### digestVersion

          public int digestVersion()

      If the query is a digest one, the requested digest version.
      Returns:
        the requested digest version if the query is a digest. Otherwise, this can return anything.

    - #### setDigestVersion

          public ReadCommand setDigestVersion(int digestVersion)

      Sets the digest version, for when digest for that command is requested.

      Note that we allow setting this independently of setting the command as a digest query as this allows us to use the command as a carrier of the digest version even if we only call setIsDigestQuery on some copy of it.

      Parameters:
        `digestVersion` - the version for the digest is this command is used for digest query..
      Returns:
        this read command.

    - #### isForThrift

          public boolean isForThrift()

      Whether this query is for thrift or not.
      Returns:
        whether this query is for thrift.

    - #### indexMetadata

          @Nullable
          public IndexMetadata indexMetadata()

      Index (metadata) chosen for this query. Can be null.
      Returns:
        index (metadata) chosen for this query

    - #### clusteringIndexFilter

          public abstract ClusteringIndexFilter clusteringIndexFilter(DecoratedKey key)

      The clustering index filter this command to use for the provided key.

      Note that that method should only be called on a key actually queried by this command and in practice, this will almost always return the same filter, but for the sake of paging, the filter on the first key of a range command might be slightly different.

      Parameters:
        `key` - a partition key queried by this command.
      Returns:
        the `ClusteringIndexFilter` to use for the partition of key `key`.

    - #### copy

          public abstract ReadCommand copy()

      Returns a copy of this command.
      Returns:
        a copy of this command.

    - #### copyAsDigestQuery

          public abstract ReadCommand copyAsDigestQuery()

      Returns a copy of this command with isDigestQuery set to true.

    - #### queryStorage

          protected abstract UnfilteredPartitionIterator queryStorage(ColumnFamilyStore cfs,
                                                                      ReadExecutionController executionController)

    - #### oldestUnrepairedTombstone

          protected abstract int oldestUnrepairedTombstone()

    - #### createResponse

          public ReadResponse createResponse(UnfilteredPartitionIterator iterator)

    - #### getIndex

          public Index getIndex(ColumnFamilyStore cfs)

    - #### maybeValidateIndex

          public void maybeValidateIndex()

      If the index manager for the CFS determines that there's an applicable 2i that can be used to execute this command, call its (optional) validation method to check that nothing in this command's parameters violates the implementation specific validation rules.

    - #### executeLocally

          public UnfilteredPartitionIterator executeLocally(ReadExecutionController executionController)

      Executes this command on the local host.
      Specified by:
        `executeLocally` in interface `ReadQuery`
      Parameters:
        `executionController` - the execution controller spanning this command
      Returns:
        an iterator over the result of executing this command locally.

    - #### recordLatency

          protected abstract void recordLatency(TableMetrics metric,
                                                long latencyNanos)

    - #### executeInternal

          public PartitionIterator executeInternal(ReadExecutionController controller)

      Description copied from interface: `ReadQuery`
      Execute the query for internal queries (that is, it basically executes the query locally).
      Specified by:
        `executeInternal` in interface `ReadQuery`
      Parameters:
        `controller` - the `ReadExecutionController` protecting the read.
      Returns:
        the result of the query.

    - #### executionController

          public ReadExecutionController executionController()

      Description copied from interface: `ReadQuery`
      Starts a new read operation.

      This must be called before `executeInternal` and passed to it to protect the read. The returned object must be closed on all path and it is thus strongly advised to use it in a try-with-ressource construction.

      Specified by:
        `executionController` in interface `ReadQuery`
      Returns:
        a newly started execution controller for this `ReadQuery`.

    - #### withStateTracking

          protected UnfilteredPartitionIterator withStateTracking(UnfilteredPartitionIterator iter)

    - #### createMessage

          public abstract MessageOut<ReadCommand> createMessage(int version)

      Creates a message for this command.

    - #### appendCQLWhereClause

          protected abstract void appendCQLWhereClause(java.lang.StringBuilder sb)

    - #### withoutPurgeableTombstones

          protected UnfilteredPartitionIterator withoutPurgeableTombstones(UnfilteredPartitionIterator iterator,
                                                                           ColumnFamilyStore cfs)

    - #### toCQLString

          public java.lang.String toCQLString()

      Recreate the CQL string corresponding to this query.

      Note that in general the returned string will not be exactly the original user string, first because there isn't always a single syntax for a given query, but also because we don't have all the information needed (we know the non-PK columns queried but not the PK ones as internally we query them all). So this shouldn't be relied too strongly, but this should be good enough for debugging purpose which is what this is for.

    - #### name

          public java.lang.String name()

      Specified by:
        `name` in interface `Monitorable`

Copyright © 2018 The Apache Software Foundation