Important
Helios features are now enabled during weekly update windows and are no longer directly tied to SingleStore engine releases. Refer to the release notes to view the latest features available in your Helios cluster.
Two-Phase Transaction Commit
On this page
SingleStore supports atomic, distributed transactions.
The 2PC Protocol
The 2PC protocol ensures that all changes in a transaction are either committed or rolled back.
-
The transaction commits: All of the transaction's updates on all involved nodes are completed.
-
The transaction rolls back: None of the updates are completed.
The 2PC protocol coordinates among the nodes to ensure this all-or-nothing behavior, also called transaction atomicity, is enforced.
2PC Workflow
In 2PC, a node is designated as the coordinator and is responsible for coordinating transaction commits across other participating nodes.
The 2PC protocol operates in two phases, a prepare phase and a commit phase.
Prepare Phase
In the prepare phase, the coordinator (the aggregator handling the transaction) contacts participating nodes and sends a prepare request to all the participants in parallel.
If one or more nodes have indicated that they cannot commit by voting NO, the coordinator sends rollback requests to all the nodes to roll back the entire transaction.
Commit Phase
Once all the votes are received, if all nodes have indicated they are OK to commit, the coordinator sends out commit requests.ack) back to the coordinator to indicate their local commit is complete.
Two-phase commit guarantees an all-or-nothing commit decision across participating nodes, but survival of an acknowledged commit after a crash is a separate durability question.ASYNC DURABILITY, a node can acknowledge COMMIT before its log records are hardened to disk.
Note
When all participants have prepared successfully, the transaction’s final outcome is a commit; a later coordinator/leaf failure does not change the final outcome to rollback.
If the coordinator backs off or fails, the participants can use the 2PC resolution protocol to determine the outcome and complete the transaction during recovery.
In high-availability (HA) deployments, if a data node (leaf) dies during a distributed transaction, an HA cluster can often still finish deciding the transaction without waiting for that exact node to come back online.
2PC Example
Consider a songs table and the following query.songs table which are distributed across many nodes.
CREATE TABLE songs(Id INT,Name TEXT,Genre TEXT,Rating DOUBLE,PublishTimestamp DATETIME);
UPDATE songsSET Genre = 'Pop' WHERE Genre = 'Pop Music';
This query updates all the rows in the songs table that have Genre = 'Pop Music' to Genre = 'Pop'.Genre='Pop Music' is updated, or none are.
The following figure illustrates 2PC for the songs table when the affected rows are distributed across two nodes.YES or NO.YES, then commit requests are sent to both nodes.ack to the coordinator.NO, the rollback phase completes when all participating nodes have rolled back their local transactions and acknowledged the outcome.
In SingleStore, the coordinator role is performed by the aggregator and Node 1, Node 2 are leaf nodes.
All queries such as the preceding are run in transactions.
The discussion and behavior apply to all data updates including INSERT and DELETE DML commands.
Troubleshooting 2PC
When a distributed transaction enters 2PC, an interrupt or failure can prevent SingleStore from returning a confirmed final result to the client.
OperationalError: 1997: Attempted to interrupt transaction execution, but the outcome is unknown because the transaction was already in its commit phase.
This error message means that the transaction outcome is unknown from the client's perspective.
Therefore, when Error 1997 is returned, verify the final result in the affected data before retrying application logic.
2PC Impacts
The 2PC feature is enabled by default on all SingleStore 8.
Last modified: