Transaction
A transaction is a sequence of operations that are carried out together and form a single unit. It must be either end up completed or is completely undone.
Transactions (TX) should have 4 properties, ACID principle.
- Atomic. The transaction is never half-done.
- Consistent. TX changes DB from one consistent state into another consistent state.
- Isolation. Data updates within a TX should not be visible to other TXs until this TX is completed.
- Durable. When a TX is done, it really is done and the updates will not disappear.
In the context of distributed systems, completing a TX may involve multiple servers. To ensure atomicity, we have to manage the behaviour of the servers (e.g. rollback on failure), and thus we use a 2 phase commit mechanism.
2 Phase Commit
A 2 phase commit procedure requires 1 coordinator (manager) and several participants (cohorts). The schema is divided into 2 phases:
-
Commit-Request (Voting) Phase
-
Commit Phase
