What is a lock-based protocol in database management?
A lock-based protocol is a method used to control access to data in a database by locking data items. It ensures that transactions do not interfere with each other, maintaining data consistency and preventing conflicts.
Click to reveal answer
beginner
What are the two main types of locks used in lock-based protocols?
The two main types of locks are: 1. Shared Lock (S-lock): Allows multiple transactions to read a data item. 2. Exclusive Lock (X-lock): Allows a transaction to write or modify a data item exclusively.
Click to reveal answer
intermediate
Explain the purpose of the Two-Phase Locking (2PL) protocol.
Two-Phase Locking (2PL) ensures serializability by dividing a transaction's locking actions into two phases: 1. Growing phase: Locks are acquired and no locks are released. 2. Shrinking phase: Locks are released and no new locks are acquired. This prevents conflicts and ensures correct transaction order.
Click to reveal answer
intermediate
What problem can occur if locks are not managed properly in lock-based protocols?
Deadlock can occur when two or more transactions wait indefinitely for locks held by each other, causing the system to freeze or stall.
Click to reveal answer
beginner
How does a shared lock differ from an exclusive lock in terms of transaction access?
A shared lock allows multiple transactions to read the same data simultaneously but prevents writing. An exclusive lock allows only one transaction to write or modify the data and prevents others from reading or writing until the lock is released.
Click to reveal answer
What does an exclusive lock allow a transaction to do?
AWrite or modify data exclusively
BRead data only
CRead data with other transactions
DRelease locks early
✗ Incorrect
An exclusive lock allows a transaction to write or modify data exclusively, preventing other transactions from accessing it simultaneously.
Which phase in Two-Phase Locking is when locks are acquired?
AShrinking phase
BWaiting phase
CGrowing phase
DReleasing phase
✗ Incorrect
In the growing phase, a transaction acquires all the locks it needs and does not release any.
What problem arises when two transactions wait for each other's locks indefinitely?
ADeadlock
BRollback
CStarvation
DCommit failure
✗ Incorrect
Deadlock occurs when transactions wait forever for locks held by each other, causing a standstill.
Which lock type allows multiple transactions to read the same data simultaneously?
ANone of the above
BExclusive lock
CWrite lock
DShared lock
✗ Incorrect
Shared locks allow multiple transactions to read the same data at the same time.
Why are lock-based protocols important in databases?
ATo speed up data entry
BTo prevent data conflicts and ensure consistency
CTo delete old data
DTo backup data automatically
✗ Incorrect
Lock-based protocols prevent conflicts between transactions and keep data consistent.
Describe how Two-Phase Locking (2PL) works and why it is important.
Think about the order of locking and unlocking in a transaction.
You got /5 concepts.
Explain the difference between shared and exclusive locks with examples.
Consider who can access the data and how.
You got /4 concepts.
Practice
(1/5)
1. What is the main purpose of lock-based protocols in a database management system?
easy
A. To control concurrent access to data and prevent conflicts
B. To speed up database queries by caching results
C. To backup data automatically at regular intervals
D. To encrypt data for security purposes
Solution
Step 1: Understand the role of lock-based protocols
Lock-based protocols manage how multiple users access data simultaneously to avoid conflicts.
Step 2: Identify the main goal
The main goal is to control concurrent access and maintain data consistency.
Final Answer:
To control concurrent access to data and prevent conflicts -> Option A
Quick Check:
Lock-based protocols = control access [OK]
Hint: Locks manage who reads/writes data safely [OK]
Common Mistakes:
Confusing locking with data backup
Thinking locks speed up queries
Mixing locking with encryption
2. Which of the following is the correct syntax to request a shared lock on a data item X in a lock-based protocol?
easy
A. lock_shared(X)
B. lock(X, shared)
C. lock_exclusive(X)
D. lock(X, exclusive)
Solution
Step 1: Understand shared lock syntax
Shared locks allow multiple readers and are usually requested with a 'shared' parameter.
Step 2: Identify correct syntax format
Among options, lock(X, shared) correctly requests a shared lock on X.
Final Answer:
lock(X, shared) -> Option B
Quick Check:
Shared lock syntax = lock(X, shared) [OK]
Hint: Shared lock uses 'shared' keyword in lock call [OK]
Common Mistakes:
Using exclusive lock syntax for shared lock
Confusing function names
Omitting lock type parameter
3. Consider two transactions T1 and T2 accessing data item A. T1 requests a shared lock on A, then T2 requests an exclusive lock on A. What will happen next?