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:
Atomicity:
All operations in a transaction are completed successfully, or none are.
Example: Money transfer between two accounts (both debit and credit must succeed).
Consistency:
A transaction brings the system from one valid state to another.
Example: Ensuring account balances are never negative.
Isolation:
Transactions are executed independently without interference.
Example: Two users transferring money from the same account simultaneously.
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:
Parent and Child Transactions:
A parent transaction can have multiple child transactions.
Example: Booking a flight (parent) and reserving a seat (child).
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:
Modularity:
Breaks down complex transactions into smaller, manageable parts.
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:
Shared Lock (Read Lock):
Multiple transactions can read a resource simultaneously.
Example: Multiple users reading a file.
Exclusive Lock (Write Lock):
Only one transaction can write to a resource at a time.
Example: A single user editing a file.
Challenges:
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.
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:
Read Phase:
Transactions read data without locking.
Validation Phase:
Before committing, the system checks for conflicts.
Write Phase:
If no conflicts are found, the transaction is committed; otherwise, it is rolled back.
Advantages:
High Concurrency:
Transactions can proceed without waiting for locks.
Example: Collaborative editing tools like Google Docs.
Low Overhead:
No need to manage locks, reducing system overhead.
Disadvantages:
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:
Timestamp Assignment:
Each transaction is assigned a timestamp when it starts.
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:
No Deadlocks:
Timestamps ensure a strict order, preventing deadlocks.
Simple Implementation:
Easy to implement compared to locking mechanisms.
Disadvantages:
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:
Two-Phase Commit (2PC):
A coordinator ensures all participants agree to commit or abort.
Example: Distributed databases like MySQL Cluster.
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:
Lock-Based Protocols:
Use locks to control access to resources.
Example: Shared and exclusive locks.
Timestamp Ordering:
Use timestamps to order transactions.
Example: Conflict resolution using timestamps.
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:
Detection Algorithms:
Detect deadlocks by analyzing wait-for graphs.
Example: Chandy-Misra-Haas algorithm.
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:
Log-Based Recovery:
Maintain a log of all transactions to replay or undo operations.
Example: Database systems like Oracle.
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