Class Increment

All Implemented Interfaces:
CellScannable, Attributes, Row, ExtendedCellScannable, HeapSize

@Public public class Increment extends Mutation
Used to perform Increment operations on a single row.

This operation ensures atomicity to readers. Increments are done under a single row lock, so write operations to a row are synchronized, and readers are guaranteed to see this operation fully completed.

To increment columns of a row, instantiate an Increment object with the row to increment. At least one column to increment must be specified using the addColumn(byte[], byte[], long) method.

  • Field Details

  • Constructor Details

    • Increment

      public Increment(byte[] row)
      Create a Increment operation for the specified row.

      At least one column must be incremented.

      Parameters:
      row - row key (we will make a copy of this).
    • Increment

      public Increment(byte[] row, int offset, int length)
      Create a Increment operation for the specified row.

      At least one column must be incremented.

      Parameters:
      row - row key (we will make a copy of this).
    • Increment

      public Increment(Increment incrementToCopy)
      Copy constructor
      Parameters:
      incrementToCopy - increment to copy
    • Increment

      public Increment(byte[] row, long ts, NavigableMap<byte[],List<Cell>> familyMap)
      Construct the Increment with user defined data. NOTED: 1) all cells in the familyMap must have the Type.Put 2) the row of each cell must be same with passed row.
      Parameters:
      row - row. CAN'T be null
      ts - timestamp
      familyMap - the map to collect all cells internally. CAN'T be null
  • Method Details

    • add

      public Increment add(Cell cell) throws IOException
      Add the specified KeyValue to this operation.
      Overrides:
      add in class Mutation
      Parameters:
      cell - individual Cell
      Throws:
      IOException - e
    • addColumn

      public Increment addColumn(byte[] family, byte[] qualifier, long amount)
      Increment the column from the specific family with the specified qualifier by the specified amount.

      Overrides previous calls to addColumn for this family and qualifier.

      Parameters:
      family - family name
      qualifier - column qualifier
      amount - amount to increment by
      Returns:
      the Increment object
    • getTimeRange

      Gets the TimeRange used for this increment.
    • setTimeRange

      public Increment setTimeRange(long minStamp, long maxStamp) throws IOException
      Sets the TimeRange to be used on the Get for this increment.

      This is useful for when you have counters that only last for specific periods of time (ie. counters that are partitioned by time). By setting the range of valid times for this increment, you can potentially gain some performance with a more optimal Get operation. Be careful adding the time range to this class as you will update the old cell if the time range doesn't include the latest cells.

      This range is used as [minStamp, maxStamp).

      Parameters:
      minStamp - minimum timestamp value, inclusive
      maxStamp - maximum timestamp value, exclusive
      Throws:
      IOException - if invalid time range
    • setTimestamp

      public Increment setTimestamp(long timestamp)
      Description copied from class: Mutation
      Set the timestamp of the delete.
      Overrides:
      setTimestamp in class Mutation
    • setReturnResults

      public Increment setReturnResults(boolean returnResults)
      Overrides:
      setReturnResults in class Mutation
      Parameters:
      returnResults - True (default) if the increment operation should return the results. A client that is not interested in the result can save network bandwidth setting this to false.
    • isReturnResults

      public boolean isReturnResults()
      Returns current setting for returnResults
      Overrides:
      isReturnResults in class Mutation
    • numFamilies

      public int numFamilies()
      Method for retrieving the number of families to increment from
      Overrides:
      numFamilies in class Mutation
      Returns:
      number of families
    • hasFamilies

      public boolean hasFamilies()
      Method for checking if any families have been inserted into this Increment
      Returns:
      true if familyMap is non empty false otherwise
    • getFamilyMapOfLongs

      public Map<byte[],NavigableMap<byte[],Long>> getFamilyMapOfLongs()
      Before 0.95, when you called Increment#getFamilyMap(), you got back a map of families to a list of Longs. Now, Mutation.getFamilyCellMap() returns families by list of Cells. This method has been added so you can have the old behavior.
      Returns:
      Map of families to a Map of qualifiers and their Long increments.
      Since:
      0.95.0
    • toString

      public String toString()
      Description copied from class: Operation
      Produces a string representation of this Operation. It defaults to a JSON representation, but falls back to a string representation of the fingerprint and details in the case of a JSON encoding failure.
      Overrides:
      toString in class Operation
    • extraHeapSize

      protected long extraHeapSize()
      Description copied from class: Mutation
      Subclasses should override this method to add the heap size of their own fields.
      Overrides:
      extraHeapSize in class Mutation
      Returns:
      the heap size to add (will be aligned).
    • setAttribute

      public Increment setAttribute(String name, byte[] value)
      Description copied from interface: Attributes
      Sets an attribute. In case value = null attribute is removed from the attributes map. Attribute names starting with _ indicate system attributes.
      Specified by:
      setAttribute in interface Attributes
      Overrides:
      setAttribute in class OperationWithAttributes
      Parameters:
      name - attribute name
      value - attribute value
    • setId

      public Increment setId(String id)
      Description copied from class: OperationWithAttributes
      This method allows you to set an identifier on an operation. The original motivation for this was to allow the identifier to be used in slow query logging, but this could obviously be useful in other places. One use of this could be to put a class.method identifier in here to see where the slow query is coming from. id to set for the scan
      Overrides:
      setId in class OperationWithAttributes
    • setDurability

      Description copied from class: Mutation
      Set the durability for this mutation
      Overrides:
      setDurability in class Mutation
    • setClusterIds

      public Increment setClusterIds(List<UUID> clusterIds)
      Description copied from class: Mutation
      Marks that the clusters with the given clusterIds have consumed the mutation
      Overrides:
      setClusterIds in class Mutation
      Parameters:
      clusterIds - of the clusters that have consumed the mutation
    • setCellVisibility

      Description copied from class: Mutation
      Sets the visibility expression associated with cells in this Mutation.
      Overrides:
      setCellVisibility in class Mutation
    • setACL

      public Increment setACL(String user, Permission perms)
      Description copied from class: Mutation
      Set the ACL for this operation.
      Overrides:
      setACL in class Mutation
      Parameters:
      user - User short name
      perms - Permissions for the user
    • setACL

      Description copied from class: Mutation
      Set the ACL for this operation.
      Overrides:
      setACL in class Mutation
      Parameters:
      perms - A map of permissions for a user or users
    • setTTL

      public Increment setTTL(long ttl)
      Description copied from class: Mutation
      Set the TTL desired for the result of the mutation, in milliseconds.
      Overrides:
      setTTL in class Mutation
      Parameters:
      ttl - the TTL desired for the result of the mutation, in milliseconds
    • setPriority

      public Increment setPriority(int priority)
      Overrides:
      setPriority in class OperationWithAttributes
    • getCellBuilder

      Description copied from class: Mutation
      get a CellBuilder instance that already has relevant Type and Row set.
      Specified by:
      getCellBuilder in class Mutation
      Parameters:
      type - e.g CellBuilderType.SHALLOW_COPY
      Returns:
      CellBuilder which already has relevant Type and Row set.