Академический Документы
Профессиональный Документы
Культура Документы
Name
Age
White
52
Green 3421
Gray
1
2
Definition:
Consistent state: satisfies all constraints
Consistent DB: DB in consistent state
Acct #
balance deleted?
DB
Reality
a2
.
.
50
.
.
150
.
.
150
TOT
.
.
1000
.
.
1000
.
.
1100
Consistent DB
Consistent DB
10
Big assumption:
If T starts with consistent state +
T executes in isolation
T leaves consistent state
11
Correctness
(informally)
12
Data sharing
e.g.: T1: give 10% raise to programmers
systems analysts
13
14
15
16
Events
Desired
Undesired
Expected
Unexpected
17
memory
processor
D
disk
18
19
Undesired Unexpected:
Everything else!
20
Undesired Unexpected:
Everything else!
Examples:
Disk data is lost
Memory lost without CPU halt
CPU implodes wiping out universe.
21
x
Memory
x
Disk
23
Operations:
Input (x): block containing x memory
Output (x): block containing x disk
24
Operations:
Input (x): block containing x memory
Output (x): block containing x disk
Read (x,t): do input(x) if necessary
t value of x in block
Write (x,t): do input(x) if necessary
value of x in block t
25
Constraint: A=B
T1: A A 2
B B2
26
A: 8
B: 8
disk
27
A: 8
B: 8
disk
28
A: 8 16
B: 8
disk
29
30
(immediate
modification)
31
(immediate
modification)
32
Undo logging
(Immediate modification)
A=B
A:8
B:8
memory
disk
log
33
Undo logging
(Immediate modification)
A=B
<T1, start>
<T1, A, 8>
A:8
B:8
disk
log
34
Undo logging
(Immediate modification)
A:8 16
B:8
disk
A=B
<T1, start>
<T1, A, 8>
<T1, B, 8>
log
35
Undo logging
(Immediate modification)
A:8 16
B:8 16
disk
A=B
<T1, start>
<T1, A, 8>
<T1, B, 8>
log
36
Undo logging
(Immediate modification)
A:8 16
B:8 16
disk
A=B
<T1, start>
<T1, A, 8>
<T1, B, 8>
<T1, commit>
log
37
One complication
Log is first written in memory
Not written to disk on every action
memory
A: 8 16
B: 8 16
Log:
<T1,start>
<T1, A, 8>
<T1, B, 8>
A: 8
B: 8
DB
Log
38
One complication
Log is first written in memory
Not written to disk on every action
memory
A: 8 16
B: 8 16
Log:
<T1,start>
<T1, A, 8>
<T1, B, 8>
A: 8 16
B: 8
DB
Log
BAD STATE
#1
39
One complication
Log is first written in memory
Not written to disk on every action
A: 8 16
B: 8 16
Log:
<T1,start>
<T1, A, 8>
<T1, B, 8>
<T1, commit>
A: 8 16
B: 8
DB
Log
BAD STATE
#2
...
memory
<T1, B, 8>
<T1, commit>
40
Recovery rules:
Undo logging
42
Recovery rules:
Undo logging
Recovery rules:
Undo logging
- write (X, v)
- output (X)
Question
Can writes of <Ti, abort> records
be done in any order (in Step 3)?
Example: T1 and T2 both write A
T1 executed before T2
T1 and T2 both rolled-back
<T1, abort> written but NOT <T2, abort>?
<T2, abort> written but NOT <T1, abort>?
T1 write A
T2 write A
time/log
45
46
To discuss:
Redo logging
Undo/redo logging, why both?
Real world actions
Checkpoints
Media failures
47
Redo Logging
First send Gretel up with no rope,
then Hansel goes up safely with rope!
48
A: 8
B: 8
DB
LOG
49
A: 8
B: 8
<T1, start>
<T1, A, 16>
<T1, B, 16>
<T1, commit>
DB
LOG
50
output
A: 8 16
B: 8 16
<T1, start>
<T1, A, 16>
<T1, B, 16>
<T1, commit>
DB
LOG
51
output
A: 8 16
B: 8 16
DB
<T1, start>
<T1, A, 16>
<T1, B, 16>
<T1, commit>
<T1, end>
LOG
52
Recovery rules:
Redo logging
54
Recovery rules:
Redo logging
IS THIS CORRECT??
55
Recovery rules:
Redo logging
Actions:
write X
output X
write X
output X
write X
output X
write X
output X
57
Actions:
write X
output X
write X
output X
write X
output X
write X
output X
combined <end> (checkpoint)
58
Solution: Checkpoint
Periodically:
(1) Do not accept new transactions
(2) Wait until all transactions finish
(3) Flush all log records to disk (log)
(4) Flush all buffers to disk (DB) (do not discard buffers)
(5) Write checkpoint record on disk (log)
(6) Resume transaction processing
59
...
<T3,C,21>
...
<T2,commit>
...
<T2,B,17>
...
Checkpoint
...
<T1,commit>
...
<T1,A,16>
60
Key drawbacks:
Undo logging: cannot bring backup DB
copies up to date
Redo logging: need to keep all modified
blocks in memory
until commit
61
62
Rules
Page X can be flushed before or
after Ti commit
Log record flushed before
corresponding updated page (WAL)
Flush at commit (log only)
63
...
...
...
<T1, commit>
...
...
...
<checkpoint>
log (disk):
Crash
64
Non-quiesce checkpoint
...
Start-ckpt
active TR:
Ti,T2,...
...
end
ckpt
...
...
L
O
G
for
undo
dirty buffer
pool pages
flushed
65
Non-quiesce checkpoint
memory
checkpoint process:
for i := 1 to M do
output(buffer i)
[transactions run concurrently]
66
L
O
G
...
T1,a
...
Ckpt
T1
...
Ckpt
end
...
T 1b
67
L
O
G
...
T1,a
Undo T1
...
Ckpt
T1
...
Ckpt
end
...
T 1b
(undo a,b)
68
Example
L
O
G
ckpt-s
T1
T1
ckptT1
T1
...
... T1 ...
...
...
...
...
a
b
end
c
cmt
69
Example
L
O
G
ckpt-s
T1
T1
ckptT1
T1
...
... T1 ...
...
...
...
...
a
b
end
c
cmt
70
ckpt
start
...
ckpt
end
...
T1
T1
ckpt... start ...
...
b
c
start
of latest
valid
checkpoint
71
Recovery process:
Backwards pass
Forward pass
backward pass
forward pass
72
73
Solution
(1) execute real-world actions after commit
(2) try to make idempotent
74
ATM
Give$$
(amt, Tid, time)
lastTid:
time:
give(amt)
75
A: 16
76
A: 16
X1
X2
X3
78
Example #2
Redundant writes,
Single reads
79
backup
database
log
active
database
80
Backup Database
Just like checkpoint,
except that we write full database
database
81
Backup Database
Just like checkpoint,
except that we write full database
database
log
db
dump
last
needed
undo
checkpoint
time
83
Summary
Consistency of data
One source of problems: failures
- Logging
- Redundancy
84