Unit 4

Unit 4: Distributed Transaction Processing - Complete Notes


1. Transactions

Definition:

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

  • It ensures that a system remains in a consistent state, even in the event of failures.

ACID Properties:

  1. Atomicity:

    • All operations in a transaction are completed successfully, or none are.

    • Example: Money transfer between two accounts (both debit and credit must succeed).

  2. Consistency:

    • A transaction brings the system from one valid state to another.

    • Example: Ensuring account balances are never negative.

  3. Isolation:

    • Transactions are executed independently without interference.

    • Example: Two users transferring money from the same account simultaneously.

  4. Durability:

    • Once a transaction is committed, its effects are permanent.

    • Example: After a successful transaction, the changes are saved even if the system crashes.


Mind Map for Transactions:


2. Nested Transactions

Definition:

  • A nested transaction is a transaction that contains other transactions (subtransactions).

  • It allows for modular and hierarchical transaction management.

How It Works:

  1. Parent and Child Transactions:

    • A parent transaction can have multiple child transactions.

    • Example: Booking a flight (parent) and reserving a seat (child).

  2. Commit and Rollback:

    • If a child transaction fails, only that part is rolled back, not the entire parent transaction.

    • Example: If seat reservation fails, the flight booking can still proceed.

Advantages:

  1. Modularity:

    • Breaks down complex transactions into smaller, manageable parts.

  2. Partial Rollback:

    • Only the failed subtransaction is rolled back, reducing the impact of failures.


Mind Map for Nested Transactions:


3. Locks

Definition:

  • Locks are mechanisms used to control access to shared resources in a transaction.

  • They ensure that only one transaction can access a resource at a time.

Types of Locks:

  1. Shared Lock (Read Lock):

    • Multiple transactions can read a resource simultaneously.

    • Example: Multiple users reading a file.

  2. Exclusive Lock (Write Lock):

    • Only one transaction can write to a resource at a time.

    • Example: A single user editing a file.

Challenges:

  1. Deadlocks:

    • Two transactions waiting for each other to release locks.

    • Example: Transaction A locks Resource 1 and waits for Resource 2, while Transaction B locks Resource 2 and waits for Resource 1.

  2. Performance Overhead:

    • Lock management can introduce latency.

    • Example: Delays in accessing heavily locked resources.


Mind Map for Locks:


4. Optimistic Concurrency Control

Definition:

  • Optimistic Concurrency Control (OCC) assumes that conflicts are rare and allows transactions to proceed without locking resources.

  • Conflicts are detected and resolved at the end of the transaction.

How It Works:

  1. Read Phase:

    • Transactions read data without locking.

  2. Validation Phase:

    • Before committing, the system checks for conflicts.

  3. Write Phase:

    • If no conflicts are found, the transaction is committed; otherwise, it is rolled back.

Advantages:

  1. High Concurrency:

    • Transactions can proceed without waiting for locks.

    • Example: Collaborative editing tools like Google Docs.

  2. Low Overhead:

    • No need to manage locks, reducing system overhead.

Disadvantages:

  1. Rollback Overhead:

    • If conflicts are frequent, rollbacks can degrade performance.

    • Example: High-contention systems like stock trading platforms.


Mind Map for Optimistic Concurrency Control:


5. Timestamp Ordering

Definition:

  • Timestamp Ordering assigns a unique timestamp to each transaction and ensures that transactions are executed in timestamp order.

How It Works:

  1. Timestamp Assignment:

    • Each transaction is assigned a timestamp when it starts.

  2. Conflict Resolution:

    • If a transaction tries to access data modified by a newer transaction, it is rolled back.

    • Example: Transaction A (timestamp 1) tries to read data updated by Transaction B (timestamp 2).

Advantages:

  1. No Deadlocks:

    • Timestamps ensure a strict order, preventing deadlocks.

  2. Simple Implementation:

    • Easy to implement compared to locking mechanisms.

Disadvantages:

  1. Starvation:

    • Older transactions may be repeatedly rolled back.

    • Example: A low-priority transaction constantly delayed by high-priority transactions.


Mind Map for Timestamp Ordering:


6. Flat vs. Nested Distributed Transactions

Flat Transactions:

  • A single-level transaction with no subtransactions.

  • Example: Transferring money between two accounts.

Nested Transactions:

  • A transaction containing subtransactions.

  • Example: Booking a flight (parent) and reserving a seat (child).

Comparison:

Feature

Flat Transactions

Nested Transactions

Structure

Single-level

Hierarchical (parent-child)

Complexity

Simple

Complex

Rollback

Entire transaction rolled back

Only failed subtransaction rolled back

Use Case

Simple operations

Complex, modular operations


Mind Map for Flat vs. Nested Transactions:


7. Atomic Commit Protocols

Definition:

  • Atomic Commit Protocols ensure that a distributed transaction is either fully committed or fully rolled back across all nodes.

Types:

  1. Two-Phase Commit (2PC):

    • A coordinator ensures all participants agree to commit or abort.

    • Example: Distributed databases like MySQL Cluster.

  2. Three-Phase Commit (3PC):

    • Adds a pre-commit phase to reduce blocking in case of failures.

    • Example: High-availability systems like Google Spanner.


Mind Map for Atomic Commit Protocols:


8. Concurrency Control in Distributed Transactions

Definition:

  • Concurrency Control ensures that multiple transactions can execute simultaneously without causing inconsistencies.

Techniques:

  1. Lock-Based Protocols:

    • Use locks to control access to resources.

    • Example: Shared and exclusive locks.

  2. Timestamp Ordering:

    • Use timestamps to order transactions.

    • Example: Conflict resolution using timestamps.

  3. Optimistic Concurrency Control:

    • Assume conflicts are rare and resolve them at commit time.

    • Example: Collaborative editing tools.


Mind Map for Concurrency Control:


9. Distributed Deadlocks

Definition:

  • Distributed Deadlocks occur when transactions in a distributed system are waiting for resources held by each other.

Detection and Prevention:

  1. Detection Algorithms:

    • Detect deadlocks by analyzing wait-for graphs.

    • Example: Chandy-Misra-Haas algorithm.

  2. Prevention Techniques:

    • Avoid deadlocks by resource allocation strategies.

    • Example: Timeout-based resource allocation.


Mind Map for Distributed Deadlocks:


10. Transaction Recovery

Definition:

  • Transaction Recovery ensures that a system can recover from failures and maintain data consistency.

Techniques:

  1. Log-Based Recovery:

    • Maintain a log of all transactions to replay or undo operations.

    • Example: Database systems like Oracle.

  2. Checkpointing:

    • Periodically save the system state to reduce recovery time.

    • Example: File systems like NTFS.


Mind Map for Transaction Recovery:


11. Overview of Replication and Distributed Multimedia Systems

Replication:

  • Definition: Creating multiple copies of data across nodes for fault tolerance and performance.

  • Example: Replicating databases in a distributed system.

Distributed Multimedia Systems:

  • Definition: Systems that handle multimedia data (e.g., video, audio) across distributed nodes.

  • Example: Streaming platforms like Netflix or YouTube.


Mind Map for Replication and Multimedia Systems:


Summary of Unit 4: Distributed Transaction Processing

  • Transactions ensure ACID properties (Atomicity, Consistency, Isolation, Durability).

  • Nested Transactions allow modular and hierarchical transaction management.

  • Locks and Optimistic Concurrency Control manage access to shared resources.

  • Timestamp Ordering ensures transactions are executed in a strict order.

  • Atomic Commit Protocols (2PC, 3PC) ensure distributed transactions are committed or rolled back atomically.

  • Concurrency Control and Deadlock Handling maintain system consistency.

  • Transaction Recovery ensures system resilience to failures.

  • Replication and Distributed Multimedia Systems handle data redundancy and multimedia processing.


Final Mind Map for Unit 4:

Last updated