Transaction and System Concepts
Transaction and System Concepts
This section explains important concepts used in transaction processing in a DBMS.
The main topics are:
-
Transaction states and operations
-
System log
-
Commit point of a transaction
-
Buffer management (brief idea)
1. Transaction States and Additional Operations
A transaction is an atomic unit of work, meaning:
It must be completed fully or not executed at all.
To manage transactions properly, the DBMS keeps track of several transaction operations.
Important Transaction Operations
1. BEGIN_TRANSACTION
-
Marks the start of a transaction.
-
The DBMS begins tracking the transaction.
Example:
2. READ and WRITE
These are the database operations inside a transaction.
-
READ → retrieves data from the database
-
WRITE → updates data in the database
Example:
3. END_TRANSACTION
Indicates that the transaction has finished executing its read and write operations.
However, the DBMS still needs to decide:
-
Whether the transaction should commit, or
-
Whether it must abort.
4. COMMIT_TRANSACTION
This indicates that the transaction has completed successfully.
Effects:
-
All updates become permanent
-
Changes cannot be undone
Example:
5. ROLLBACK / ABORT
This indicates that the transaction failed.
Effects:
-
All changes made by the transaction are undone
-
Database returns to the previous consistent state
Example:
2. Transaction States
During its life cycle, a transaction passes through different states.
1. Active State
-
The transaction has started execution.
-
It performs READ and WRITE operations.
Example:
2. Partially Committed State
-
Transaction has finished its operations.
-
The system performs final checks before committing.
These checks include:
-
Concurrency control validation
-
Logging of changes
3. Committed State
-
The transaction has reached the commit point.
-
All changes are permanently stored in the database.
Even if the system crashes, the updates must remain.
4. Failed State
The transaction moves to this state if:
-
An error occurs
-
The system aborts the transaction
-
Concurrency control rejects the transaction
5. Terminated State
-
The transaction leaves the system.
-
All temporary transaction information is removed.
Transaction State Flow
OR
3. The System Log
To recover from failures, the DBMS maintains a system log.
The log is a special file that records all important transaction activities.
Characteristics of the Log
-
Stored on disk
-
Sequential append-only file
-
Keeps history of transaction operations
It records operations such as:
-
Start of transactions
-
Data updates
-
Commit or abort events
Log Buffers
Before writing to disk, log entries are stored temporarily in main memory buffers called log buffers.
Process:
When the buffer is full, it is written to disk.
This reduces the number of disk write operations.
Types of Log Records
Each log record contains a transaction ID (T).
1. Start Transaction
Indicates transaction T has started.
2. Write Item
Means transaction T changed item X.
Example:
Both values are stored so that the system can:
-
Undo changes
-
Redo changes
3. Read Item
Indicates transaction T read item X.
(Not always stored unless auditing is required.)
4. Commit
Transaction T completed successfully.
Its changes can be permanently stored.
5. Abort
Transaction T failed.
Its changes must be undone.
Undo and Redo Operations
The log helps perform two important recovery actions.
Undo
If a transaction fails:
-
The DBMS reverses its updates.
-
Database items are restored to their old values.
Example:
Redo
Sometimes a transaction commits but the system crashes before writing data to disk.
Using the log, the DBMS reapplies the updates.
Example:
4. Commit Point of a Transaction
A commit point is the moment when a transaction becomes permanent.
A transaction reaches the commit point when:
-
All operations are successfully executed
-
All updates are recorded in the log
After that, the DBMS writes:
into the log.
Why Commit Point Is Important
After reaching the commit point:
-
The transaction cannot be undone
-
Its changes must remain in the database permanently
Recovery After System Crash
During recovery, the system checks the log.
Case 1: Transaction Started but Not Committed
These transactions must be rolled back.
Case 2: Transaction Committed
These transactions must be redone if necessary.
Force Writing the Log
Before committing a transaction, the DBMS forces the log buffer to be written to disk.
This process is called:
Force-writing the log
Reason:
If the system crashes, the log must contain the transaction information needed for recovery.
Simple Overview of Transaction Processing
Summary
Transaction and system concepts ensure that:
-
Transactions execute safely
-
Failures can be recovered
-
Database consistency is preserved
The system log and commit mechanism are essential for reliable database recovery.

Comments
Post a Comment