SlideShare a Scribd company logo
1 of 12
Download to read offline
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.
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:
• T1 to read lock file F
• (giving it permission to read every record in F),
• T2 to read lock F and write lock a record in F, such as x.
• Thus T1 would implicitly have a read lock on x that conflicts
with T2’s write lock on x.
2.B. Redo question (2.A), replacing “r lock” by “w lock”.
Is it correct for a transaction to hold an w lock on x’s parent
instead?
• Yes, it is correct.
• Assuming the given protocol is correct using iw locks, then w
locks must work too
• w lock is strictly stronger than an iw lock.
• By “stronger,” we mean that any lock type that conflicts with an
iw lock also conflicts with a w lock.
• You might think it’s incorrect because it needlessly prevents
certain operations from running.
• This is a performance problem, but not incorrect, in the sense
of breaking a conflict or an ACID property.
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.A. What is the state of the table after running the following
transaction?:
TID=8: Increment the balance of account 10 by 100;
Delete account 12;
Insert account 13 with balance 700.
The database state after transaction 8 commits
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
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
3.C. After transactions 7 and 8 have finished and no other
transactions are active, suppose we garbage collect all of the
versions that aren’t needed. Assuming transaction ids
increase monotonically with respect time, what does the table
look like after the garbage collection step?
The garbage collector keeps the last committed update of each
account:
TID Prev TID Account# Balance
8 Null 10 300
4 Null 11 400
8 Null 13 700
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:
• T1:
• Scan F, returning all the records in F
• Read(x)
• T2:
• 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 T1
and T2. Explain why it’s non- serializable.
1. T1: Scan F, returning all the records in F
2. T2: Insert a record into F
3. T2: Write(x)
4. Commit2
5. T1: Read(x)
• The first two operations imply and T1 precedes T2, 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
T2 precedes T1.
• So the execution isn’t SR.
4.B. Explain why this is an example of the phantom problem.
• T1:
• Scan F, returning all the records in F
• Read(x)
• T2:
• Insert a record into F
• Write(x)
T2’s insertion into F is a phantom record. T1’s scan doesn’t see
the record, but T1’s Read(x) indirectly sees the result in data
item x (assuming the value of x is a function of the records in F).

More Related Content

What's hot

Process Synchronization
Process SynchronizationProcess Synchronization
Process SynchronizationSonali Chauhan
 
Synchronize access to shared mutable data
Synchronize access to shared mutable dataSynchronize access to shared mutable data
Synchronize access to shared mutable dataKohei Nozaki
 
Chapter 6 - Process Synchronization
Chapter 6 - Process SynchronizationChapter 6 - Process Synchronization
Chapter 6 - Process SynchronizationWayne Jones Jnr
 
protocols of concurrency control
protocols of concurrency controlprotocols of concurrency control
protocols of concurrency controlMOHIT DADU
 
Distributed Computing On Topics of: Leader election + Byzantine algorithms)
Distributed Computing On Topics of: Leader election + Byzantine algorithms)Distributed Computing On Topics of: Leader election + Byzantine algorithms)
Distributed Computing On Topics of: Leader election + Byzantine algorithms)Osama Askoura
 
Process synchronization
Process synchronizationProcess synchronization
Process synchronizationSaad11233
 
Distributed Computing Set 3 - Topics of non-Byzantine Consensus
Distributed Computing Set 3 - Topics of non-Byzantine ConsensusDistributed Computing Set 3 - Topics of non-Byzantine Consensus
Distributed Computing Set 3 - Topics of non-Byzantine ConsensusOsama Askoura
 

What's hot (11)

Process Synchronization
Process SynchronizationProcess Synchronization
Process Synchronization
 
Synchronize access to shared mutable data
Synchronize access to shared mutable dataSynchronize access to shared mutable data
Synchronize access to shared mutable data
 
C# Loops
C# LoopsC# Loops
C# Loops
 
Chapter 6 - Process Synchronization
Chapter 6 - Process SynchronizationChapter 6 - Process Synchronization
Chapter 6 - Process Synchronization
 
Basic constructs ii
Basic constructs  iiBasic constructs  ii
Basic constructs ii
 
protocols of concurrency control
protocols of concurrency controlprotocols of concurrency control
protocols of concurrency control
 
Python - Lecture 10
Python - Lecture 10Python - Lecture 10
Python - Lecture 10
 
Semaphores
SemaphoresSemaphores
Semaphores
 
Distributed Computing On Topics of: Leader election + Byzantine algorithms)
Distributed Computing On Topics of: Leader election + Byzantine algorithms)Distributed Computing On Topics of: Leader election + Byzantine algorithms)
Distributed Computing On Topics of: Leader election + Byzantine algorithms)
 
Process synchronization
Process synchronizationProcess synchronization
Process synchronization
 
Distributed Computing Set 3 - Topics of non-Byzantine Consensus
Distributed Computing Set 3 - Topics of non-Byzantine ConsensusDistributed Computing Set 3 - Topics of non-Byzantine Consensus
Distributed Computing Set 3 - Topics of non-Byzantine Consensus
 

Viewers also liked

Data profiling
Data profilingData profiling
Data profilingsdamodar8
 
Gaceta1148
Gaceta1148Gaceta1148
Gaceta1148aoja55
 
Hóa vô cơ tập 2 - Hoàng Nhâm
Hóa vô cơ tập 2 - Hoàng NhâmHóa vô cơ tập 2 - Hoàng Nhâm
Hóa vô cơ tập 2 - Hoàng NhâmCat Anh Nguyen Ngoc
 
Resumen unit 5 where i live social science
Resumen unit 5 where i live social science Resumen unit 5 where i live social science
Resumen unit 5 where i live social science Blanca Francisco Tardón
 
Part of the pipeline-why continuous testing is essential - velocity conf
Part of the pipeline-why continuous testing is essential - velocity confPart of the pipeline-why continuous testing is essential - velocity conf
Part of the pipeline-why continuous testing is essential - velocity confTapabrata Pal
 
Csc and tesda equivalency program
Csc and tesda equivalency programCsc and tesda equivalency program
Csc and tesda equivalency programCHRISLEE PHIL
 

Viewers also liked (11)

Info ensayo deber
Info ensayo deberInfo ensayo deber
Info ensayo deber
 
Data profiling
Data profilingData profiling
Data profiling
 
Info ensayo deber
Info ensayo deberInfo ensayo deber
Info ensayo deber
 
Conociendo la Cencia Medica
Conociendo la Cencia MedicaConociendo la Cencia Medica
Conociendo la Cencia Medica
 
Smartphone
SmartphoneSmartphone
Smartphone
 
Lign105 guide
Lign105 guideLign105 guide
Lign105 guide
 
Gaceta1148
Gaceta1148Gaceta1148
Gaceta1148
 
Hóa vô cơ tập 2 - Hoàng Nhâm
Hóa vô cơ tập 2 - Hoàng NhâmHóa vô cơ tập 2 - Hoàng Nhâm
Hóa vô cơ tập 2 - Hoàng Nhâm
 
Resumen unit 5 where i live social science
Resumen unit 5 where i live social science Resumen unit 5 where i live social science
Resumen unit 5 where i live social science
 
Part of the pipeline-why continuous testing is essential - velocity conf
Part of the pipeline-why continuous testing is essential - velocity confPart of the pipeline-why continuous testing is essential - velocity conf
Part of the pipeline-why continuous testing is essential - velocity conf
 
Csc and tesda equivalency program
Csc and tesda equivalency programCsc and tesda equivalency program
Csc and tesda equivalency program
 

Similar to Solution6.2012

Characteristics Schedule based on Recover-ability & Serial-ability
Characteristics Schedule based on Recover-ability & Serial-abilityCharacteristics Schedule based on Recover-ability & Serial-ability
Characteristics Schedule based on Recover-ability & Serial-abilityMeghaj Mallick
 
Multi version Concurrency Control and its applications in Advanced database s...
Multi version Concurrency Control and its applications in Advanced database s...Multi version Concurrency Control and its applications in Advanced database s...
Multi version Concurrency Control and its applications in Advanced database s...GauthamSK4
 
Recovery & Atom city & Log based Recovery
Recovery & Atom city & Log based RecoveryRecovery & Atom city & Log based Recovery
Recovery & Atom city & Log based RecoveryMeghaj Mallick
 
Concepts of Data Base Management Systems
Concepts of Data Base Management SystemsConcepts of Data Base Management Systems
Concepts of Data Base Management SystemsDinesh Devireddy
 
3 concurrency controlone_v3
3 concurrency controlone_v33 concurrency controlone_v3
3 concurrency controlone_v3ashish61_scs
 
17. Recovery System in DBMS
17. Recovery System in DBMS17. Recovery System in DBMS
17. Recovery System in DBMSkoolkampus
 
16. Concurrency Control in DBMS
16. Concurrency Control in DBMS16. Concurrency Control in DBMS
16. Concurrency Control in DBMSkoolkampus
 
Chapter Three _Concurrency Control Techniques_ETU.ppt
Chapter Three _Concurrency Control Techniques_ETU.pptChapter Three _Concurrency Control Techniques_ETU.ppt
Chapter Three _Concurrency Control Techniques_ETU.ppthaymanot taddesse
 
Concurrency Control, Recovery, Case Studies
Concurrency Control, Recovery, Case StudiesConcurrency Control, Recovery, Case Studies
Concurrency Control, Recovery, Case StudiesPrabu U
 
db unit 4 dbms protocols in transaction
db unit 4 dbms  protocols in transactiondb unit 4 dbms  protocols in transaction
db unit 4 dbms protocols in transactionKumari Naveen
 
recoverability and serializability dbms
recoverability and serializability  dbmsrecoverability and serializability  dbms
recoverability and serializability dbmsKumari Naveen
 

Similar to Solution6.2012 (20)

Assignment.6.2012
Assignment.6.2012Assignment.6.2012
Assignment.6.2012
 
Unit 06 dbms
Unit 06 dbmsUnit 06 dbms
Unit 06 dbms
 
Unit 07 dbms
Unit 07 dbmsUnit 07 dbms
Unit 07 dbms
 
Characteristics Schedule based on Recover-ability & Serial-ability
Characteristics Schedule based on Recover-ability & Serial-abilityCharacteristics Schedule based on Recover-ability & Serial-ability
Characteristics Schedule based on Recover-ability & Serial-ability
 
concurrency-control
concurrency-controlconcurrency-control
concurrency-control
 
Multi version Concurrency Control and its applications in Advanced database s...
Multi version Concurrency Control and its applications in Advanced database s...Multi version Concurrency Control and its applications in Advanced database s...
Multi version Concurrency Control and its applications in Advanced database s...
 
Transaction.pptx
Transaction.pptxTransaction.pptx
Transaction.pptx
 
Recovery & Atom city & Log based Recovery
Recovery & Atom city & Log based RecoveryRecovery & Atom city & Log based Recovery
Recovery & Atom city & Log based Recovery
 
Concepts of Data Base Management Systems
Concepts of Data Base Management SystemsConcepts of Data Base Management Systems
Concepts of Data Base Management Systems
 
Unit06 dbms
Unit06 dbmsUnit06 dbms
Unit06 dbms
 
3 concurrency controlone_v3
3 concurrency controlone_v33 concurrency controlone_v3
3 concurrency controlone_v3
 
unit06-dbms-new.ppt
unit06-dbms-new.pptunit06-dbms-new.ppt
unit06-dbms-new.ppt
 
Unit07 dbms
Unit07 dbmsUnit07 dbms
Unit07 dbms
 
17. Recovery System in DBMS
17. Recovery System in DBMS17. Recovery System in DBMS
17. Recovery System in DBMS
 
16. Concurrency Control in DBMS
16. Concurrency Control in DBMS16. Concurrency Control in DBMS
16. Concurrency Control in DBMS
 
Recovery system
Recovery systemRecovery system
Recovery system
 
Chapter Three _Concurrency Control Techniques_ETU.ppt
Chapter Three _Concurrency Control Techniques_ETU.pptChapter Three _Concurrency Control Techniques_ETU.ppt
Chapter Three _Concurrency Control Techniques_ETU.ppt
 
Concurrency Control, Recovery, Case Studies
Concurrency Control, Recovery, Case StudiesConcurrency Control, Recovery, Case Studies
Concurrency Control, Recovery, Case Studies
 
db unit 4 dbms protocols in transaction
db unit 4 dbms  protocols in transactiondb unit 4 dbms  protocols in transaction
db unit 4 dbms protocols in transaction
 
recoverability and serializability dbms
recoverability and serializability  dbmsrecoverability and serializability  dbms
recoverability and serializability dbms
 

More from ashish61_scs

More from ashish61_scs (20)

7 concurrency controltwo
7 concurrency controltwo7 concurrency controltwo
7 concurrency controltwo
 
Transactions
TransactionsTransactions
Transactions
 
22 levine
22 levine22 levine
22 levine
 
21 domino mohan-1
21 domino mohan-121 domino mohan-1
21 domino mohan-1
 
20 access paths
20 access paths20 access paths
20 access paths
 
19 structured files
19 structured files19 structured files
19 structured files
 
18 philbe replication stanford99
18 philbe replication stanford9918 philbe replication stanford99
18 philbe replication stanford99
 
17 wics99 harkey
17 wics99 harkey17 wics99 harkey
17 wics99 harkey
 
16 greg hope_com_wics
16 greg hope_com_wics16 greg hope_com_wics
16 greg hope_com_wics
 
15 bufferand records
15 bufferand records15 bufferand records
15 bufferand records
 
14 turing wics
14 turing wics14 turing wics
14 turing wics
 
14 scaleabilty wics
14 scaleabilty wics14 scaleabilty wics
14 scaleabilty wics
 
13 tm adv
13 tm adv13 tm adv
13 tm adv
 
11 tm
11 tm11 tm
11 tm
 
10b rm
10b rm10b rm
10b rm
 
10a log
10a log10a log
10a log
 
09 workflow
09 workflow09 workflow
09 workflow
 
08 message and_queues_dieter_gawlick
08 message and_queues_dieter_gawlick08 message and_queues_dieter_gawlick
08 message and_queues_dieter_gawlick
 
06 07 lock
06 07 lock06 07 lock
06 07 lock
 
05 tp mon_orbs
05 tp mon_orbs05 tp mon_orbs
05 tp mon_orbs
 

Solution6.2012

  • 1. 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.
  • 2. 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: • T1 to read lock file F • (giving it permission to read every record in F), • T2 to read lock F and write lock a record in F, such as x. • Thus T1 would implicitly have a read lock on x that conflicts with T2’s write lock on x.
  • 3. 2.B. Redo question (2.A), replacing “r lock” by “w lock”. Is it correct for a transaction to hold an w lock on x’s parent instead? • Yes, it is correct. • Assuming the given protocol is correct using iw locks, then w locks must work too • w lock is strictly stronger than an iw lock. • By “stronger,” we mean that any lock type that conflicts with an iw lock also conflicts with a w lock. • You might think it’s incorrect because it needlessly prevents certain operations from running. • This is a performance problem, but not incorrect, in the sense of breaking a conflict or an ACID property.
  • 4. 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.
  • 5. 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
  • 6. 3.A. What is the state of the table after running the following transaction?: TID=8: Increment the balance of account 10 by 100; Delete account 12; Insert account 13 with balance 700. The database state after transaction 8 commits 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 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
  • 7. 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?
  • 8. 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
  • 9. 3.C. After transactions 7 and 8 have finished and no other transactions are active, suppose we garbage collect all of the versions that aren’t needed. Assuming transaction ids increase monotonically with respect time, what does the table look like after the garbage collection step? The garbage collector keeps the last committed update of each account: TID Prev TID Account# Balance 8 Null 10 300 4 Null 11 400 8 Null 13 700 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
  • 10. 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: • T1: • Scan F, returning all the records in F • Read(x) • T2: • 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.
  • 11. 4.A. Given an example of a non-serializable execution of T1 and T2. Explain why it’s non- serializable. 1. T1: Scan F, returning all the records in F 2. T2: Insert a record into F 3. T2: Write(x) 4. Commit2 5. T1: Read(x) • The first two operations imply and T1 precedes T2, 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 T2 precedes T1. • So the execution isn’t SR.
  • 12. 4.B. Explain why this is an example of the phantom problem. • T1: • Scan F, returning all the records in F • Read(x) • T2: • Insert a record into F • Write(x) T2’s insertion into F is a phantom record. T1’s scan doesn’t see the record, but T1’s Read(x) indirectly sees the result in data item x (assuming the value of x is a function of the records in F).