DOC PREVIEW
UMD CMSC 424 - Concurrency Control

This preview shows page 1-2-22-23 out of 23 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 23 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 23 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 23 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 23 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 23 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Concurrency ControlExample SchedulesExample ScheduleExample Schedule (Cont.)Example Schedules (Cont.)Equivalence by SwappingSlide 7Slide 8Slide 9Slide 10Lock instructionsLocking IssuesSlide 132PhaseLocking2PL IssuesStrict 2PLDealing with DeadlocksExample of Granularity HierarchyCompatibility Matrix with Intention Lock ModesSlide 20ExampleExamplesSlide 23Concurrency ControlConcurrency ControlExample SchedulesExample SchedulesConstraint: The sum of A+B must be the sameBefore: 100+50After: 45+105T1read(A)A = A -50write(A)read(B)B=B+50write(B)T2read(A)tmp = A*0.1A = A – tmpwrite(A)read(B)B = B+ tmpwrite(B)Transactions: T1: transfers $50 from A to B T2: transfers 10% of A to B=150, consistentExample 1: a “serial” scheduleExample ScheduleExample ScheduleAnother “serial” schedule:T1read(A)A = A -50write(A)read(B)B=B+50write(B)T2read(A)tmp = A*0.1A = A – tmpwrite(A)read(B)B = B+ tmpwrite(B)Before: 100+50After: 40+110Consistent but not the same as previous schedule..Either is OK!=150, consistentExample Schedule (Cont.)Example Schedule (Cont.)Another “good” schedule:T1read(A)A = A -50write(A)read(B)B=B+50write(B)T2read(A)tmp = A*0.1A = A – tmpwrite(A)read(B)B = B+ tmpwrite(B)Effect: Before After A 100 45 B 50 105Same as one of the serial schedulesSerializableExample Schedules (Cont.)Example Schedules (Cont.) A “bad” scheduleBefore: 100+50 = 150After: 50+60 = 110 !!Not consistentT1read(A)A = A -50write(A)read(B)B=B+50write(B)T2read(A)tmp = A*0.1A = A – tmpwrite(A)read(B)B = B+ tmpwrite(B)Non SerializableEquivalence by SwappingEquivalence by SwappingT1read(A)A = A -50write(A)read(B)B=B+50write(B)T2read(A)tmp = A*0.1A = A – tmpwrite(A)read(B)B = B+ tmpwrite(B)T1read(A)A = A -50write(A)read(B)B=B+50write(B)T2read(A)tmp = A*0.1A = A – tmpwrite(A)read(B)B = B+ tmpwrite(B)Equivalence by SwappingEquivalence by SwappingT1read(A)A = A -50write(A)read(B)B=B+50write(B)T2read(A)tmp = A*0.1A = A – tmpwrite(A)read(B)B = B+ tmpwrite(B)T1read(A)A = A -50write(A)read(B)B=B+50write(B)T2read(A)tmp = A*0.1A = A – tmpwrite(A)read(B)B = B+ tmpwrite(B)Equivalence by SwappingEquivalence by SwappingT1read(A)A = A -50write(A)read(B)B=B+50write(B)T2read(A)tmp = A*0.1A = A – tmpwrite(A)read(B)B = B+ tmpwrite(B)T1read(A)A = A -50write(A)read(B)B=B+50write(B)T2read(A)tmp = A*0.1A = A – tmpwrite(A)read(B)B = B+ tmpwrite(B)Example Schedules (Cont.)Example Schedules (Cont.) A “bad” scheduleT1read(A)A = A -50write(A)read(B)B=B+50write(B)T2read(A)tmp = A*0.1A = A – tmpwrite(A)read(B)B = B+ tmpwrite(B)XYCan’t move Y below X read(B) and write(B) conflictExample Schedules (Cont.)Example Schedules (Cont.) A “bad” scheduleT1read(A)A = A -50write(A)read(B)B=B+50write(B)T2read(A)tmp = A*0.1A = A – tmpwrite(A)read(B)B = B+ tmpwrite(B)XYCan’t move Y below X read(B) and write(B) conflictOther options don’t work eitherSo: Not Conflict SerializableLock instructionsLock instructionsNew instructions- lock-S: shared lock request- lock-X: exclusive lock request- unlock: release previously held lockExample: lock-X(B)read(B)B B-50write(B)unlock(B)lock-X(A)read(A)A A + 50write(A)unlock(A)lock-S(A)read(A)unlock(A)lock-S(B)read(B)unlock(B)display(A+B)T1T2Locking IssuesLocking IssuesNo xction proceeds:Deadlock- T1 waits for T2 to unlock A- T2 waits for T1 to unlock BT1 T2lock-X(B)read(B)B  B-50write(B) lock-X(A)lock-S(A)read(A)lock-S(B)Rollback transactionsCan be costly...Locking IssuesLocking IssuesDoes not ensure serializability by itself:lock-X(B)read(B)B B-50write(B)unlock(B)lock-X(A)read(A)A A + 50write(A)unlock(A)lock-S(A)read(A)unlock(A)lock-S(B)read(B)unlock(B)display(A+B)T1T2T2 displays 50 less!!2PhaseLocking2PhaseLockingExample: T1 in 2PLT1lock-X(B)read(B)B  B - 50write(B)lock-X(A)read(A)A  A - 50write(A)unlock(B)unlock(A)Growing phaseShrinking phase2PL Issues2PL Issues2PL does not prevent deadlock> 2 xctions involved?- Rollbacks expensiveT1 T2lock-X(B)read(B)B  B-50write(B) lock-X(A)lock-S(A)read(A)lock-S(B)Strict 2PLStrict 2PLT1 T2 T3lock-X(A)read(A)lock-S(B)read(B)write(A)unlock(A)<xction fails>lock-X(A)read(A)write(A)unlock(A)lock-S(A)read(A)Strict 2PLwill not allow thatDealing with DeadlocksDealing with DeadlocksHow do you detect a deadlock?Wait-for graphDirected edge from Ti to TjTi waiting for TjT1 T2 T3 T4S(V)X(V)S(W)X(Z)S(V)X(W)T1T2T4T3Suppose T4 requests lock-S(Z)....Example of Granularity HierarchyExample of Granularity Hierarchy The highest level in the example hierarchy is the entire database. The levels below are of type area, file or relation and record in that order.Compatibility Matrix withCompatibility Matrix with Intention Lock Modes Intention Lock ModesThe compatibility matrix for all lock modes is: ISIXSS IXX ISIXSS IXX        holderrequestorParent Child can belocked in locked inISIXSSIXXPCIS, SIS, S, IX, X, SIX[S, IS] not necessaryX, IX, [SIX]noneExampleExampleR1t1t2 t3t4T1(IS)T1(S), T2(IX)T2(X)ExamplesExamplesRt1t3t4t2f2.1f2.2f4.2f4.2T1(IX)T1(IX)T1(X)Rt1t3t4t2f2.1f2.2f4.2f4.2T1(IS)T1(S)Rt1t3t4t2f2.1f2.2f4.2f4.2T1(SIX)T1(IX)T1(X)Can T2 access object f2.2 in X mode? What locks will T2 get?ExamplesExamplesT1 scans R, and updates a few tuples:T1 gets an SIX lock on R, then repeatedly gets an S lock on tuples of R, and occasionally upgrades to X on the tuples.T2 uses an index to read only part of R:T2 gets an IS lock on R, and repeatedly gets an S lock on tuples of R.T3 reads all of R:T3 gets an S lock on R. OR, T3 could behave like T2; can use lock escalation to decide which.--IS IX--ISIX S XSX 


View Full Document

UMD CMSC 424 - Concurrency Control

Documents in this Course
Lecture 2

Lecture 2

36 pages

Databases

Databases

44 pages

Load more
Download Concurrency Control
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Concurrency Control and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Concurrency Control 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?