Uploaded image for project: 'Ignite'
  1. Ignite
  2. IGNITE-15086

Design a public tx API

    XMLWordPrintableJSON

Details

    • Task
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • None
    • 3.0.0-alpha3
    • None

    Description

      Design a public tx API.

      The proposed design includes async and sync APIs to execute a transaction.

      The transaction facade looks like this:

      /**
       * Ignite Transactions facade.
       */
      public interface IgniteTransactions {
          /**
           * Begins the transaction.
           *
           * @return The future.
           */
          CompletableFuture<Transaction> beginAsync();
      
          /**
           * Synchronously executes a closure within a transaction.
           * <p>
           * If the closure is executed normally (no exceptions), the transaction is automatically committed.
           *
           * @param clo The closure.
           */
          void runInTransaction(Consumer<Transaction> clo);
      }
      

      Transacton interface:

      /**
       * The transaction.
       */
      public interface Transaction {
          /**
           * Synchronously commits a transaction.
           * Does nothing if it's already finished by committing or rolling back.
           */
          void commit();
      
          /**
           * Asynchronously commits a transaction.
           * Does nothing if it's already finished by committing or rolling back.
           *
           * @return The future.
           */
          CompletableFuture<Void> commitAsync();
      
          /**
           * Synchronously rolls back a transaction.
           * Does nothing if it's already finished by committing or rolling back.
           */
          void rollback();
      
          /**
           * Asynchronously rolls back a transaction.
           * Does nothing if it's already finished by committing or rolling back.
           *
           * @return The future.
           */
          CompletableFuture<Void> rollbackAsync();
      }
      

      Example of synchronous transaction:

              igniteTransactions.runInTransaction(tx -> {
                  Table txTable = table.withTransaction(tx); // table view enlisted in the transaction.
      
                  txTable.upsertAsync(...);
      
                  tx.commit(); 
              });
      

      Example of asynchronous transaction:

              igniteTransactions.beginAsync()
                  .thenApply(tx -> accounts.withTransaction(tx))
                  .thenCompose(txTbl -> txTbl.upsertAsync(...).thenApply(i -> txTbl.transaction()))
                  .thenCompose(Transaction::commitAsync);
      

      Attachments

        Issue Links

          Activity

            People

              ascherbakov Alexey Scherbakov
              ascherbakov Alexey Scherbakov
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 1.5h
                  1.5h