Transaction and System Concepts

 

Transaction and System Concepts

This section explains important concepts used in transaction processing in a DBMS.

These concepts help the system manage transactions, ensure recovery from failures, and maintain database consistency.

The main topics are:

  1. Transaction states and operations

  2. System log

  3. Commit point of a transaction

  4. 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:

BEGIN_TRANSACTION

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:

READ(X) WRITE(X)

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:

COMMIT

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:

ROLLBACK

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:

BEGIN → ACTIVE

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

Begin Transaction ↓ Active ↓ Partially CommittedCommitted ↓ Terminated

OR

Active ↓ Failed ↓ Rollback ↓ Terminated





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:

TransactionLog Buffer (memory)Log File (disk)

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

[start_transaction, T]

Indicates transaction T has started.


2. Write Item

[write_item, T, X, old_value, new_value]

Means transaction T changed item X.

Example:

X : 100120

Both values are stored so that the system can:

  • Undo changes

  • Redo changes


3. Read Item

[read_item, T, X]

Indicates transaction T read item X.

(Not always stored unless auditing is required.)


4. Commit

[commit, T]

Transaction T completed successfully.

Its changes can be permanently stored.


5. Abort

[abort, T]

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:

X = 100 → 120 Undo → X = 100

Redo

Sometimes a transaction commits but the system crashes before writing data to disk.

Using the log, the DBMS reapplies the updates.

Example:

Redo → X = 120

4. Commit Point of a Transaction

A commit point is the moment when a transaction becomes permanent.

A transaction reaches the commit point when:

  1. All operations are successfully executed

  2. All updates are recorded in the log

After that, the DBMS writes:

[commit, T]

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

[start_transaction, T] (no commit record)

These transactions must be rolled back.


Case 2: Transaction Committed

[start_transaction, T] [commit, T]

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

Transaction Begins ↓ Operations (Read/Write) ↓ Log Records Created ↓ Checks for CommitCommit Point ↓ Permanent Database Update

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

Popular posts from this blog

Database Management Systems DBMS PCCST402 Semester 4 KTU CS 2024 Scheme

Data Models, Schemas and Instances

Introduction to Database Management System -DBMS