Class Txn

java.lang.Object
com.aerospike.client.Txn

public final class Txn extends Object
Multi-record transaction (MRT). Each command in the MRT must use the same namespace.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static enum 
    MRT state.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Txn()
    Create MRT, assign random transaction id and initialize reads/writes hashmaps with default capacities.
    Txn(int readsCapacity, int writesCapacity)
    Create MRT, assign random transaction id and initialize reads/writes hashmaps with given capacities.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Clear MRT.
    boolean
    Return if the MRT monitor record should be closed/deleted.
    int
    Get MRT deadline.
    long
    Return MRT ID.
    boolean
    Return if MRT is inDoubt.
    Return MRT namespace.
    Get all read keys and their versions.
    Get record version for a given key.
    Return MRT state.
    int
    Return MRT timeout in seconds.
    Get all write keys and their versions.
    boolean
    Does MRT monitor record exist.
    void
    onRead(Key key, Long version)
    Process the results of a record read.
    void
    onWrite(Key key, Long version, int resultCode)
    Process the results of a record write.
    void
    Add key to write hash when write command is in doubt (usually caused by timeout).
    void
    setDeadline(int deadline)
    Set MRT deadline.
    void
    setInDoubt(boolean inDoubt)
    Set MRT inDoubt flag.
    void
    Set MRT namespace only if doesn't already exist.
    void
    Set MRT state.
    void
    setTimeout(int timeout)
    Set MRT timeout in seconds.
    void
    Verify that the MRT state allows future commands.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Txn

      public Txn()
      Create MRT, assign random transaction id and initialize reads/writes hashmaps with default capacities.

      The default client MRT timeout is zero. This means use the server configuration mrt-duration as the MRT timeout. The default mrt-duration is 10 seconds.

    • Txn

      public Txn(int readsCapacity, int writesCapacity)
      Create MRT, assign random transaction id and initialize reads/writes hashmaps with given capacities.

      The default client MRT timeout is zero. This means use the server configuration mrt-duration as the MRT timeout. The default mrt-duration is 10 seconds.

      Parameters:
      readsCapacity - expected number of record reads in the MRT. Minimum value is 16.
      writesCapacity - expected number of record writes in the MRT. Minimum value is 16.
  • Method Details

    • getId

      public long getId()
      Return MRT ID.
    • setTimeout

      public void setTimeout(int timeout)
      Set MRT timeout in seconds. The timer starts when the MRT monitor record is created. This occurs when the first command in the MRT is executed. If the timeout is reached before a commit or abort is called, the server will expire and rollback the MRT.

      If the MRT timeout is zero, the server configuration mrt-duration is used. The default mrt-duration is 10 seconds.

    • getTimeout

      public int getTimeout()
      Return MRT timeout in seconds.
    • verifyCommand

      public void verifyCommand()
      Verify that the MRT state allows future commands.
    • onRead

      public void onRead(Key key, Long version)
      Process the results of a record read. For internal use only.
    • getReadVersion

      public Long getReadVersion(Key key)
      Get record version for a given key.
    • getReads

      public Set<Map.Entry<Key,Long>> getReads()
      Get all read keys and their versions.
    • onWrite

      public void onWrite(Key key, Long version, int resultCode)
      Process the results of a record write. For internal use only.
    • onWriteInDoubt

      public void onWriteInDoubt(Key key)
      Add key to write hash when write command is in doubt (usually caused by timeout).
    • getWrites

      public Set<Key> getWrites()
      Get all write keys and their versions.
    • setNamespace

      public void setNamespace(String ns)
      Set MRT namespace only if doesn't already exist. If namespace already exists, verify new namespace is the same.
    • getNamespace

      public String getNamespace()
      Return MRT namespace.
    • setDeadline

      public void setDeadline(int deadline)
      Set MRT deadline. The deadline is a wall clock time calculated by the server from the MRT timeout that is sent by the client when creating the MRT monitor record. This deadline is used to avoid client/server clock skew issues. For internal use only.
    • getDeadline

      public int getDeadline()
      Get MRT deadline. For internal use only.
    • closeMonitor

      public boolean closeMonitor()
      Return if the MRT monitor record should be closed/deleted. For internal use only.
    • monitorExists

      public boolean monitorExists()
      Does MRT monitor record exist.
    • setState

      public void setState(Txn.State state)
      Set MRT state. For internal use only.
    • getState

      public Txn.State getState()
      Return MRT state.
    • setInDoubt

      public void setInDoubt(boolean inDoubt)
      Set MRT inDoubt flag. For internal use only.
    • getInDoubt

      public boolean getInDoubt()
      Return if MRT is inDoubt.
    • clear

      public void clear()
      Clear MRT. Remove all tracked keys.