Title: Transaction Management
1????? ?????????3
- Transaction Management
- Part 3
2???? ???????? ??? ??????
3???? ???????? ??? ??????
- ??????? ??????? ??? ?????, ??? ?? ???? ???????
??? ????? ??? ???? ????? ????? ?? ??????? - ??? ?????
- ???? ???????? ????????
-
- ???? ???????? ??????? ?? ????? ??????? ??? ???
???????
optimistic concurrency control
Timestamp-Based Concurrency Control
4?????? ??????
- ??????? ???? ?? ????? ?????
- ??????? ??????? ???????, ?????? ?????, ????
?????? ?????? ????? ????? - ??????? ???????? ????? ????? ?????? ?? ??????? ??
?????? ?????? ????? ????? - ??????? ??????? ??? ?????? ???????
5?? ???? ???? ????? ?? ??????, ???? ???? ????
- ?? ???? ?????
- ?? ?????? ????? ??????, ????? ????? ???????
- ?? ???? ???? ????? ?? ??????, ??????? ??? ??????
????? ????? ?????? ????? ?? ???????, ???? ????
???? ???? ??????? ????? ???? ????
6???? ???????? ??? ?????? ????? ???? ???????? ??
??????
- ????? ?? ???? ???????? ??????? ?? ?????? ?????
?????? ?? - ????? ????????, ???? ????? ????? ?? ????? ????
?????? - ????? ?? ???? ???????? ??? ?????? ????? ?????? ??
- ??????? ????? ???? (???? ????? ?? ????? ????
?????, ????? ????? ????? ???????) - ????? ????? (????? ?????????)
7?? ??? ???? ?????? ???? ????? ???????? ????????
- ?????? ?????? (?????, ?????) ?????? ???????
???????, ????? ?????? ?? ??? ?????? ????? - ???? ??? ??????, ?????? ???? ??????? ???? ?? ????
????? ????? ?? ?????? - ????? ?????? ?????? ???? ???? ???????? ????????
(????? ??????? ???? ??????? ???????)
8???? ???????? ????????
- Optimistic Concurrency Control
9???? ???????? ????????Optimistic Concurrency
Control
- ????? ????????? ????? ?? ?????? ?? ???? ????? ??
????? ?????, ???? ???? ??? ?? ????? ??? ?????
???? ???? ?? ?????
10?????? ???????? ?? ????? ???? ????? ?????????
- ??? ??????
- ??? ???? ????? ??? ????? ???? ??????? ?????? ??
?????, ?????? ????? ????? ?? ??????? ????? - ????? ????? ?? ?? ???????? ???????? ???? ??????
????? - ??? ??????
- ??? ??????
- ?? ?????? ???? ??????, ????? ?????? ?? ???????
??????? ???? ?????? ????? ????
11??? ?????
- ???? ??? ???? ????? ?? ??? ?????? ???????? (?????
??????) ??? ??? ????? - ??? ????? ???, ?????? ?????? ?? ????? ??? (???
?????) ???? ?? ?????? ???? - ??? ???? ????? ?? ??? ?????? ???? ????
- ?????, ??????? ?????? ?? ?????? ?? ????? ??????
????? ?????? ??????? - ????, ?? ???? ??? ??? ????? ????? ???? ???????
??? ??? ???? - ???? ????? ????? ????, ?? ???? ???? ???? ?????
????? ?????
12?? ???? ??????????
- ?????? ????? ??? ??? ????? ???? ???? ????? ??
????? - ?? ?????? ????? ??? ???, ?? ?? ???????? ??? ?????
??? ???? ?????? ?? ??????? ??????? ???? ??????
????? ???? - ?????, ??? ???? ????? ?????? ?????? ??????? ?????
13????? ???
- ?? ???? ????? ????? ??? ?????? ??? ??????
- TS(Ti) ???? ?? ????? ???? ?? ????? Ti
- ?????? ?????? ?????? ????? ?? ??? ???????
??????? ?? ??????? ???? ?????? ?????? ??? ???????
??????? ??? ???? ?? ?????? ???? - ?????, ???? ?????? ?? ?????? "?????" ?????? ?????
?????? ???? ?? ????? ??????
14?? ?? ???? ??????
- ???? Tk ????? ?????? ???? ?? ???? Ti ????????
?????, ????? ???? ?? ???? Ti ??????? - TS(Tk) gt TS(Ti) ???
- Ti ???? ?????? ?? ??????
- ????? ?- Ti ???? ?? ?????? ?????? ???? ?- Tk ????
?? ?????? - ???? ?? ???? ?- Tk ??? Ti ?????? ???? (?????? ???
???? ??????? ????? ?????), ???? ????? ??????? ??
Tk ?????? ???? ?????? ?? Ti
15??? ??????
- ?? Tk ?????? ???? ?- Ti ???????, ?? ???? ???
??????? ?? Tk ??????? ???? ??????? ?? Ti - ??? ????, ???? ??? ?????? ?????? ?? Tk ???????
???? ?????? ?????? ??????? ?? Ti, ?? ???????
?????? ?? ???? ?????? ??????? ????? ??????
(?????? ?- TS(Tk) gt TS(Ti))
16?? ?? ???? ??????
- ?? Tk ?????? ???? ?- Ti ???????, ?? ??? ???? A
????? ?? ??? Ti ????? ?? ??? Tk, ???? ????? ?- Tk
????? ?? ???? ?? A ???? ?- Ti ????? ?? ?????
?????? ?? A - ???? ????? Ti ?? ????? ??? ???? ?- Tk ?????
17??????, ????? ?????????, ???? ???? Tk ???? ?????
?? ???? ???
- ??? ???? Ti ???????? ???? Tk, ????? TS(Tk) gt
TS(Ti), ???? ??????? ??? ???? ?????? ????? - Tk ?????? ???? ?- Ti ?????, ??
- Ti ???? ????? ??? ???? ?- Tk ?????
- ??? ???? ?? ???????, ???? ????? ??? ???? ?? ?????
??? - ????? ??????? ?????? ?????
- ????? ??????? ?????? ?????
- ???? ?????? ?????? ?? ?? ????
?? ??? ???? ????? ?? ????? ?? ???? ????????
???????
18????? ????? ?????????
- ???? ???? Ti ???? ?????? ?? ??? ??????, ????
????? ??? ?? ???? Tk ???? ???? ?? ??? ??????, ???
??? ???? ???? A ?- Ti ????? ????? - ?? ?? ???? Tk ??"?, ?? ???? ???? ????? ????
?????? - ???? ????? ?? Tk ???? (kill policy) ?? ??? ??
???? ?????? ???? ?????? (die policy)
19????? ????? ?????
- ???? ???? ?? ?????? ??????
- (transaction id, item id, modified)
- ?? ????, ?????? ????, ?????? ????? ??"? ????? ??
?- id ?? ????? ??- id ?? ????? - ???? modified ??? ?????? false
- ???? ???? ??????? ?????? ?? ??????, ?? ???????
??? ?????? ??????
20???? ??????
- ???? ???? Ti ????? ???? ???? A, ??? ????? ??????
?? ?? ??????? ???? ????? A ????? ????? ?? ????
modified ?- true - ???? ????? ???? (kill policy) ?? ?? ???????, ???
??????? ???? Ti?????, ?? ??? ??? ???? ???????
???? ?????? (die policy)
21???? ??????
- ???? ???? Tk ?????, ???? ????? ?????? ?? ??
??????? ???? ???? ?? - ?? (?????) ???? ???????, ???? ???? ????? A, ????
modified ??? true, ????? ???? ????? ???? ???????
???? ??? ???? A, ??? Tk ?? ???? ???? - ??? ????, ???? ?? Tk
22??????? ?? ????? ??????? ?????
- ???? ???? ?????? ????? ????? ?? ???? ?? ????
modified ??? ??????? ???? ???? ???? A, ???? ?????
????? ????? ?? ?????
23???? ???? ?????? ????? ???? ?? ??? ???? ???????
- ??????, ???? ????? ???
- ??? ?? ??????? ????? ?????? ???? ?? ??? ??????,
??? ???? ??????? ?????? (???, ???????) ?? ??
????? ?? ???? ???? ????? - ???, ????? ???? ?? ????? ???? ???? ???? ????
?????? ?? ????? ???? ???? ???? ????? ?? ???
?????? ??????
24?????, ?????? ????, ?? ????? ?? ???? ?????? ?????
??? ???? ??????? ?????? ????? ?-
- ?? ????? ???? ??????? ????? ?? ?? ????? (??? ??
???? ?? ?????? ????? ????? ???????) - ????? ?????? ????? ???? ?????? ????? ??? ?????
- ???? ?? ????? ?????? ???, ?? ???? ????? ????
???, ?? ????? ?? ????? ??? ??? ??????? ??????
25???? ???????? ??????? ?? ?????? ???
- Timestamp-Based Concurrency Control
26???? ???????? ??????? ?? ?????? ???
Timestamp-Based Concurrency Control
- ????? ???? ?? ?????? ????? ???? ?????, ??????
????? ??? ??? ?????? ????? ?? ????? - ???? ????? ????? ??? ???? ??? ??????
- ???? ??????? ????? ??????? ????? ????? ??? ????
????? ?????? ?????? ??? ??????? ??????? ??? ????
?? ?????? ???? - "?????" ?? ???? ?????? ????? ?????? ??? ?????
??????
27?? ??? ???? ?? ?????? ???
- ??? ???? A ???? ?? ??? ?????? ???
- RTS(A) ??? ????? ??? ??????? ??? ????? ????
??????? (???? ????, ???? ?? ????? ?????? ?????
????? ?? A) - WTS(A) ??? ????? ??? ??????? ??? ????? ????
??????? (???? ????, ???? ?? ????? ?????? ?????
????? ?? A) - ??????, ???? T ?????? ???? A ???? ?? RTS(A) ?-
TS(T) ?? RTS(A) ??? ?- TS(T) - ????? ????, ???? T ?????? ???? A ???? ?? WTS(A)
?- TS(T) ?? WTS(A) ??? ?- TS(T)
28?? ???? ??????
- ???? T ?? ????? ????? ???? ???? ???? ?? ??? ????
????, ?????? ?????? ???? T - ?????? ?????, ?? T ???? ????? ???? A, ??
- ?? TS(T) lt WTS(A), ?? ???? ???? ?? T ??????? ????
???? (?? ????? ??? ????) - ???? T ????? ?? A ?-
- RTS(A) max TS(T), RTS(A)
29?? ??? ???? ??????
- ???? T ?? ????? ????? ???? ???? ???? ?? ??? ????
????, ?????? ?????? ???? T - ?????? ?????, ?? T ???? ????? ???? A, ??
- ?? TS(T) lt RTS(A), ?? ???? ???? ?? T ??????? ????
???? (?? ????? ??? ????) - ?? TS(T) gt RTS(A) ??? TS(T) gt WTS(A), ?? T ?????
?? A ?- WTS(A) TS(T)
30??? ???? ?? TS(T) gt RTS(A) ??? TS(T) lt WTS(A)?
- ?? ????? ???? ?????? ????? ??????, ???? ????? ???
??? ???? A ?? ????? ?? WTS(A) - ?????, ?????? ?- T ????? ????? ???? ????? ??
????? A ??? ??? ??????, ?????? ?????? ?????? ?? A
?? ??? ???? ???? T, ???? ???? ?? A ???????
?????? ????? ??? ?????? ???? T
31??? ?????? ??????? ?? A ?? ??? T ??? ?????
???????
- TS(T) ???? ?- WTS(A), ?? T ??? ??????? ????? ??
A - ???? T ?? ???? ?? A, ?? ??? ?????? TS(T) lt
RTS(A), ?? TS(T) lt WTS(A) - ??? ???? ?- TS(T) gt RTS(A)
32???? ????? ????? ???????
- ???? T ?????? ???? A ????? ????? ????? ??????
????? ?????? ????? ?? A ?? ????? ?- T ??????? - ???? ????? ?????? ????? ????? ?? A ?? ?????????
- ?? ???? ?? ????, ?? ?????? ????? ?????? ????????,
??????? ????? ???? ????? ??????? ????? ?????
????????
33?????
- ???????? ?????? ???? ????? ??????? ????? ???????
?? ??? 2PL (?? ???????? ?????? ????????) - ??? ???? ????
- ???? ????? ?? ????? ?????? ??? ??? ??????? ????
?????? ????? ?????? ????????, ???????? ??????
???? ???? ??? ??????????? ?? ?????? ???????
??????? - ??????? ?? ????? ??????? ???? ?????? ???????
34???? ???????? ????? ??????
- Multiversion Concurrency Control
35???? ???????? ????? ??????Multiversion
Concurrency Control
- ??? ???? ???? ?????? ?????? ????
- ?????? T ????? ???? A ??? ????? ?????? ???? ????
?? A, ??- WTS(A) ??? ???? ?- TS(T) - ??? ??????? ?? ???? A ???? ?- RTS(A), ????? ?- TS
?? ????? ??? ?????? ????? ?? A
36???? ???? ?????
- ???? T ????? ????? ???? A, ????? ?? ????? ??? ??
?? ?- WTS(A) ??? ????, ???? ?? ??? ?????? ?-
TS(T) - ????? ?????? ?? RTS(A)
- RTS(A) max TS(T), RTS(A)
37??? ???????
- ?? ???? T ???? ????? ???? A, ?? ???? ????? (???
????????? ?????? ???? ?????) ?- TS(T) gt RTS(A) - ?? ???? ?? ??????, ?? ??????? ???? ???? ?? A, ???
?? WTS(A) ????? ?- TS(T) - ?- RTS(A) ?? ????? ????? ??? ??? ?- RTS(A) ?? ??
??????? ??????? (????? ???? ?- RTS(A)) - ?? ????? ???? ??????, ?? ???? ???? ?? T ???????
???? ????
38??????
- ?????? ????? ???? ????? ??? ?????? ????? ??
????????? ?? ??????? - ???????? ?? ???? (?????) ??????
- ?????? ?????? ????? ?????? ????? ???? ?? ??
?????? ?????? ???? ??? ?? - ????? ???? ??????? ???? ?? ???? ?? ?????
- ???? ????? ?????? ???? ???? ???? ?? ???? ??? ????
39?????? ?????? ??????? ???????
40??????? ?? ???????? ?????
- Multiple-Granularity Locks
41??????? ?? ???????? ?????Multiple-Granularity
Locks
- ?? ???? ????? ????? ?? ????? ????? (??????) ??
???? (???), ?? ???? ?????? ???? ?? ?? ????, ???
?????? ?? ?????? ?? ?????? ???????? - ????? ???, ?? ???? ????? ????? ?? ??? ??? ??????
?? ????, ?? ???? ?????? ???? ?? ???? ???, ??? ??
????? ??????? ????? ????? ?????? ?? ???? ????? ??
???? ????
42????? ????
- ?? ???? ????? ????? ?? ????? ??????? ??????? ???
????, ?? ???? ????? ?? ?? ??? - ????? ???, ?? ???? ????? ????? ?? ??? ???
????????, ?? ???? ????? ?? ?? ??????? ???? ??? ??
?? ???
43?????, ????? ??? ???? ???? ?????? ????? ????? ??
????????
- ???? ???????? ???? ??????, ??? ??? ????? ???????,
??? ???????? ???????? ?????? ??? ???? - ????? ????? ???? ????? ?? ????????? ????? ?????
????? - ??? ??????? ?????? ????? ????? ????? ??? ?? ??
????? ???? ???? ????? ????? (?? ?????) ?????
????? ???? ?? ?? ??????
44???? ????? ??? ????????? ?????? ?? ??? ???????
- ????? ????????
- ??? ??????? ???? ??????
- ?? ???? (???) ????? ????
- ?? ?? (????) ???? ??????
- ???? ???? ???? ?? ???, ????
- ????? ??? ?? ??? ???????
- ?????? ?? ???? ??? ?? ?? ??????? ????? ??????
???? ??????? ?? - ??????, ?????? ?? ???? ?? ?? ????? ?? ?????
45????? ???? ?"? ????? S ?? X ?????? ????? ?? ??-???
- ?? ????? ???? S ?? X ????? ?? ???? ???, ??
??????? ??? ?????? ?? ????? ?? ?? ?? ??????? ??
????? - ???, ???? ???? ????? ????? ???? ?? ??? ??????
????? ????? ???? ?? ???? ?? ???? ????? (ancestor)
?? ?????
46???? ?? ?????? ?????Intention Locks
- ????? ???? intention exclusive ????? ?"? IX
- ?? ???? ????? ???? ?"? ????? IX, ?? ????? ????
??? ?? ????? ????? ?????? ?? ????? ?"? ????? X - ????? ???? intention shared ????? ?"? IS
- ?? ???? ????? ???? ?"? ????? IS, ?? ????? ????
??? ?? ????? ????? ?????? ?? ????? ?"? ????? S
47?????? ??? ???? ????????
- ??? ????, ?? ???? ?????? ????? ???? ?????? S ??
??? ??? ????? ???? X (?? ???? ????) - ?? ???? ?????? ????? ???? ?????? IS ?? ??? ???
????? ???? X (?? ???? ????) - ?? ???? ?????? ????? ???? ?????? IX ?? ??? ???
??????? ???? S ?? X (?? ?????? ?????) - ??????, ?? ???? ?????? ????? ???? ?????? IS ?????
?????? IX ??-????? - ???? ?? ???? ?????? IS ????? ?????? S ??-?????
- ?? ?? ????? X, ?? ??? ?????? ??? ????? ????
48?????? ?????????(??? ??? ?????? ?????)
???? ??? ????? ?????? IX ??? S
49????????? ??????? ??-????????
- ???? ????? ?????? ?????? ????? ?"? S, X, IX ?? IS
- ???? ????? ????? ???? ?"? IS ?? S ?? ??? ??????
IS ?? ????? ?? ????? - ???? ????? ????? ???? ?"? IX ?? X ?? ??? ??????
IX ?? ????? ?? ????? - ???? ?????? ????? ???? ?"? S ?? X, ?? ?? ???????
?? ????? ?????? ?? ?? ???? ???? ?????? ???? ???
??? ?????
50???? ?????????
- ?? ???? ????? ????? ??? ??? ???? (IS, IX, S ?? X)
????? ????, ??? ?? ?? ??? ??? ??????? ?? ??????
?? ????? - ?? ??????? (??? ????? ??????) ??????? ???
????????? ?? ?????? ???? ????? - ?????, ???? ????? ?? ??????
- ???? ?????? ?????? ?? ????? (??? ??? ????), ????
????? ?? ????? ???????
51???? ???? ????? ?
- ???? ????? ????? ????? ??? ??? ???? (IS, IX, S ??
X) ????? ???? ?? ?? ??? ?? ??? ??????? ?? ??????
?? ?????? - ?? ???? ????? ?? ?????? ??? ?????? (???? ???????
????? ?? ?????), ?? ?? ???? ???? ????? ????? ??
????? ?"? X ??? ????? ?? ??? ???? ?"? X - ?? ????? ??????? ????? ?????? ????? S ?? X ??
???? ????? ??? ?? ???? ?? ?????? ?????? ?????
?????? ????? X ????? ?? ?? ???
52???? ????
- ???? ???? ????? ??? ?????? ?????? ???? ??? ??
?????? ??????? ???? - ????? ???? ?? ????? ??????? ??? ???? ?"? IX ??"?
S - ?????? ????? ?????? ????? ???? ?? ?"? IS
- ????? ????? ???? ?????? ?????? ?"? IX ?? X
- ?????? ????? ?????? ????? ?????? ????? ?"? S
53????? ?? ??????Granularity Escalation
- ??? ??????? ??? ????????? ??????? ????? ??????
- ???? ?????? ?? ???????? ????? (????, ????? ????
?? ??????) ????? ????? ???????? ?????? ????? ????
?? ?????, ?? ??????? ?? ????????? ???? ????
(????, ?????? ???? ?? ????)
???? ????? ????? ???? ?"? X ??? ??"? ????? ????
?? ????? ?"? X
54??????
- ????????? ?? ?????? ?? ???????? ????? ?? ???????
??? ??????? ?????????? - ?????? ???? ?? ?????, ???? 506
- ???? ?? ????? intention locks ?????? warnings
55??? ????????????? ???????
56?????? Latches
- ??????, ??? ?????? ?????? ?????? ??-????? ???????
?? ??? ?????? ????? ??????? ????? ???? - ?????? ??? ???? ????? ??-????? ?? ????? ????? ??
???? ????, ???? ????? ?????? ???? ?? ????? ????
???? ??? ??? ????? ????? ?? ????? ?? ????? ??????
?????
57?????? ???????? ?? ??? B
- ???? ?????? ???? ??? ?? B (??? ???? ????? ??????
???? ?? ????), ???? ????? ?? ?? ?????? ?? ???????
???? ?????? ??? ?? ?? ???? - ????? ???????? ?? ??? ?????? ????? ?? ?? ??????
??-????? - ???????? 2PL ????? ??????? ?? ?????? ???????
?????
58???? ????
- ???? ????? ????? ?? ?? B ??? ???????? ??????
???? ???????? ???? 2PL - ??????, ???? ????? ?? ??????? ?? ????? ????????
?? ??? ????? ????, ????? ??? ???? ????? ????? ??
????? ???????? - ????? ????