The Journey of 100DaysofCode aka 100DaysofMongoDB (@Aasawari_24)

Day20 as #100DaysofMongoDB as #100daysofcode

Discussing on how WiredTiger uses Transactions and how are WiredTiger helpful in Transactions.

WiredTiger uses Transactions within the API to start and stop the transactions within a session. If the user doesn’t not explicitly enables the transaction, it gets enabled for the operations.

The Lifecycle of Transactions

It can be explained through the following diagram:

Source: WiredTiger: Transactions (Architecture Guide)

The transaction gets committed automatically when when explicitly enabled else, when enabled via WT_SESSION::begin_transaction , it will be active until committed or rolled back.

Like any other database, the WiredTiger enforce the ACID properties in the Transactions.

Along with the ACID properties, WiredTiger provides a mechanism of Timestamps.
These are sequence numbers associated with each operations. Users can assign a read timestamp at the beginning of the transaction. And updates smaller or equal to read timestamp would be visible.
Users can use any 64 bit unsigned integer as logical timestamps.

A stable timestamp is the minimum timestamp that a new operation can commit it.

Along with the timestamp, transaction also provides the Visibility feature.
The operation is visible only when both transaction-id and timestamp are visible.

In order to read the key, WiredTiger traverses until a visible update ifs found. WiredTiger are organise as singly linked list with latest transaction at head, known as the update chain. If unavailable, WiredTiger will search the history store to check if there is a version to the reader.

WiredTiger also has prepared Transactions which work under snapshot isolations.
By introducing the prepared stage, a two-phase distributed transaction algorithm can rely on the prepared state to reach consensus among all the nodes for committing.

The WiredTiger also has prepared timestamp and durable timestamp which prevents the slow transaction with stable global timestamp.

If you have any questions and suggestions related to wired tiger, feel free to post on the community platforms.

Thanks
Aasawari

3 Likes