Docsity

Database Concurrency Control: Locking and Multi-versioning Solutions, Exercises of Transaction Processing for E Commerce

Toggle sidebar
bg1
Assignment 6 - Solution
Problem 1
Suppose a transaction sets an intention-write lock on a file and
later sets a write lock on a record of the file.
Is it safe for the transaction to release the intention-write lock
before it commits? Why?
No it’s not safe. Suppose record x is contained in file F. Consider
the following execution:
iwl1[F] wl1[x] w1[x] iwu1[F] rl2[F] r2[x] w1[x] wu1[x] c1 ru2[F] c2
Transaction T1 writes x twice, once before r2[x] and once
afterwards, so the result isn’t serializable.
docsity.com
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Database Concurrency Control: Locking and Multi-versioning Solutions and more Exercises Transaction Processing for E Commerce in PDF only on Docsity!

Assignment 6 - Solution

Problem 1 Suppose a transaction sets an intention-write lock on a file and later sets a write lock on a record of the file. Is it safe for the transaction to release the intention-write lock before it commits? Why?

No it’s not safe. Suppose record x is contained in file F. Consider the following execution:

iwl 1 [F] wl 1 [x] w 1 [x] iwu 1 [F] rl 2 [F] r 2 [x] w 1 [x] wu 1 [x] c 1 ru 2 [F] c 2

Transaction T 1 writes x twice, once before r 2 [x] and once afterwards, so the result isn’t serializable.

Problem 2 The multi-granularity locking protocol requires that if a transaction has a w or iw lock on a data item x , then it must have an iw lock on x ’s parent.

2.A. Is it correct for a transaction to hold an r lock on x ’s parent instead? Either explain why it’s correct or give an example where it fails.

  • No, it is incorrect.
  • This would allow:
    • T 1 to read lock file F
      • (giving it permission to read every record in F),
    • T 2 to read lock F and write lock a record in F, such as x.
  • Thus T 1 would implicitly have a read lock on x that conflicts with T 2 ’s write lock on x.

2.C. Assuming the lock graph is a tree, suggest a case where it would be useful to set such a w lock as in (2.B) (whether or not it’s correct).

In cases where the data manager would escalate fine-grained w locks to coarse-grained locks, then using the coarse-grained w as parent will perform slightly better by avoiding the escalation cost and the cost of needlessly setting the fine-grained locks before escalating.

Problem 3

Consider the following database table, which supports a multiversion concurrency control.

Suppose the commit list contains {1,2,3,4,6} and there are no active transactions.

TID Prev TID Account# Balance 1 Null 10 100 3 1 10 200 1 Null 11 300 4 1 11 400 5 4 11 350 6 Null 12 500

3.B. Suppose a read-only query with TID=7 reads all the accounts. It starts executing before executing transaction 8 starts executing and finishes after transaction 8 commits (same transaction 8 as part (a)). Which versions of which rows does it read?

3.B.

  • When it started executing, transaction 7 read the following commit list: {1,2,3,4,6}.
  • It read the following:
    • version TID 3 of Account 10,
    • version TID 4 of Account 11 (because 5 didn’t commit)
    • version TID 6 of account 12.
  • It does not see any of transaction 8’s updates because transaction 8 was not on the commit list when it started.

TID Prev TID Account# Balance 1 Null 10 100 3 1 10 200 8 3 10 300 1 Null 11 300 4 1 11 400 5 4 11 350 6 Null 12 500 8 6 12 deleted 8 Null 13 700

Problem 4 Suppose file F contains a sequence of fixed-length records, and F ’s descriptor includes a count of the number of records in F , which is used to find the end of F. Consider the following two transactions:

  • T 1 :
    • Scan F , returning all the records in F
    • Read( x )
  • T 2 :
    • Insert a record into F
    • Write( x )

Data item x is not in F. Both transactions are two-phase locked (locking records in F and x ), but neither transaction locks count.

4.A. Given an example of a non-serializable execution of T 1 and T 2. Explain why it’s non- serializable.

  1. T 1 : Scan F , returning all the records in F
  2. T 2 : Insert a record into F
  3. T 2 : Write( x )
  4. Commit 2
  5. T 1 : Read( x )
  • The first two operations imply and T 1 precedes T 2 , but since they don’t lock count, the first operation doesn’t cause the second one to be delayed.
  • The third and fifth operations on x conflict, which imply that T 2 precedes T 1.
  • So the execution isn’t SR.