A deadlock occurs when two or more transactions wait indefinitely for each other to release locks on resources, causing all involved transactions to stop progressing.
Click to reveal answer
intermediate
Name one common method used to detect deadlocks in databases.
One common method is the wait-for graph, where transactions are nodes and edges represent waiting for locks. A cycle in this graph indicates a deadlock.
Click to reveal answer
intermediate
What is deadlock prevention in databases?
Deadlock prevention involves designing the system to avoid conditions that can cause deadlocks, such as by ordering resource requests or using timeouts.
Click to reveal answer
intermediate
How does deadlock resolution typically work in databases?
Deadlock resolution usually involves choosing one transaction as a victim and rolling it back to break the deadlock, allowing other transactions to continue.
Click to reveal answer
beginner
Why is deadlock handling important in database management?
Deadlock handling is important to ensure that transactions do not get stuck forever, which would block other operations and reduce system performance and reliability.
Click to reveal answer
What indicates a deadlock in a wait-for graph?
AA cycle in the graph
BA disconnected node
CA node with no edges
DA linear chain of nodes
✗ Incorrect
A cycle in the wait-for graph means transactions are waiting on each other in a loop, which is a deadlock.
Which of the following is NOT a deadlock handling technique?
ADeadlock detection
BDeadlock prevention
CDeadlock avoidance
DDeadlock ignoring
✗ Incorrect
Ignoring deadlocks is not a handling technique because it causes the system to hang indefinitely.
What action is taken to resolve a deadlock?
ACommit all transactions
BRestart the database server
CRollback one or more transactions
DIncrease lock timeout
✗ Incorrect
Rolling back one or more transactions breaks the deadlock cycle and allows others to proceed.
Deadlock prevention can be achieved by:
AAllowing transactions to wait indefinitely
BRequesting all locks at once in a fixed order
CIgnoring lock requests
DUsing random lock granting
✗ Incorrect
Requesting locks in a fixed order prevents circular wait, a necessary condition for deadlocks.
Why is deadlock detection preferred over prevention in some systems?
APrevention can reduce concurrency
BDetection avoids all deadlocks
CDetection is simpler to implement
DPrevention is slower
✗ Incorrect
Prevention techniques can limit how transactions access resources, reducing system concurrency and performance.
Explain what a deadlock is in a database and why it happens.
Think about transactions waiting for locks held by each other.
You got /3 concepts.
Describe the main strategies used to handle deadlocks in databases.
Consider how systems avoid, find, or fix deadlocks.
You got /4 concepts.
Practice
(1/5)
1. What is a deadlock in a database system?
easy
A. A situation where two or more transactions wait indefinitely for each other to release locks
B. A method to speed up database queries
C. A backup process for database recovery
D. A type of database index
Solution
Step 1: Understand the concept of deadlock
A deadlock occurs when transactions wait for resources locked by each other, causing a cycle of waiting.
Step 2: Identify the correct description
Only a situation where two or more transactions wait indefinitely for each other to release locks describes this waiting cycle causing indefinite blocking.
Final Answer:
A situation where two or more transactions wait indefinitely for each other to release locks -> Option A
Quick Check:
Deadlock = indefinite waiting cycle [OK]
Hint: Deadlock means transactions stuck waiting on each other [OK]
Common Mistakes:
Confusing deadlock with query optimization
Thinking deadlock is a backup process
Mixing deadlock with indexing
2. Which of the following is a common method to handle deadlocks in databases?
easy
A. Ignoring the deadlock and letting transactions wait
B. Deadlock detection and transaction rollback
C. Increasing the database size
D. Using more indexes
Solution
Step 1: Review deadlock handling methods
Deadlock handling usually involves detecting the deadlock and aborting one transaction to break the cycle.
Step 2: Match the correct method
Deadlock detection and transaction rollback correctly states deadlock detection and rollback, which is standard practice.
Final Answer:
Deadlock detection and transaction rollback -> Option B
Quick Check:
Deadlock handling = detect and rollback [OK]
Hint: Deadlocks are handled by detection and rollback [OK]
Common Mistakes:
Thinking deadlocks can be ignored
Believing increasing size fixes deadlocks
Confusing indexing with deadlock handling
3. Consider two transactions T1 and T2. T1 holds a lock on resource A and waits for resource B. T2 holds a lock on resource B and waits for resource A. What will happen if the database uses deadlock detection?
medium
A. Both transactions will complete successfully without waiting
B. The transactions will wait forever causing a system crash
C. The database will automatically grant both resources to both transactions
D. The database will detect the deadlock and abort one transaction
Solution
Step 1: Analyze the resource waiting scenario
T1 and T2 each hold one resource and wait for the other, creating a circular wait (deadlock).
Step 2: Understand deadlock detection response
The database detects this cycle and aborts one transaction to break the deadlock.
Final Answer:
The database will detect the deadlock and abort one transaction -> Option D
Quick Check:
Deadlock detection aborts one transaction [OK]
Hint: Deadlock detection aborts one waiting transaction [OK]
Common Mistakes:
Assuming both transactions finish without waiting
Thinking system crashes always occur
Believing resources are shared automatically
4. A database system uses timeout to handle deadlocks. A transaction waits for a lock for 10 seconds before aborting. What is the problem if the timeout is set too low?
medium
A. Transactions may abort unnecessarily even if no deadlock exists