Transactions

The Flow Service automatically uses transactions to execute operations with transaction-based components -- RDBPut, FileGet, and POP3, for example. You can also execute a flow as a single transaction and you can configure two-phase commits for databases that support XA.

Overview of Flow Service Transactions

There's a single transaction manager for a single execution of a flow, which is processed by a single request, including the processing of SubFlow components, an error-processing flow defined for the flow, and the NextFlow component. Components add transactions to the transaction manager. The transaction manager executes transactions in order when the time comes.

What's a Component Transaction?

Some, but not all, components use transactions. Below are some examples of the commit and rollback actions for some transaction-based components:

Component Commit action Rollback action
RDBPut The component issues a COMMIT statement to the database. The component issues a ROLLBACK statement to the database.
FileGet The component deletes the files after reading them. Do nothing.
POP3 The component deletes messages on the mail server after reading them. Do nothing

When Are Transactions Executed?

You can set the BeginTransaction property of the start component for a flow to specify when transactions are executed: Set BeginTransaction to true to execute the flow's transactions when the request finishes execution. The last end component's Transaction property specifies a commit or rollback.

Set BeginTransaction to false to commit when each component finishes execution. The component rolls back the transaction when an error occurs.

Example: Flow Transactions and RDB Component Transactions

Consider an RDBPut component that's configured to insert millions of records using loop processing. The Transaction property of the flow's start component determines when the transactions will execute:

BeginTransaction setting Time of commit
true After inserting all records.
false After each record is inserted.

Note that inserting millions of records in a single transaction will have better performance than executing millions of transactions, committing one record at a time.

Notes on Transaction Manager Execution

See below for notes on how the transaction manager executes transactions.

Transaction Priority

By default, a flow's transaction manager executes transactions by order and priority. The default order is first in, first out. High-priority transactions are inserted into the appropriate place in the order of execution.

Note

Currently, only database transactions have high priority.

Rejecting Duplicate Transactions

If multiple components add the same transactions, the transaction manager uses the first transaction only.

Executing database transactions: For example, RDB components that share the same connection add the same transaction to the transaction manager. This is also true for multiple flows running in the same request. In this example, the transaction manager has only one transaction.

Configuring Transactions in Flows

You can use the BeginTransaction property of a start component to execute a flow, a subflow, or an error-processing flow as a single transaction.

Configuring Flow Transactions

You can execute a flow in a single transaction by setting BeginTransaction to true in the flow's start component.

BeginTransaction setting Commit or Rollback time
true Commit or roll back all transactions after the flow finishes execution, including subflows.
false Commit when each component finishes execution.

Specifying the Commit Action

To specify the commit action when you set BeginTransaction to true, set the last end component's Transaction property to Commit or Rollback.

Calling a Subflow in the Same Transaction

Subflows execute in the same transaction as the parent flow when you set BeginTransaction to true for the parent flow's start component, regardless of the BeginTransaction setting for the subflow's start component.

Configuring Subflow Transactions

To execute a subflow in a single transaction, set BeginTransaction to false for the parent flow's start component and set BeginTransaction to true for the subflow's start component.

Configuring Error-Processing Flow Transactions

You can execute the error-processing flow in the same transaction or in a separate transaction.

When you set BeginTransaction to true for the parent flow, if a component throws an error, the transaction manager does nothing for that component and processing begins for the error-processing flow. The error-processing flow's BeginTransaction setting is ignored. You define the transaction's commit action by setting the Transaction property for the end component to Commit or Rollback.

When you set BeginTransaction to false in the parent flow, if a component throws an error, the transaction manager executes a rollback and then processing begins for the error-processing flow. In this case the error-processing flow's BeginTransaction setting isn't ignored. You can set BeginTransaction to true here to execute the error-processing flow as a single, separate transaction.

Configuring NextFlow Transactions

Normally, an end component commits or rollbacks the transaction. But, a NextFlow component provides a third option: DoNothing. If you set DoNothing, the transaction manager doesn't commit or roll back the transaction at the NextFlow component. The transaction continues into the next flow.

Configuring Distributed Transactions (Two-Phase Commits)

You can use the two-phase commit protocol to execute a transaction that's distributed across multiple databases. Two-phase commit is supported only for RDB connections.

Configuring a Two-Phase Commit

Set the XA property to true in the connection properties for each database participating in the two-phase commit.

Additionally, set BeginTransaction to true for the flow's start component.

Note

If don't set BeginTransaction to true, a run-time error may occur.

XA vs. non-XA Commit

To commit a series of non-XA transactions, the flow's transaction manager commits each individual transaction. If a transaction results in an error, the previous transaction is not rolled back.

Supported Databases

The Flow Service currently supports two-phase commits to the following databases:

Configuring Transaction Recovery for XA Transactions

The Flow Service can recover XA transactions if the server goes down while a transaction is running. See below to walk through the recovery process and configure transaction recovery.

Recovering from System Errors

The Flow Service recovers the transaction when one of the following system errors occurs while an XA transaction is running:

Note

Errors that occur during normal flow execution don't need recovery. The transaction manager rolls back the transactions during normal flow execution if an error occurs.

Configuring Transaction Recovery

You can configure the recovery interval, retry count, and email notifications in the management console, on the Settings > Services > Flow > Flow Engine page.