Dbms Unit 4&5 (GPT)
Dbms Unit 4&5 (GPT)
(SAQs)1. What is a transaction? Sketch and explain the transaction state diagram.
A transaction is a unit of program execution that accesses and possibly updates data. A
transaction ensures that database integrity is maintained despite system failures or concurrent
executions.
State diagram:
9. Short notes:
Phantom phenomenon: Occurs when range queries miss newly inserted tuples due
to lack of proper locking.
Cursor stability: Locks a tuple only during access; read locks are released
immediately after reading.
Weak isolation levels:
o Read uncommitted: May read uncommitted changes.
o Read committed: Reads committed data but doesn’t ensure repeatable reads.
o Repeatable read: Ensures same data read in multiple operations but doesn’t
prevent phantoms.
Starvation problem: A transaction continuously waits due to others being
prioritized, often mitigated by fair scheduling.
1. Conflict Serializability
Conflict serializability ensures that the schedule of transactions can be rearranged into a serial
schedule using a sequence of swaps of non-conflicting operations. Conflicts occur when two
transactions perform operations on the same data item, and at least one of them is a write
operation.
1. Identify Transactions and Operations: List all read and write operations in the schedule.
o Draw directed edges between transactions if they conflict (e.g., one transaction
writes a data item that another reads).
3. Check for Cycles: If the precedence graph has no cycles, the schedule is conflict-serializable.
Graph Construction:
Conflict serializability guarantees consistency and is essential for ensuring that concurrent
transactions produce the same result as sequential execution.
2. View Serializability
View serializability ensures schedules produce the same final result as a serial schedule. It is broader
than conflict serializability and includes some schedules that are not conflict-serializable.
1. Same Initial Reads: Transactions reading initial values must match across schedules.
2. Same Intermediate Reads: For every data item read, the value must come from the same
transaction.
3. Same Final Writes: The final write of every data item in the schedule must be the same.
Example:
View Serializability checks if another serial schedule (e.g., T1 → T2 → T3) produces the same reads
and writes as the original schedule. If it does, the schedule is view-serializable.
View serializability is harder to test as it requires analyzing all potential serial schedules, but it
captures more permissible schedules compared to conflict serializability.
Locks control access to data to ensure consistency and isolation. Two primary lock types are:
1. Shared (S) Lock: Allows multiple transactions to read a data item simultaneously but
prevents writing.
2. Exclusive (X) Lock: Allows one transaction to read and write a data item, blocking others.
Locking Protocols:
Strict 2PL: Holds all locks until the transaction commits or aborts.
Rigorous 2PL: Keeps all locks until commit, including shared locks.
Example:
This ensures that T1’s write is not interfered with by T2’s read.
4. Lock-Based Protocols
Lock-based protocols are mechanisms for maintaining transaction serializability and isolation.
Key Variants:
1. Basic Two-Phase Locking: Ensures serializability by restricting the order of acquiring and
releasing locks.
2. Strict Two-Phase Locking: Avoids cascading rollbacks by holding exclusive locks until commit.
3. Rigorous Two-Phase Locking: Retains both shared and exclusive locks until commit,
providing stronger isolation.
Advantages:
Guarantees serializability.
Disadvantages:
This protocol assigns a unique timestamp to each transaction, dictating the order of operations to
ensure serializability.
Steps:
Example:
Timestamp ordering prevents deadlocks but can cause cascading rollbacks if dependencies exist.
6. Validation-Based Protocols
This optimistic approach assumes minimal conflicts and validates transactions before committing.
Phases:
1. Read Phase: Transaction reads data and performs operations on local copies.
Example:
T1 reads A and B.
Validation protocols are ideal for low-conflict scenarios and allow higher concurrency.
7. Multiple Granularity Locks
Granularity refers to the size of the data item being locked (e.g., database, table, row).
Lock Hierarchy:
1. Database level
2. Table level
3. Row level
Intention Locks: Indicate a transaction’s intention to acquire specific locks at a finer granularity.
Example:
This strategy balances concurrency and overhead by allowing finer-grained locking when necessary.
Deadlock: A state where transactions wait indefinitely for resources held by each other.
Prevention Strategies:
1. Wait-Die Scheme: Older transactions wait; younger transactions are rolled back.
Detection:
Recovery:
By combining these strategies, systems can handle deadlocks effectively while maintaining high
concurrency.
UNIT V
Short Answer Questions:
Transaction Failures:
System Crashes: Hardware or software failures causing system downtime (e.g., power
failure).
Disk Failures: Physical issues like disk crashes that may destroy data.
Volatile Storage: Temporary, lost during crashes (e.g., main memory, cache).
Purpose:
Steps:
Advantages:
Applications:
o Real-time web analytics and big data processing (e.g., Hadoop integration).
Types of Logging:
o Deferred Database Modification: Writes are recorded in logs but deferred until
commit. Ensures no partial changes occur.
Recovery Phases:
Logs are critical in maintaining database consistency, even during system crashes or failures.
Mechanisms:
o Database Buffering: Keeps active database blocks in memory, writing them back
when needed.
Key Practices:
o Follow Write-Ahead Logging (WAL): Logs are written before data is flushed to disk.
Features:
o Failure Detection: Detect primary site failure using redundant communication links.
o Control Transfer: Backup recovers using received logs and becomes the new primary.
Commit Strategies:
Document Stores (e.g., MongoDB): JSON-like documents, suitable for semi-structured data.
Key-Value Stores (e.g., Redis): Simple key-value pairs for caching and session management.
Graph Databases (e.g., Neo4j): Node-edge relationships for social networks and
recommendation engines.
NoSQL simplifies CRUD operations, offering flexibility and scalability for modern applications.