Class Txn

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

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

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

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

    Modifier and Type
    Method
    Description
    void
    Clear transaction.
    boolean
    Return if the transaction monitor record should be closed/deleted.
    int
    Get transaction deadline.
    long
    Return transaction ID.
    boolean
    Return if transaction is inDoubt.
    Return transaction namespace.
    Get all read keys and their versions.
    Get record version for a given key.
    Return transaction state.
    int
    Return transaction timeout in seconds.
    Get all write keys and their versions.
    boolean
    Does transaction 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 transaction deadline.
    void
    setInDoubt(boolean inDoubt)
    Set transaction inDoubt flag.
    void
    Set transaction namespace only if doesn't already exist.
    void
    Set transaction state.
    void
    setTimeout(int timeout)
    Set transaction timeout in seconds.
    void
    Verify that the transaction 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 transaction, assign random transaction id and initialize reads/writes hashmaps with default capacities.

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

    • Txn

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

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

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

    • getId

      public long getId()
      Return transaction ID.
    • setTimeout

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

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

    • getTimeout

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

      public void verifyCommand()
      Verify that the transaction 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 transaction namespace only if doesn't already exist. If namespace already exists, verify new namespace is the same.
    • getNamespace

      public String getNamespace()
      Return transaction namespace.
    • setDeadline

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

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

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

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

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

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

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

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

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