Bird
Raised Fist0
DBMS Theoryknowledge~20 mins

Lock-based protocols in DBMS Theory - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
πŸŽ–οΈ
Lock-based Protocols Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding Two-Phase Locking (2PL)

Which statement best describes the Two-Phase Locking (2PL) protocol in database systems?

AIt requires transactions to acquire all locks before releasing any, ensuring serializability.
BIt allows transactions to release locks before acquiring new ones, improving concurrency.
CIt permits transactions to acquire and release locks in any order without restrictions.
DIt uses timestamps instead of locks to control transaction execution order.
Attempts:
2 left
πŸ’‘ Hint

Think about how 2PL controls when locks can be acquired and released to avoid conflicts.

πŸ“‹ Factual
intermediate
2:00remaining
Lock Compatibility Matrix

In lock-based protocols, which of the following lock pairs are compatible, allowing concurrent access?

AExclusive lock and Exclusive lock
BExclusive lock and Shared lock
CShared lock and Shared lock
DShared lock and Exclusive lock
Attempts:
2 left
πŸ’‘ Hint

Consider which locks allow reading and which prevent others from accessing.

πŸ” Analysis
advanced
2:00remaining
Deadlock Detection Scenario

Consider two transactions T1 and T2. T1 holds a lock on resource A and requests a lock on resource B. T2 holds a lock on resource B and requests a lock on resource A. What is the outcome?

AT1 proceeds first, then T2, no deadlock occurs.
BDeadlock occurs because both transactions wait indefinitely for each other’s locks.
CBoth transactions abort immediately to avoid deadlock.
DLocks are granted simultaneously, so no waiting occurs.
Attempts:
2 left
πŸ’‘ Hint

Think about what happens when two transactions wait for each other’s locked resources.

❓ Comparison
advanced
2:00remaining
Strict 2PL vs Rigorous 2PL

Which of the following correctly distinguishes Strict Two-Phase Locking (Strict 2PL) from Rigorous Two-Phase Locking (Rigorous 2PL)?

AStrict 2PL allows shared locks to be released early; Rigorous 2PL releases exclusive locks early.
BStrict 2PL uses timestamps; Rigorous 2PL uses lock queues.
CStrict 2PL releases locks as soon as possible; Rigorous 2PL holds locks until the transaction aborts.
DStrict 2PL releases all exclusive locks only at commit time; Rigorous 2PL releases all locks (shared and exclusive) only at commit time.
Attempts:
2 left
πŸ’‘ Hint

Focus on when locks are released in each protocol.

❓ Reasoning
expert
2:00remaining
Impact of Lock Granularity on Concurrency

How does using finer lock granularity (e.g., row-level locks) compared to coarser granularity (e.g., table-level locks) affect concurrency and overhead in a database system?

AFiner granularity increases concurrency but also increases locking overhead and complexity.
BFiner granularity decreases concurrency and reduces overhead.
CCoarser granularity increases concurrency and reduces overhead.
DLock granularity has no effect on concurrency or overhead.
Attempts:
2 left
πŸ’‘ Hint

Think about how locking smaller parts affects how many transactions can run simultaneously and the cost of managing locks.

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

  1. Step 1: Understand the role of lock-based protocols

    Lock-based protocols manage how multiple users access data simultaneously to avoid conflicts.
  2. Step 2: Identify the main goal

    The main goal is to control concurrent access and maintain data consistency.
  3. Final Answer:

    To control concurrent access to data and prevent conflicts -> Option A
  4. 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

  1. Step 1: Understand shared lock syntax

    Shared locks allow multiple readers and are usually requested with a 'shared' parameter.
  2. Step 2: Identify correct syntax format

    Among options, lock(X, shared) correctly requests a shared lock on X.
  3. Final Answer:

    lock(X, shared) -> Option B
  4. 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?
medium
A. Both T1 and T2 will hold locks simultaneously
B. T2 will immediately get the exclusive lock
C. T1 will be aborted due to conflict
D. T2 will wait until T1 releases the shared lock

Solution

  1. Step 1: Analyze lock compatibility

    Shared locks allow multiple readers, but exclusive locks require exclusive access.
  2. Step 2: Understand lock waiting rules

    T2's exclusive lock request conflicts with T1's shared lock, so T2 must wait until T1 releases the lock.
  3. Final Answer:

    T2 will wait until T1 releases the shared lock -> Option D
  4. Quick Check:

    Exclusive lock waits for shared lock release [OK]
Hint: Exclusive lock waits if shared lock exists [OK]
Common Mistakes:
  • Assuming exclusive lock is granted immediately
  • Thinking both locks can coexist
  • Believing transaction abort happens automatically
4. A transaction T tries to acquire an exclusive lock on data item B but the system throws a deadlock error. What is the most likely cause?
medium
A. T is waiting for another transaction holding a conflicting lock on B
B. T requested a shared lock instead of exclusive lock
C. T has already released all its locks
D. The data item B does not exist in the database

Solution

  1. Step 1: Understand deadlock in locking

    Deadlock occurs when two or more transactions wait indefinitely for locks held by each other.
  2. Step 2: Identify cause of deadlock error

    T's exclusive lock request is blocked because another transaction holds a conflicting lock, causing deadlock.
  3. Final Answer:

    T is waiting for another transaction holding a conflicting lock on B -> Option A
  4. Quick Check:

    Deadlock = waiting on conflicting locks [OK]
Hint: Deadlock means waiting on each other's locks [OK]
Common Mistakes:
  • Confusing deadlock with syntax errors
  • Assuming deadlock means missing data
  • Thinking deadlock occurs if locks are released
5. In a system using strict two-phase locking (2PL), which of the following is true about when locks are released?
hard
A. Locks are released randomly during the transaction
B. Locks are released immediately after each data item is accessed
C. All locks are released only after the transaction commits or aborts
D. Shared locks are released before exclusive locks

Solution

  1. Step 1: Understand strict two-phase locking

    Strict 2PL requires holding all locks until the transaction finishes (commit or abort) to ensure serializability.
  2. Step 2: Identify lock release timing

    Locks are not released during the transaction but only after it ends, preventing conflicts.
  3. Final Answer:

    All locks are released only after the transaction commits or aborts -> Option C
  4. Quick Check:

    Strict 2PL releases locks after commit/abort [OK]
Hint: Strict 2PL holds locks until transaction ends [OK]
Common Mistakes:
  • Releasing locks too early during transaction
  • Confusing strict 2PL with basic locking
  • Assuming random lock release
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard