4 unit. pdf
4 unit. pdf
1. Explain why timestamp-based concurrency control allows schedules that are not recoverable.
Describe how it can be modified through buffering to disallow such schedules.
Timestamp-based concurrency control assigns a unique timestamp to each transaction at the time
of its initiation. This ensures that the relative ordering of transactions is determined by their
timestamps, with older transactions having priority over younger ones. However, this mechanism
can create schedules that are not recoverable, especially in cases of dirty reads. A dirty read
happens when a transaction reads data written by another transaction that has not yet committed.
If the transaction that made the modification is rolled back (after the other transaction has read it),
the data used by the transaction is inconsistent, resulting in an irrecoverable schedule.
For example, if Transaction writes a value to a data item and Transaction reads that value before
commits, a failure in could lead to an inconsistent database. If commits based on uncommitted
data from , recovery from this situation would be impossible since might have already committed
based on a value that is no longer valid.
This issue can be mitigated through buffering, where transactions that depend on uncommitted
data are delayed until the transaction they depend on either commits or rolls back. Buffering
essentially prevents a transaction from committing until all the transactions it depends on have
either committed or been rolled back, ensuring that only committed data is used by subsequent
transactions. This change helps in preventing dirty reads and, thus, ensures that schedules are
recoverable, meaning that the system can revert to a consistent state even after failures.
4. Define failure classification. What are the different types of failures in a database system?
Failures in a database system can be classified into several types based on their causes and
impacts:
1. Transaction Failures: These failures occur during the execution of a single transaction and may
result from various factors:
Logical Errors: These errors occur when a transaction cannot complete due to an internal issue,
such as an invalid input or violation of a constraint (e.g., trying to insert a record with a duplicate
primary key).
System Errors: These errors occur when the database system detects an issue, such as a deadlock
or an unexpected termination of a transaction due to resource contention or a software bug.
2. System Crashes: A system crash occurs when the database management system (DBMS)
crashes due to hardware failure, software bugs, or power loss. This can lead to the loss of data that
has not been written to permanent storage (e.g., in-memory data).
3. Disk Failures: Disk failures occur when the underlying storage device, such as a hard drive or
solid-state drive (SSD), fails due to physical damage, like a head crash, or due to issues in data
transfer. A disk failure can cause the loss of data or the corruption of stored data, which may be
irrecoverable if not properly backed up.
Understanding these different types of failures helps in implementing recovery mechanisms such
as log-based recovery, checkpointing, and rollback operations to ensure the integrity and
consistency of the database.
5. Differentiate between prevention and detection of deadlocks.
Deadlocks occur when two or more transactions are waiting indefinitely for each other to release
resources, such as locks, and thus cannot proceed. Handling deadlocks in a database system can
be done through either prevention or detection mechanisms:
1. Deadlock Prevention:
Wait-Die Scheme: In this scheme, older transactions are allowed to wait for resources held by
younger transactions, while younger transactions requesting the same resource are rolled back
("killed"). This prevents deadlocks by ensuring that a younger transaction cannot block an older one.
Wound-Wait Scheme: In this scheme, older transactions force younger transactions to roll back
when they request the same resource, ensuring that no younger transaction can block an older one.
The system "wounds" younger transactions that are blocked and "waits" for older transactions to
proceed.
Prevention techniques avoid deadlocks by designing transaction behavior in a way that makes it
impossible for deadlocks to occur. However, this comes at the cost of potentially higher overhead,
as transactions may be aborted and restarted frequently.
2. Deadlock Detection:
Deadlock detection involves periodically checking for cycles in a wait-for graph, which is a directed
graph that tracks the waiting relationships between transactions. If a cycle is detected, it indicates a
deadlock.
Once a deadlock is detected, one or more transactions in the cycle are selected to be rolled back to
break the deadlock. The choice of which transaction to abort may depend on factors like the
transaction's age, resources it holds, or the cost of aborting it.
Detection mechanisms provide more flexibility and efficiency by allowing transactions to continue
executing as long as no deadlock exists, but the system must periodically check for deadlocks,
which adds overhead.