Interface TransactionService

  • All Superinterfaces:
    AsyncTransactionService, AutoCloseable

    public interface TransactionService
    extends 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 Detail

      • get

        @CheckForNull
        Long get​(long startTimestamp)
        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
      • putUnlessExists

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

        default void putUnlessExistsMultiple​(Map<Long,​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.
        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 AutoCloseable