Lecture 17-1 Lecture 17-1 Computer Science 425 Distributed Systems CS 425 / CSE 424 / ECE 428 Fall 2010 Indranil Gupta (Indy) October 19, 2010 Lecture 17 Concurrency Control Reading: Chapter 13 (relevant parts) 2010, I. Gupta, K. Nahrtstedt, S. Mitra, N. Vaidya, M. T. Harandi, J. Hou
25
Embed
Computer Science 425 Distributed Systems CS 425 / CSE 424 / ECE 428 Fall 2010
Computer Science 425 Distributed Systems CS 425 / CSE 424 / ECE 428 Fall 2010. Indranil Gupta (Indy) October 19, 2010 Lecture 17 Concurrency Control Reading: Chapter 13 (relevant parts). 2010, I . Gupta, K. Nahrtstedt, S. Mitra, N. Vaidya, M. T. Harandi, J. Hou. Example Transaction. - PowerPoint PPT Presentation
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
2010, I. Gupta, K. Nahrtstedt, S. Mitra, N. Vaidya, M. T. Harandi, J. Hou
Lecture 17-2Lecture 17-2
Banking transaction for a customer (ATM)Transfer $100 from saving to checking account;
Transfer $200 from money-market to checking account;
Withdraw $400 from checking account.
Transaction:1. savings.deduct(100) /* includes verification */
2. checking.add(100) /* depends on success of 1 */
3. mnymkt.deduct(200) /* includes verification */
4. checking.add(200) /* depends on success of 3 */
5. checking.deduct(400) /* includes verification */
6. dispense(400)
7. commit
Example TransactionExample Transaction
Lecture 17-3Lecture 17-3
Properties of Transactions (ACID) Properties of Transactions (ACID)
Atomicity: All or nothing
Consistency: starting in a consistent state, the transaction ends in a consistent state.
Isolation: Each transaction must be performed without interference from other transactions, i.e., the intermediate effects of a transaction must not be visible to other transactions.
Durability: After a transaction has completed successfully, all its effects are saved in permanent storage.
It is desirable to have concurrent transactions because it increases throughput at server
But this can be done only to the extent that ACID properties are not violated
Example from Last LectureExample from Last Lecture
100 200 300a: b: c:
278c:
a:
242b:
b: 220
80
== T1 (complete) followedby T2 (complete)
Lecture 17-5Lecture 17-5
The effect of an operation refers toThe value of an object set by a write operation
The result returned by a read operation.
Two operations are said to be in conflict, if their combined effect depends on the order they are executed, e.g., read-write, write-read, write-write (all on same variables). NOT read-read, not on different variables.
Two transactions are serially equivalent if and only if all pairs of conflicting operations (pair containing one operation from each transaction) are executed in the same order (transaction order) for all objects (data) they both access.Why? Can start from original operation sequence and swap the order of
non-conflicting operations to obtain a series of operations where one transaction finishes completely before the second transaction starts
Why is the above result important? Because: Serial equivalence is the basis for concurrency control protocols for transactions.
Conflicting Operations Conflicting Operations
Lecture 17-6Lecture 17-6
Read and Write Operation Conflict RulesRead and Write Operation Conflict Rules
Operations of differenttransactions
Conflict Reason
read read No Because the effect of a pair of read operations
does not depend on the order in which they are
executed
read write Yes Because the effect of a read and a write operation
depends on the order of their execution
write write Yes Because the effect of a pair of write operations
depends on the order of their execution
Lecture 17-7Lecture 17-7
An interleaving of the operations of 2 or more transactions is said to be serially equivalent if the combined effect is the same as if these transactions had been performed sequentially (in some order).
Deadlocks Deadlocks Necessary conditions for deadlocks
Non-shareable resources (locked objects)
No preemption on locks
Hold & Wait or Circular Wait
T U
Wait forHeld by
Held byWait for
A
BT
U
Wait forHeld by
Held byWait for
A
BV
W
...
...
Wait for
Wait forHeld by
Held by
Hold & Wait Circular Wait
Lecture 17-19Lecture 17-19
Naïve Deadlock Resolution Using TimeoutNaïve Deadlock Resolution Using Timeout
Transaction T Transaction U
Operations Locks Operations Locks
a.deposit(100); write lock A
b.deposit(200) write lock B
b.withdraw(100)
waits for U’s a.withdraw(200); waits for T’s
lock on B lock on A (timeout elapses)
T’s lock on A becomes vulnerable, unlock A, abort T
a.withdraw(200); write locks Aunlock A, B
Disadvantages?
Lecture 17-20Lecture 17-20
Strategies to Fight DeadlockStrategies to Fight Deadlock
Deadlocks can be resolved by lock timeout (costly and open to false positives)
Deadlock Prevention: violate one of the necessary conditions for deadlock (from previous slide), e.g., lock all objects at transaction start only; release all if any locking operation fails
Deadlock Avoidance: Have transactions declare max resources they will request, but allow them to lock at any time (Banker’s algorithm)
Deadlock Detection: deadlocks can be detected, e.g., by using a wait-for graph, & then resolved by aborting one of the transactions in the cycle.
Lecture 17-21Lecture 17-21
ConclusionConclusion
• Increasing concurrency important because it improves throughput at server
• Applications are willing to tolerate temporary inconsistency and deadlocks in turn
• These inconsistencies and deadlocks need to be prevented or detected
• Driven and validated by actual application characteristics – mostly-read applications do not have too many conflicting operations anyway
• Reading for next lecture: Section 13.{1, 2, 4} , Section 14.{1, 2, 3, 5}
Lock Hierarchy for the Banking ExampleLock Hierarchy for the Banking Example
Branch
AccountA B C
•Deposit and withdrawal operations require locking at the granularity of an account.•branchTotal operation acquires a read lock on all of the accounts.
Lecture 17-24Lecture 17-24
Lock Hierarchy for a DiaryLock Hierarchy for a Diary
At each level, the setting of a parent lock has the sameeffect as setting all the equivalent child locks.
Lecture 17-25Lecture 17-25
If objects are in a “part-of” hierarchy, a lock at a higher node implicitly applies to children objects.
Before a child node (in the object hierarchy) gets a read/write lock, an intention lock (I-read/I-write) is set for all ancestor nodes. The intention lock is compatible with other intention locks but conflicts with read/write locks according to the usual rules.
Lock set Lock requestedread write I-read I-write
none OK OK OK OKread OK WAIT OK WAITwrite WAIT WAIT WAIT WAITI-read OK WAIT OK OKI-write WAIT WAIT OK OK