Interface TransactionService

  • All Superinterfaces:
    AsyncTransactionService, java.lang.AutoCloseable

    public interface TransactionService
    extends java.lang.AutoCloseable, AsyncTransactionService
    Transaction service is used by the atlas protocol to determine is a given transaction has been committed or aborted. Transaction services may assume that data tables are written at timestamps greater than or equal to AtlasDbConstants.STARTING_TS (1). A given startTimestamp will only ever have one non-null value. This means that non-null values returned from this service can be aggressively cached. Caching negative look ups should not be done for performance reasons. If a null value is returned, that startTimestamp will likely be rolled back and set to TransactionConstants.FAILED_COMMIT_TS (-1).
    • Method Summary

      All Methods Instance Methods Abstract Methods Default Methods Deprecated Methods 
      Modifier and Type Method Description
      void close()
      Frees up resources associated with the transaction service.
      java.lang.Long get​(long startTimestamp)
      Deprecated.
      java.util.Map<java.lang.Long,​java.lang.Long> get​(java.lang.Iterable<java.lang.Long> startTimestamps)
      Deprecated.
      TransactionStatus getV2​(long startTimestamp)
      Gets the commit status associated with a given start timestamp.
      java.util.Map<java.lang.Long,​TransactionStatus> getV2​(java.lang.Iterable<java.lang.Long> startTimestamps)  
      void markInProgress​(long startTimestamp)
      In practice, a transaction on schema version >= 4 must call this method before any information about its start timestamp is persisted into the KVS; i.e.
      default void markInProgress​(java.lang.Iterable<java.lang.Long> startTimestamps)  
      void putUnlessExists​(long startTimestamp, long commitTimestamp)
      This operation is guaranteed to be atomic and only commit the value if it hasn't already been committed.
      default void putUnlessExists​(java.util.Map<java.lang.Long,​java.lang.Long> startTimestampToCommitTimestamp)
      This operation seeks to commit multiple transactions; implementations may override it if this can be done more efficiently than performing individual putUnlessExists(long, long) operations.
    • Method Detail

      • get

        @CheckForNull
        @Deprecated
        java.lang.Long get​(long startTimestamp)
        Deprecated.
        Gets the commit timestamp associated with a given start timestamp. Non-null responses may be cached on the client-side. Null responses must not be cached, as they could subsequently be updated. This function may return null, which means that the transaction in question had not been committed, at least at some point between the request being made and it returning.
        Parameters:
        startTimestamp - start timestamp of the transaction being looked up
        Returns:
        timestamp which the transaction committed at, or null if the transaction had not committed yet.
      • get

        @Deprecated
        java.util.Map<java.lang.Long,​java.lang.Long> get​(java.lang.Iterable<java.lang.Long> startTimestamps)
        Deprecated.
      • getV2

        @CheckForNull
        TransactionStatus getV2​(long startTimestamp)
        Gets the commit status associated with a given start timestamp. Known responses may be cached on the client-side. Future result may return unknown transaction status, which means that the transaction in question has been concluded i.e. its status cannot change.
        Parameters:
        startTimestamp - start timestamp of the transaction being looked up
        Returns:
        the status of the transaction.
      • getV2

        java.util.Map<java.lang.Long,​TransactionStatus> getV2​(java.lang.Iterable<java.lang.Long> startTimestamps)
      • markInProgress

        void markInProgress​(long startTimestamp)
        In practice, a transaction on schema version >= 4 must call this method before any information about its start timestamp is persisted into the KVS; i.e. KVS writes, writing to the sweep queue, etc. i.e. this method MUST be called for each start timestamp before is ever called.
      • markInProgress

        default void markInProgress​(java.lang.Iterable<java.lang.Long> startTimestamps)
      • putUnlessExists

        void putUnlessExists​(long startTimestamp,
                             long commitTimestamp)
                      throws KeyAlreadyExistsException
        This operation is guaranteed to be atomic and only commit the value if it hasn't already been committed. The naming is not accurate as this operation can differ in implementation.
        Throws:
        KeyAlreadyExistsException - If this transaction was already committed, but get(long) should be called to check what the value was set to. This may throw spuriously due to retry.
        java.lang.RuntimeException - If a runtime exception is thrown, this operation may or may not have ran.
      • putUnlessExists

        default void putUnlessExists​(java.util.Map<java.lang.Long,​java.lang.Long> startTimestampToCommitTimestamp)
        This operation seeks to commit multiple transactions; implementations may override it if this can be done more efficiently than performing individual putUnlessExists(long, long) operations. This operation is NOT atomic. On success, it is guaranteed that all start/commit timestamp pairs have been successfully stored. However, on failure, start/commit timestamp pairs may or may not have been stored; users should check the state of the transaction service with get(Iterable) if they need to know what has happened.
        Parameters:
        startTimestampToCommitTimestamp - map of start timestamps to corresponding commit timestamps
        Throws:
        KeyAlreadyExistsException - if the value corresponding to some start timestamp in the map already existed.
        java.lang.RuntimeException - if an error occurred; in this case, the operation may or may not have ran.
      • close

        void close()
        Frees up resources associated with the transaction service.
        Specified by:
        close in interface java.lang.AutoCloseable