what we have covered?
DESCRIPTION
What we have covered?. Indexing and Hashing Data warehouse and OLAP Data Mining Information Retrieval and Web Mining XML and XQuery Spatial Databases Transaction Management. Lecture 7: Transactions. The Setting. - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/1.jpg)
1
What we have covered?
Indexing and Hashing Data warehouse and OLAP Data Mining Information Retrieval and Web Mining XML and XQuery Spatial Databases Transaction Management
![Page 2: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/2.jpg)
2
Lecture 7: Transactions
![Page 3: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/3.jpg)
3
The Setting
Database systems are normally being accessed by many users or processes at the same time. Both queries and modifications.
Unlike operating systems, which support interaction of processes, a DMBS needs to keep processes from troublesome interactions.
![Page 4: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/4.jpg)
4
Example: Bad Interaction
You and your domestic partner each take $100 from different ATM’s at about the same time. The DBMS better make sure one
account deduction doesn’t get lost. Compare: An OS allows two people
to edit a document at the same time. If both write, one’s changes get lost.
![Page 5: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/5.jpg)
5
ACID Transactions
A DBMS is expected to support “ACID transactions,” processes that are: Atomic : Either the whole process is done
or none is. Consistent : Database constraints are
preserved. Isolated : It appears to the user as if only
one process executes at a time. Durable : Effects of a process do not get
lost if the system crashes.
![Page 6: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/6.jpg)
6
Transactions in SQL
SQL supports transactions, often behind the scenes. Each statement issued at the generic
query interface is a transaction by itself.
In programming interfaces like Embedded SQL or PSM, a transaction begins the first time a SQL statement is executed and ends with the program or an explicit transaction-end.
![Page 7: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/7.jpg)
7
COMMIT
The SQL statement COMMIT causes a transaction to complete. It’s database modifications are now
permanent in the database.
![Page 8: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/8.jpg)
8
ROLLBACK
The SQL statement ROLLBACK also causes the transaction to end, but by aborting. No effects on the database.
Failures like division by 0 or a constraint violation can also cause rollback, even if the programmer does not request it.
![Page 9: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/9.jpg)
9
An Example: Interacting Processes
Assume the usual Sells(bar,beer,price) relation, and suppose that Joe’s Bar sells only Bud for $2.50 and Miller for $3.00.
Sally is querying Sells for the highest and lowest price Joe charges.
Joe decides to stop selling Bud and Miller, but to sell only Heineken at $3.50.
![Page 10: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/10.jpg)
10
Sally’s Program
Sally executes the following two SQL statements, which we call (min) and (max), to help remember what they do.
(max)SELECT MAX(price) FROM SellsWHERE bar = ’Joe’’s Bar’;
(min) SELECT MIN(price) FROM SellsWHERE bar = ’Joe’’s Bar’;
![Page 11: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/11.jpg)
11
Joe’s Program
At about the same time, Joe executes the following steps, which have the mnemonic names (del) and (ins).
(del) DELETE FROM Sells WHERE bar = ’Joe’’s Bar’;
(ins) INSERT INTO Sells VALUES(’Joe’’s Bar’, ’Heineken’,
3.50);
![Page 12: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/12.jpg)
12
Interleaving of Statements
Although (max) must come before (min), and (del) must come before (ins), there are no other constraints on the order of these statements, unless we group Sally’s and/or Joe’s statements into transactions.
![Page 13: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/13.jpg)
13
Example: Strange Interleaving
Suppose the steps execute in the order (max)(del)(ins)(min).
Joe’s Prices:Statement:Result:
Sally sees MAX < MIN!
2.50, 3.00
(del) (ins)
3.50
(min)
3.50
2.50, 3.00
(max)
3.00
![Page 14: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/14.jpg)
14
Fixing the Problem by Using Transactions
If we group Sally’s statements (max)(min) into one transaction, then she cannot see this inconsistency.
She sees Joe’s prices at some fixed time. Either before or after he changes
prices, or in the middle, but the MAX and MIN are computed from the same prices.
![Page 15: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/15.jpg)
15
Another Problem: Rollback
Suppose Joe executes (del)(ins), not as a transaction, but after executing these statements, thinks better of it and issues a ROLLBACK statement.
If Sally executes her statements after (ins) but before the rollback, she sees a value, 3.50, that never existed in the database.
![Page 16: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/16.jpg)
16
Solution
If Joe executes (del)(ins) as a transaction, its effect cannot be seen by others until the transaction executes COMMIT. If the transaction executes ROLLBACK
instead, then its effects can never be seen.
![Page 17: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/17.jpg)
17
Isolation Levels
SQL defines four isolation levels = choices about what interactions are allowed by transactions that execute at about the same time.
How a DBMS implements these isolation levels is highly complex, and a typical DBMS provides its own options.
![Page 18: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/18.jpg)
18
Choosing the Isolation Level
Within a transaction, we can say:SET TRANSACTION ISOLATION LEVEL
Xwhere X =
1. SERIALIZABLE2. REPEATABLE READ3. READ COMMITTED4. READ UNCOMMITTED
![Page 19: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/19.jpg)
19
Serializable Transactions
If Sally = (max)(min) and Joe = (del)(ins) are each transactions, and Sally runs with isolation level SERIALIZABLE, then she will see the database either before or after Joe runs, but not in the middle.
It’s up to the DBMS vendor to figure out how to do that, e.g.: True isolation in time. Keep Joe’s old prices around to answer
Sally’s queries.
![Page 20: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/20.jpg)
20
Isolation Level Is Personal Choice
Your choice, e.g., run serializable, affects only how you see the database, not how others see it.
Example: If Joe Runs serializable, but Sally doesn’t, then Sally might see no prices for Joe’s Bar. i.e., it looks to Sally as if she ran in
the middle of Joe’s transaction.
![Page 21: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/21.jpg)
21
Read-Commited Transactions
If Sally runs with isolation level READ COMMITTED, then she can see only committed data, but not necessarily the same data each time.
Example: Under READ COMMITTED, the interleaving (max)(del)(ins)(min) is allowed, as long as Joe commits. Sally sees MAX < MIN.
![Page 22: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/22.jpg)
22
Repeatable-Read Transactions
Requirement is like read-committed, plus: if data is read again, then everything seen the first time will be seen the second time. But the second and subsequent reads
may see more tuples as well.
![Page 23: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/23.jpg)
23
Example: Repeatable Read
Suppose Sally runs under REPEATABLE READ, and the order of execution is (max)(del)(ins)(min). (max) sees prices 2.50 and 3.00. (min) can see 3.50, but must also see
2.50 and 3.00, because they were seen on the earlier read by (max).
![Page 24: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/24.jpg)
24
Read Uncommitted
A transaction running under READ UNCOMMITTED can see data in the database, even if it was written by a transaction that has not committed (and may never).
Example: If Sally runs under READ UNCOMMITTED, she could see a price 3.50 even if Joe later aborts.
![Page 25: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/25.jpg)
25
Concurrency Control
T1 T2 … Tn
DB(consistencyconstraints)
![Page 26: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/26.jpg)
26
Review
Why do we need transaction? What’s ACID? What’s SQL support for transaction? What’s the four isolation level
SERIALIZABLE REPEATABLE READ READ COMMITTED READ UNCOMMITTED
![Page 27: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/27.jpg)
27
Example:
T1: Read(A) T2: Read(A)A A+100 A A2Write(A) Write(A)Read(B) Read(B)B B+100 B B2Write(B) Write(B)
Constraint: A=B
![Page 28: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/28.jpg)
28
Schedule A
T1 T2Read(A); A A+100Write(A);Read(B); B B+100;Write(B);
Read(A);A A2;
Write(A);
Read(B);B B2;
Write(B);
A B25 25
125
125
250
250250 250
![Page 29: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/29.jpg)
29
Schedule B
T1 T2
Read(A);A A2;
Write(A);
Read(B);B B2;
Write(B);Read(A); A A+100Write(A);Read(B); B B+100;Write(B);
A B25 25
50
50
150
150150 150
![Page 30: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/30.jpg)
30
Schedule C
T1 T2Read(A); A A+100Write(A);
Read(A);A A2;
Write(A);Read(B); B B+100;Write(B);
Read(B);B B2;
Write(B);
A B25 25
125
250
125
250250 250
![Page 31: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/31.jpg)
31
Schedule D
T1 T2Read(A); A A+100Write(A);
Read(A);A A2;
Write(A);
Read(B);B B2;
Write(B);Read(B); B B+100;Write(B);
A B25 25
125
250
50
150250 150
![Page 32: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/32.jpg)
32
Schedule E
T1 T2’Read(A); A A+100Write(A);
Read(A);A A1;
Write(A);
Read(B);B B1;
Write(B);Read(B); B B+100;Write(B);
A B25 25
125
125
25
125125 125
Same as Schedule Dbut with new T2’
![Page 33: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/33.jpg)
33
Want schedules that are “good”,regardless of
initial state and transaction semantics
Only look at order of read and writes
Example: Sc=r1(A)w1(A)r2(A)w2(A)r1(B)w1(B)r2(B)w
2(B)
![Page 34: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/34.jpg)
34
Sc’=r1(A)w1(A) r1(B)w1(B)r2(A)w2(A)r2(B)w2(B)
T1 T2
Example: Sc=r1(A)w1(A)r2(A)w2(A)r1(B)w1(B)r2(B)w2(B)
![Page 35: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/35.jpg)
35
Review
Why do we need transaction? What’s ACID? What’s SQL support for transaction? What’s the four isolation level
SERIALIZABLE REPEATABLE READ READ COMMITTED READ UNCOMMITTED
![Page 36: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/36.jpg)
36
Example:
T1: Read(A) T2: Read(A)A A+100 A A2Write(A) Write(A)Read(B) Read(B)B B+100 B B2Write(B) Write(B)
Constraint: A=B
![Page 37: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/37.jpg)
37
Schedule D
T1 T2Read(A); A A+100Write(A);
Read(A);A A2;
Write(A);
Read(B);B B2;
Write(B);Read(B); B B+100;Write(B);
A B25 25
125
250
50
150250 150
![Page 38: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/38.jpg)
38
However, for Sd:Sd=r1(A)w1(A)r2(A)w2(A)
r2(B)w2(B)r1(B)w1(B)
as a matter of fact, T2 must precede T1
in any equivalent schedule, i.e., T2 T1
![Page 39: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/39.jpg)
39
T1 T2 Sd cannot be rearrangedinto a serial
scheduleSd is not “equivalent” to
any serial scheduleSd is “bad”
T2 T1
Also, T1 T2
![Page 40: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/40.jpg)
40
Schedule C
T1 T2Read(A); A A+100Write(A);
Read(A);A A2;
Write(A);Read(B); B B+100;Write(B);
Read(B);B B2;
Write(B);
A B25 25
125
250
125
250250 250
![Page 41: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/41.jpg)
41
Returning to Sc
Sc=r1(A)w1(A)r2(A)w2(A)r1(B)w1(B)r2(B)w2(B)
T1 T2 T1 T2
no cycles Sc is “equivalent” to aserial schedule(in this case T1,T2)
![Page 42: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/42.jpg)
42
Concepts
Transaction: sequence of ri(x), wi(x) actionsConflicting actions: r1(A) w2(A) w1(A)
w2(A) r1(A) w2(A)
Schedule: represents chronological orderin which actions are executed
Serial schedule: no interleaving of actions or transactions
![Page 43: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/43.jpg)
43
Definition
S1, S2 are conflict equivalent schedulesif S1 can be transformed into S2 by a series of swaps on non-conflicting actions.
![Page 44: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/44.jpg)
44
Definition
A schedule is conflict serializable if it is conflict equivalent to some serial schedule.
![Page 45: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/45.jpg)
45
Nodes: transactions in SArcs: Ti Tj whenever
- pi(A), qj(A) are actions in S- pi(A) <S qj(A)
- at least one of pi, qj is a write
Precedence graph P(S) (S is
schedule)
![Page 46: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/46.jpg)
46
Exercise:
What is P(S) forS = w3(A) w2(C) r1(A) w1(B) r1(C) w2(A) r4(A) w4(D)
Is S serializable?
![Page 47: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/47.jpg)
47
Another Exercise:
What is P(S) forS = w1(A) r2(A) r3(A) w4(A) ?
![Page 48: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/48.jpg)
48
Lemma
S1, S2 conflict equivalent P(S1)=P(S2)
Proof:Assume P(S1) P(S2) Ti: Ti Tj in S1 and not in S2
S1 = …pi(A)... qj(A)… pi, qj
S2 = …qj(A)…pi(A)... conflict
S1, S2 not conflict equivalent
![Page 49: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/49.jpg)
49
Note: P(S1)=P(S2) S1, S2 conflict equivalent
Counter example:
S1=w1(A) r2(A) w2(B) r1(B) S2=r2(A) w1(A) r1(B) w2(B)
![Page 50: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/50.jpg)
50
Theorem
P(S1) acyclic S1 conflict serializable
() Assume S1 is conflict serializable Ss: Ss, S1 conflict equivalent P(Ss) = P(S1)
P(S1) acyclic since P(Ss) is acyclic
![Page 51: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/51.jpg)
51
() Assume P(S1) is acyclicTransform S1 as follows:(1) Take T1 to be transaction with no incident arcs(2) Move all T1 actions to the front
S1 = ……. qj(A)…….p1(A)…..
(3) we now have S1 = < T1 actions ><... rest ...>(4) repeat above steps to serialize rest!
T1
T2 T3
T4
TheoremP(S1) acyclic S1 conflict serializable
![Page 52: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/52.jpg)
52
How to enforce serializable schedules?
Option 1: run system, recording P(S); at end of day, check
for P(S) cycles and declare if execution was good
![Page 53: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/53.jpg)
53
Option 2: prevent P(S) cycles from occurring T1 T2 ….. Tn
Scheduler
DB
How to enforce serializable schedules?
![Page 54: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/54.jpg)
54
A locking protocol
Two new actions:lock (exclusive): li (A)
unlock: ui (A)
scheduler
T1 T2
locktable
![Page 55: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/55.jpg)
55
Rule #1: Well-formed transactions
Ti: … li(A) … pi(A) … ui(A) ...
![Page 56: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/56.jpg)
56
Rule #2 Legal scheduler
S = …….. li(A) ………... ui(A) ……...
no lj(A)
![Page 57: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/57.jpg)
57
What schedules are legal?What transactions are well-formed?S1 = l1(A)l1(B)r1(A)w1(B)l2(B)u1(A)u1(B)r2(B)w2(B)u2(B)l3(B)r3(B)u3(B)
S2 = l1(A)r1(A)w1(B)u1(A)u1(B)l2(B)r2(B)w2(B)l3(B)r3(B)u3(B)
S3 = l1(A)r1(A)u1(A)l1(B)w1(B)u1(B)l2(B)r2(B)w2(B)u2(B)l3(B)r3(B)u3(B)
Exercise:
![Page 58: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/58.jpg)
58
What schedules are legal?What transactions are well-formed?S1 = l1(A)l1(B)r1(A)w1(B)l2(B)u1(A)u1(B)r2(B)w2(B)u2(B)l3(B)r3(B)u3(B)
S2 = l1(A)r1(A)w1(B)u1(A)u1(B)l2(B)r2(B)w2(B)l3(B)r3(B)u3(B)
S3 = l1(A)r1(A)u1(A)l1(B)w1(B)u1(B)l2(B)r2(B)w2(B)u2(B)l3(B)r3(B)u3(B)
Exercise:
![Page 59: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/59.jpg)
59
Schedule F
T1 T2l1(A);Read(A)A A+100;Write(A);u1(A)
l2(A);Read(A)A Ax2;Write(A);u2(A)l2(B);Read(B)B Bx2;Write(B);u2(B)
l1(B);Read(B)B B+100;Write(B);u1(B)
![Page 60: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/60.jpg)
60
Schedule F
T1 T2 25 25l1(A);Read(A)A A+100;Write(A);u1(A) 125
l2(A);Read(A)A Ax2;Write(A);u2(A) 250l2(B);Read(B)B Bx2;Write(B);u2(B) 50
l1(B);Read(B)B B+100;Write(B);u1(B) 150
250 150
A B
![Page 61: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/61.jpg)
61
Rule #3 Two phase locking (2PL)
for transactions
Ti = ……. li(A) ………... ui(A) ……...
no unlocks no locks
![Page 62: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/62.jpg)
62
# locksheld byTi
Time Growing Shrinking Phase Phase
![Page 63: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/63.jpg)
63
Schedule G
T1 T2l1(A);Read(A)A A+100;Write(A)l1(B); u1(A)
l2(A);Read(A) A Ax2;Write(A);ll22(B)(B)
delayed
![Page 64: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/64.jpg)
64
Schedule G
T1 T2l1(A);Read(A)A A+100;Write(A)l1(B); u1(A)
l2(A);Read(A) A Ax2;Write(A);ll22(B)(B)
Read(B);B B+100Write(B); u1(B)
delayed
![Page 65: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/65.jpg)
65
Schedule G
T1 T2l1(A);Read(A)A A+100;Write(A)l1(B); u1(A)
l2(A);Read(A) A Ax2;Write(A);ll22(B)(B)
Read(B);B B+100Write(B); u1(B)
l2(B); u2(A);Read(B) B Bx2;Write(B);u2(B);
delayed
![Page 66: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/66.jpg)
66
Schedule H (T2 reversed)
T1 T2l1(A); Read(A) l2(B);Read(B)A A+100;Write(A) B Bx2;Write(B)
ll11(B)(B) l l22(A)(A)delayeddelayed
![Page 67: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/67.jpg)
67
Assume deadlocked transactions are rolled back They have no effect They do not appear in schedule
E.g., Schedule H =This space intentionally
left blank!
![Page 68: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/68.jpg)
68
Next step:
Show that rules #1,2,3 conflict- serializable schedules
![Page 69: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/69.jpg)
69
Conflict rules for li(A), ui(A):
li(A), lj(A) conflict li(A), uj(A) conflict
Note: no conflict < ui(A), uj(A)>, < li(A), rj(A)>,...
![Page 70: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/70.jpg)
70
Theorem Rules #1,2,3 conflict (2PL) serializable
schedule
To help in proof:Definition Shrink(Ti) = SH(Ti) =
first unlock action of Ti
![Page 71: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/71.jpg)
71
LemmaTi Tj in S SH(Ti) <S SH(Tj)
Proof of lemma:Ti Tj means that
S = … pi(A) … qj(A) …; p,q conflictBy rules 1,2:
S = … pi(A) … ui(A) … lj(A) ... qj(A) …
By rule 3: SH(Ti) SH(Tj)
So, SH(Ti) <S SH(Tj)
![Page 72: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/72.jpg)
72
Proof:(1) Assume P(S) has cycle
T1 T2 …. Tn T1
(2) By lemma: SH(T1) < SH(T2) < ... <
SH(T1)
(3) Impossible, so P(S) acyclic(4) S is conflict serializable
Theorem Rules #1,2,3 conflict (2PL) serializable
schedule
![Page 73: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/73.jpg)
73
Beyond this simple 2PL protocol, it is all a matter of improving performance and allowing more concurrency…. Shared locks Multiple granularity Inserts, deletes and phantoms Other types of C.C. mechanisms
![Page 74: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/74.jpg)
74
Shared locks
So far:S = ...l1(A) r1(A) u1(A) … l2(A) r2(A) u2(A) …
Do not conflict
Instead:S=... ls1(A) r1(A) ls2(A) r2(A) …. us1(A)
us2(A)
![Page 75: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/75.jpg)
75
Lock actionsl-ti(A): lock A in t mode (t is S or X)u-ti(A): unlock t mode (t is S or X)
Shorthand:ui(A): unlock whatever modes
Ti has locked A
![Page 76: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/76.jpg)
76
Rule #1 Well formed transactionsTi =... l-S1(A) … r1(A) … u1 (A) …Ti =... l-X1(A) … w1(A) … u1 (A) …
![Page 77: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/77.jpg)
77
What about transactions that read and write same object?
Option 1: Request exclusive lockTi = ...l-X1(A) … r1(A) ... w1(A) ... u(A)
…
![Page 78: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/78.jpg)
78
Option 2: Upgrade (E.g., need to read, but don’t know if will write…)
Ti=... l-S1(A) … r1(A) ... l-X1(A) …w1(A) ...u(A)…
Think of- Get 2nd lock on A, or- Drop S, get X lock
• What about transactions that read and write same object?
![Page 79: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/79.jpg)
79
Rule #2 Legal scheduler
S = ....l-Si(A) … … ui(A) …
no l-Xj(A)
S = ... l-Xi(A) … … ui(A) …
no l-Xj(A) no l-Sj(A)
![Page 80: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/80.jpg)
80
A way to summarize Rule #2
Compatibility matrix
Comp S XS true falseX false false
![Page 81: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/81.jpg)
81
Rule # 3 2PL transactions
No change except for upgrades:(I) If upgrade gets more locks
(e.g., S {S, X}) then no change!
(II) If upgrade releases read (shared)lock (e.g., S X)- can be allowed in growing
phase
![Page 82: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/82.jpg)
82
Proof: similar to X locks case
Detail:l-ti(A), l-rj(A) do not conflict if comp(t,r)l-ti(A), u-rj(A) do not conflict if comp(t,r)
Theorem Rules 1,2,3 Conf.serializablefor S/X locks schedules
![Page 83: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/83.jpg)
83
Lock types beyond S/X
Examples:(1) increment lock(2) update lock
![Page 84: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/84.jpg)
84
Example (1): increment lock
Atomic increment action: INi(A){Read(A); A A+k;
Write(A)} INi(A), INj(A) do not conflict!
A=7A=5 A=17
A=15
INi(A)
+2
INj(A)
+10
+10
INj(A)
+2
INi(A)
![Page 85: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/85.jpg)
85
Comp S X ISXI
![Page 86: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/86.jpg)
86
Comp S X IS T F FX F F FI F F T
![Page 87: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/87.jpg)
87
Update locks
A common deadlock problem with upgrades:
T1 T2l-S1(A)
l-S2(A)
l-Xl-X11(A)(A)
l-Xl-X22(A)(A)
--- Deadlock ---
![Page 88: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/88.jpg)
88
Solution
If Ti wants to read A and knows itmay later want to write A, it requestsupdate lock (not shared)
![Page 89: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/89.jpg)
89
Comp S X USXU
New request
Lock alreadyheld in
![Page 90: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/90.jpg)
90
Comp S X US T F TX F F FU TorF F F
-> symmetric table?
New request
Lock alreadyheld in
![Page 91: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/91.jpg)
91
Note: object A may be locked in different modes at the same time...
S1=...l-S1(A)…l-S2(A)…l-U3(A)… l-S4(A)…?
l-U4(A)…?
To grant a lock in mode t, mode t must be compatible with all currently held locks on object
![Page 92: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/92.jpg)
92
How does locking work in practice?
Every system is different(E.g., may not even provide CONFLICT-SERIALIZABLE schedules)
But here is one (simplified) way ...
![Page 93: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/93.jpg)
93
(1) Don’t trust transactions torequest/release
locks(2) Hold all locks until transaction
commits#
locks
time
Sample Locking System:
![Page 94: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/94.jpg)
94
Ti
Read(A),Write(B)
l(A),Read(A),l(B),Write(B)…
Read(A),Write(B)
Scheduler, part I
Scheduler, part II
DB
locktable
![Page 95: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/95.jpg)
95
Lock table Conceptually
A
BC
...
Lock info for B
Lock info for C
If null, object is unlocked
Every
poss
ible
obje
ct
![Page 96: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/96.jpg)
96
But use hash table:
A
If object not found in hash table, it is unlocked
Lock info for AA
......
H
![Page 97: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/97.jpg)
97
Lock info for A - example
tran mode wait? Nxt T_link
Object:AGroup mode:UWaiting:yesList:
T1 S no
T2 U no
T3 XX yes
To other T3
records
![Page 98: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/98.jpg)
98
What are the objects we lock?
?
Relation A
Relation B
...
Tuple A
Tuple BTuple C
...
Disk block
A
Disk block
B
...
DB DB DB
![Page 99: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/99.jpg)
99
Locking works in any case, but should we choose small or large objects?
If we lock large objects (e.g., Relations) Need few locks Low concurrency
If we lock small objects (e.g., tuples,fields) Need more locks More concurrency
![Page 100: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/100.jpg)
100
We can have it both ways!!
Ask any janitor to give you the solution...
hall
Stall 1 Stall 2 Stall 3 Stall 4
restroom
![Page 101: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/101.jpg)
101
Example
R1
t1t2 t3
t4
T1(IS)
T1(S)
, T2(S)
![Page 102: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/102.jpg)
102
Example
R1
t1t2 t3
t4
T1(IS)
T1(S)
, T2(IX)
T2(IX)
![Page 103: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/103.jpg)
103
Multiple granularity
Comp Requestor
IS IX S SIX X IS
Holder IX S
SIX
X
![Page 104: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/104.jpg)
104
Multiple granularity
Comp Requestor
IS IX S SIX X IS
Holder IX S
SIX
X
T T T T F
F
F
F
FFFFF
FFFT
FTFT
FFTT
![Page 105: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/105.jpg)
105
Parent Child can belocked in locked in
ISIXSSIXX
P
C
![Page 106: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/106.jpg)
106
Parent Child can belocked in locked in
ISIXSSIXX
P
C
IS, SIS, S, IX, X, SIX[S, IS] not necessaryX, IX, [SIX]none
![Page 107: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/107.jpg)
107
Rules
(1) Follow multiple granularity comp function(2) Lock root of tree first, any mode(3) Node Q can be locked by Ti in S or IS only
if parent(Q) locked by Ti in IX or IS(4) Node Q can be locked by Ti in X,SIX,IX only if parent(Q) locked by Ti in IX,SIX(5) Ti is two-phase(6) Ti can unlock node Q only if none of Q’s children are locked by Ti
![Page 108: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/108.jpg)
108
Exercise: Can T2 access object f2.2 in X
mode? What locks will T2 get?
R1
t1
t2 t3t4T1(IX)
f2.1 f2.2 f3.1 f3.2
T1(IX)
T1(X)
![Page 109: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/109.jpg)
109
Exercise: Can T2 access object f2.2 in X
mode? What locks will T2 get?
R1
t1
t2 t3t4T1(X)
f2.1 f2.2 f3.1 f3.2
T1(IX)
![Page 110: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/110.jpg)
110
Exercise: Can T2 access object f3.1 in X
mode? What locks will T2 get?
R1
t1
t2 t3t4T1(S)
f2.1 f2.2 f3.1 f3.2
T1(IS)
![Page 111: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/111.jpg)
111
Exercise: Can T2 access object f2.2 in S
mode? What locks will T2 get?
R1
t1
t2 t3t4T1(IX)
f2.1 f2.2 f3.1 f3.2
T1(SIX)
T1(X)
![Page 112: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/112.jpg)
112
Exercise: Can T2 access object f2.2 in X
mode? What locks will T2 get?
R1
t1
t2 t3t4T1(IX)
f2.1 f2.2 f3.1 f3.2
T1(SIX)
T1(X)
![Page 113: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/113.jpg)
113
Insert + delete operations
Insert
A
Z
...
![Page 114: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/114.jpg)
114
Modifications to locking rules:
(1) Get exclusive lock on A before deleting A
(2) At insert A operation by Ti, Ti is given exclusive lock on A
![Page 115: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/115.jpg)
115
Still have a problem: PhantomsPhantomsExample: relation R (E#,name,…)
constraint: E# is keyuse tuple locking
R E# Name ….o1 55 Smitho2 75 Jones
![Page 116: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/116.jpg)
116
T1: Insert <04,Kerry,…> into RT2: Insert <04,Bush,…> into R
T1 T2
S1(o1) S2(o1)S1(o2) S2(o2)Check Constraint Check Constraint
Insert o3[04,Kerry,..] Insert
o4[04,Bush,..]
... ...
![Page 117: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/117.jpg)
117
Solution
Use multiple granularity tree Before insert of node Q, lock parent(Q) in X mode R1
t1t2 t3
![Page 118: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/118.jpg)
118
Back to exampleT1: Insert<04,Kerry> T2: Insert<04,Bush>
T1 T2
X1(R)
Check constraintInsert<04,Kerry>U(R)
X2(R)Check constraintOops! e# = 04 already in
R!
XX22(R(R))
delayed
![Page 119: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/119.jpg)
119
Instead of using R, can use index on R:
Example: R
Index0<E#<100
Index100<E#<200
E#=2 E#=5 E#=107 E#=109...
...
...
![Page 120: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/120.jpg)
120
This approach can be generalized to multiple indexes...
![Page 121: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/121.jpg)
121
Next:
Tree-based concurrency control Validation concurrency control
![Page 122: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/122.jpg)
122
Example
A
B C
D
E F
• all objects accessed through root, following pointers
T1 lock
T1 lockT1 lock
can we release A lock if we no longer need A??
![Page 123: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/123.jpg)
123
Idea: traverse like “Monkey Bars”
A
B C
D
E F
T1 lock
T1 lockT1 lock
T1 lock
![Page 124: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/124.jpg)
124
Why does this work?
Assume all Ti start at root; exclusive lock Ti Tj Ti locks root before Tj
Actually works if we don’t always start at root
Root
Q Ti Tj
![Page 125: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/125.jpg)
125
Rules: tree protocol (exclusive locks)
(1) First lock by Ti may be on any item(2) After that, item Q can be locked by
Ti only if parent(Q) locked by Ti
(3) Items may be unlocked at any time(4) After Ti unlocks Q, it cannot relock Q
![Page 126: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/126.jpg)
126
Tree-like protocols are used typically for B-tree concurrency control
E.g., during insert, do not release parent lock, until you are certain child does not have to split
Root
![Page 127: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/127.jpg)
127
Validation
Transactions have 3 phases:(1) Read
all DB values read writes to temporary storage no locking
(2) Validate check if schedule so far is serializable
(3) Write if validate ok, write to DB
![Page 128: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/128.jpg)
128
Key idea
Make validation atomic If T1, T2, T3, … is validation order,
then resulting schedule will be conflict equivalent to Ss = T1 T2
T3...
![Page 129: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/129.jpg)
129
To implement validation, system keeps two sets:
FIN = transactions that have finished phase 3 (and are all done)
VAL = transactions that have successfully finished
phase 2 (validation)
![Page 130: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/130.jpg)
130
Example of what validation must prevent:
RS(T2)={B} RS(T3)={A,B}
WS(T2)={B,D} WS(T3)={C}
time
T2
start
T2
validated
T3
validatedT3
start
=
![Page 131: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/131.jpg)
131
T2
finishphase 3
Example of what validation must prevent:
RS(T2)={B} RS(T3)={A,B}
WS(T2)={B,D} WS(T3)={C}
time
T2
start
T2
validated
T3
validatedT3
start
=
allow
T3
start
![Page 132: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/132.jpg)
132
Another thing validation must prevent:
RS(T2)={A} RS(T3)={A,B}WS(T2)={D,E} WS(T3)={C,D}
time
T2
validatedT3
validated
finish
T2BAD: w3(D) w2(D)
![Page 133: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/133.jpg)
133
finish
T2
Another thing validation must prevent:
RS(T2)={A} RS(T3)={A,B}WS(T2)={D,E} WS(T3)={C,D}
time
T2
validatedT3
validated
allow
finish
T2
![Page 134: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/134.jpg)
134
Validation rules for Tj:
(1) When Tj starts phase 1: ignore(Tj) FIN
(2) at Tj Validation:if check (Tj) then
[ VAL VAL U {Tj}; do write phase; FIN FIN U {Tj} ]
![Page 135: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/135.jpg)
135
Check (Tj):
For Ti VAL - IGNORE (Tj) DO
IF [ WS(Ti) RS(Tj)
OR Ti FIN ] THEN RETURN false;
RETURN true;
Is this check too restrictive ?
![Page 136: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/136.jpg)
136
Improving Check(Tj)
For Ti VAL - IGNORE (Tj) DO IF [ WS(Ti) RS(Tj) OR
(Ti FIN AND WS(Ti) WS(Tj) )]
THEN RETURN false;RETURN true;
![Page 137: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/137.jpg)
137
Exercise:
T: RS(T)={A,B} WS(T)={A,C}
V: RS(V)={B} WS(V)={D,E}
U: RS(U)={B} WS(U)={D}
W: RS(W)={A,D} WS(W)={A,C}
startvalidatefinish
![Page 138: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/138.jpg)
138
Validation (also called optimistic concurrency control) is useful in some cases:
- Conflicts rare- System resources plentiful- Have real time constraints
![Page 139: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/139.jpg)
139
Summary
Have studied C.C. mechanisms used in practice- 2 PL- Multiple granularity- Tree (index) protocols- Validation
![Page 140: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/140.jpg)
140
What about concurrent actions?
Ti issues System Input(X) t xread(x,t) issues completes
input(x)time
T2 issueswrite(B,S)
Systemissues
input(B)
input(B)completes
B S
Systemissues
output(B)output(B)completes
![Page 141: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/141.jpg)
141
So net effect is either S=…r1(x)…w2(b)… or S=…w2(B)…r1(x)…
![Page 142: What we have covered?](https://reader034.vdocument.in/reader034/viewer/2022051116/56814e5e550346895dbbfc28/html5/thumbnails/142.jpg)
142
Assume equivalent to either r1(A) w2(A)or w2(A) r1(A)
low level synchronization mechanism Assumption called “atomic actions”
What about conflicting, concurrent actions on same object?
start r1(A) end r1(A)
start w2(A) end w2(A) time