1 of 18

Unit 5: Advanced Transaction Processing & Concurrency Control

Prepared By: Mr. Akshay D. Thorat

2 of 18

Introduction to Transactions

​

  • A transaction is a sequence of operations performed as a single logical unit of work

​

  • Ensures data consistency even in case of failures

​

  • Examples: Bank transfer, ticket booking, order placement

​

  • Must satisfy ACID properties

3 of 18

ACID Properties

​

  • Atomicity: All or nothing execution

​

  • Consistency: Database moves from one valid state to another

​

  • Isolation: Concurrent transactions do not interfere

​

  • Durability: Results persist even after system failure

​

  • Foundation of reliable transaction processing

4 of 18

Transaction States

​

  • Active

​

  • Partially Committed

​

  • Committed

​

  • Failed

​

  • Aborted

​

  • State transitions ensure controlled execution and recovery

5 of 18

Simple Transaction Model

​

  • Read and write operations

​

  • Example:
    • read(X)
    • X = X – 100
    • write(X)

​

  • Transactions operate on local copies before committing

​

  • Ensures isolation and consistency

​

6 of 18

Schedules in Transaction Processing

​

  • Schedule: Order of operations from multiple transactions

​

  • Types:
    • Serial
    • Non‑serial
    • Serializable

​

  • Goal: Allow concurrency without violating correctness

7 of 18

Serializability

​

  • Ensures concurrent execution behaves like a serial schedule

​

  • Types:
    • Conflict Serializability
    • View Serializability

​

  • Conflict serializability uses precedence graphs

​

  • A schedule is serializable if graph has no cycles

8 of 18

Need for Concurrency Control

​

  • Prevents:
    • Lost updates
    • Dirty reads
    • Unrepeatable reads
    • Phantom reads

​

  • Ensures isolation among concurrent transactions

​

  • Improves system throughput

9 of 18

Lock-Based Protocols

​

  • Shared Lock (S): Read-only

​

  • Exclusive Lock (X): Read + Write

​

  • Lock Compatibility Matrix

​

  • Ensures controlled access to data items

​

  • Prevents conflicts between transactions

10 of 18

Two-Phase Locking (2PL)

​

  • Growing Phase: Acquire locks

​

  • Shrinking Phase: Release locks

​

  • Guarantees conflict serializability

​

  • Variants:
    • Basic 2PL
    • Strict 2PL
    • Rigorous 2PL

11 of 18

Deadlocks in DBMS

​

  • Occurs when transactions wait indefinitely for each other

​

  • Example:
    • T1 waits for X locked by T2
    • T2 waits for Y locked by T1

​

  • System halts unless resolved

12 of 18

Deadlock Handling Techniques

​

  • Deadlock Prevention:
    • Wait‑Die
    • Wound‑Wait

​

  • Deadlock Detection:
    • Wait‑for graph

​

  • Deadlock Recovery:
    • Abort victim transaction
    • Rollback and restart

13 of 18

Multiple Granularity Locking

​

  • Locks applied at different levels:
    • Database
    • File
    • Page
    • Record
    • Field
  • Uses intention locks (IS, IX, SIX)

​

  • Improves concurrency and reduces overhead

14 of 18

Timestamp-Based Protocols

​

  • Each transaction gets a unique timestamp

​

  • Ensures serializability based on timestamps

​

  • Types:
    • Basic timestamp ordering
    • Thomas Write Rule
  • Avoids deadlocks completely

​

15 of 18

Thomas Write Rule

​

  • Allows certain outdated writes to be ignored

​

  • Improves concurrency

​

  • Used when write operations do not affect correctness

​

  • More flexible than basic timestamp ordering

16 of 18

Validation-Based (Optimistic) Protocols

​

  • Assumes low conflict probability

​

  • Phases:
    • Read Phase
    • Validation Phase
    • Write Phase

​

  • Used in systems with high read and low write operations

17 of 18

Recovery & Logging

​

  • Ensures durability after failures
  • Log-based recovery:

​

    • Write-Ahead Logging (WAL)
    • Redo and Undo operations
  • Checkpointing:

​

    • Reduces recovery time
    • Saves system state periodically

18 of 18

Summary of Transaction Processing

​

  • ACID ensures reliability

​

  • Serializability ensures correctness

​

  • Locking & timestamp protocols ensure isolation

​

  • Deadlock handling ensures smooth execution

​

  • Recovery ensures durability

​

  • Essential for mission-critical applications