Presentation is loading. Please wait.

Presentation is loading. Please wait.

CPSC-608 Database Systems

Similar presentations


Presentation on theme: "CPSC-608 Database Systems"— Presentation transcript:

1 CPSC-608 Database Systems
Fall 2018 Instructor: Jianer Chen Office: HRBB 315C Phone: Notes #33

2 Graduate Database …… DBMS User-1 User-2 User-3 User-n lock table DDL
complier lock table file manager logging & recovery concurrency control User-1 DDL User-2 transaction manager index/file manager buffer manager ……,T2,T1 User-3 query execution engine …… DML complier DML …… Q2,Q1 main memory buffers User-n secondary storage (disks) DBMS Graduate Database

3 Tranactions What is a transaction? What is a logic step
A sequence of actions that we want to be done as a single “logic step ” What is a logic step (what do we want a transaction to be)? ACID: Atomicity: either all steps of a transaction happen, or none happen Consistency: a transaction transforms a consistent DB into a consistent DB Isolation: execution of a transaction is isolated from that of other transactions Durability: if a transaction commits, its effects persist.

4 We will be focused on: How to prevent/fix constraint violations
due to system failures How do we recover from system failures? due to concurrent executed transactions due to both

5 Computational Model CPU memory disk input (x): disk Bx  memory Bx
output (x): memory Bx  disk Bx read (x,t): \\ do input(x) if necessary t  value of x in memory Write (x,t): \\ do input(x) if necessary Bx in memory  value of t Computational Model CPU A=10 B=10 C=30 memory disk 5

6 Computational Model CPU
Thus, we must find a way to record the changes made by the transactions: 1. This can only be done in main memory; 2. The record must be copied to disk memory disk 6

7 Computational Model CPU
T1: A  A  3 B  B  3 read (A,t); t  t3; write (A,t); read (B,t); t  t3; write (B,t); output (A); output (B); CPU Thus, we must find a way to record the changes made by the transactions: 1. This can only be done in main memory; 2. The record must be copied to disk A=10 B=10 C=30 memory disk 7

8 Computational Model CPU
T1: A  A  3 B  B  3 read (A,t); t  t3; write (A,t); read (B,t); t  t3; write (B,t); output (A); output (B); CPU Thus, we must find a way to record the changes made by the transactions: 1. This can only be done in main memory; 2. The record must be copied to disk log A=10 B=10 C=30 A=30 (T1, A 10 →30) memory disk 8

9 Computational Model CPU
T1: A  A  3 B  B  3 read (A,t); t  t3; write (A,t); read (B,t); t  t3; write (B,t); output (A); output (B); CPU Thus, we must find a way to record the changes made by the transactions: 1. This can only be done in main memory; 2. The record must be copied to disk log A=10 B=10 C=30 A=30 A=30 (T1, A 10 →30) (T1, B 10 →30) (T1, A 10 →30) (T1, B 10 →30) B=30 B=30 memory disk 9

10 Computational Model CPU
T1: A  A  3 B  B  3 read (A,t); t  t3; write (A,t); read (B,t); t  t3; write (B,t); output (A); output (B); CPU Thus, we must find a way to record the changes made by the transactions: 1. This can only be done in main memory; 2. The record must be copied to disk log A=10 B=10 C=30 A=30 A=30 (T1, A 10 →30) (T1, B 10 →30) (T1, A 10 →30) (T1, B 10 →30) B=30 B=30 memory disk 10

11 Computational Model CPU
T1: A  A  3 B  B  3 read (A,t); t  t3; write (A,t); read (B,t); t  t3; write (B,t); output (A); output (B); CPU Thus, we must find a way to record the changes made by the transactions: 1. This can only be done in main memory; 2. The record must be copied to disk A=30 B=30 C=30 (T1, A 10 →30) (T1, B 10 →30) memory disk 11

12 When should log be copied to disk?
Computational Model T1: A  A  3 B  B  3 read (A,t); t  t3; write (A,t); read (B,t); t  t3; write (B,t); output (A); output (B); CPU Thus, we must find a way to record the changes made by the transactions: 1. This can only be done in main memory; 2. The record must be copied to disk log A=30 B=30 C=30 A=30 (T1, A 10 →30) (T1, B 10 →30) (T1, A 10 →30) (T1, B 10 →30) B=30 (T1, A 10 →30) (T1, B 10 →30) memory When should log be copied to disk? disk 12

13 Computational Model CPU
T1: A  A  3 B  B  3 read (A,t); t  t3; write (A,t); read (B,t); t  t3; write (B,t); output (A); output (B); CPU Thus, we must find a way to record the changes made by the transactions: 1. This can only be done in main memory; 2. The record must be copied to disk log A=30 B=30 C=30 A=30 (T1, A 10 →30) (T1, B 10 →30) (T1, A 10 →30) (T1, B 10 →30) B=30 (T1, A 10 →30) (T1, B 10 →30) memory When should log be copied to disk? After the changes reach disk? disk 13

14 Computational Model CPU
T1: A  A  3 B  B  3 read (A,t); t  t3; write (A,t); read (B,t); t  t3; write (B,t); output (A); output (B); CPU Thus, we must find a way to record the changes made by the transactions: 1. This can only be done in main memory; 2. The record must be copied to disk log A=30 B=30 C=30 A=30 (T1, A 10 →30) (T1, B 10 →30) (T1, A 10 →30) (T1, B 10 →30) B=30 memory When should log be copied to disk? After the changes reach disk? disk 14

15 Computational Model CPU
T1: A  A  3 B  B  3 read (A,t); t  t3; write (A,t); read (B,t); t  t3; write (B,t); output (A); output (B); CPU Thus, we must find a way to record the changes made by the transactions: 1. This can only be done in main memory; 2. The record must be copied to disk log A=30 B=30 C=30 A=30 (T1, A 10 →30) (T1, B 10 →30) (T1, A 10 →30) (T1, B 10 →30) B=30 (T1, A 10 →30) (T1, B 10 →30) memory When should log be copied to disk? Before the changes reach disk? disk 15

16 Computational Model CPU
T1: A  A  3 B  B  3 read (A,t); t  t3; write (A,t); read (B,t); t  t3; write (B,t); output (A); output (B); CPU Thus, we must find a way to record the changes made by the transactions: 1. This can only be done in main memory; 2. The record must be copied to disk log A=10 B=10 C=30 A=30 (T1, A 10 →30) (T1, B 10 →30) (T1, A 10 →30) (T1, B 10 →30) B=30 (T1, A 10 →30) (T1, B 10 →30) memory When should log be copied to disk? Before the changes reach disk? disk 16

17 When should log be copied to disk?
Computational Model T1: A  A  3 B  B  3 read (A,t); t  t3; write (A,t); read (B,t); t  t3; write (B,t); output (A); output (B); CPU Thus, we must find a way to record the changes made by the transactions: 1. This can only be done in main memory; 2. The record must be copied to disk log A=10 B=10 C=30 A=30 (T1, A 10 →30) (T1, B 10 →30) (T1, A 10 →30) (T1, B 10 →30) B=30 (T1, A 10 →30) (T1, B 10 →30) memory When should log be copied to disk? Arbitrarily? disk 17

18 When should log be copied to disk?
Computational Model T1: A  A  3 B  B  3 read (A,t); t  t3; write (A,t); read (B,t); t  t3; write (B,t); output (A); output (B); CPU Thus, we must find a way to record the changes made by the transactions: 1. This can only be done in main memory; 2. The record must be copied to disk log A=30 B=10 C=30 A=30 (T1, A 10 →30) (T1, B 10 →30) (T1, A 10 →30) (T1, B 10 →30) B=30 (T1, B 10 →30) memory When should log be copied to disk? Arbitrarily? disk 18

19 Coping with System Failures
Therefore, the logging strategy must be carefully designed to ensure Atomicity and Durability. If you are going to be in the logging business, one of the things that you have to do is to learn about heavy equipment. Robert VanNatta, Logging History of Columbia County

20 Coping with System Failures
Therefore, the logging strategy must be carefully designed to ensure Atomicity and Durability. If you are going to be in the logging business, one of the things that you have to do is to learn about heavy equipment. Robert VanNatta, Logging History of Columbia County We will study three logging strategies: Undo-logging Redo-logging Undo/Redo-logging

21 Coping with System Failures
Therefore, the logging strategy must be carefully designed to ensure Atomicity and Durability. If you are going to be in the logging business, one of the things that you have to do is to learn about heavy equipment. Robert VanNatta, Logging History of Columbia County We will study three logging strategies: Undo-logging Redo-logging Undo/Redo-logging

22 Undo-Logging The format of the Undo-log: <T, start>
<T, A, aold> …… <T, B, bold> <T, commit> (or <T, abort>) transaction T starts transaction T wrote on A/B, and A/B had an old value aold/bold transaction T commits/abort

23 Undo-Logging The format of the Undo-log: Main idea of Undo-logging:
<T, start> <T, A, aold> …… <T, B, bold> <T, commit> (or <T, abort>) transaction T starts transaction T wrote on A/B, and A/B had an old value aold/bold transaction T commits/abort Main idea of Undo-logging: When log record <T, commit> reaches disk, all changes made by T have reached disk.

24 Undo-Logging Main idea of Undo-logging: When <T, commit> reaches disk, all changes made by T have reached disk. <T,V1, a1> <T, commit> New V1 <T, start> <T,V3, a3> <T,V2, a2> <T,V4, a4> New V3 New V4 New V2 The order in which the values reach disk Undo-logging rules: U1. The log record <T, V, aold> reaches disk before the change of V reaches disk; U2. The log record <T, commit> reaches disk after all changes made by T reach disk.

25 Undo-Logging Algorithms for undo-logging Undo-logging rules:
U1. The log record <T, V, aold> reaches disk before the change of V reaches disk; U2. The log record <T, commit> reaches disk after all changes made by T reach disk. Algorithms for undo-logging

26 Undo-Logging Algorithms for undo-logging Log recording
Undo-logging rules: U1. The log record <T, V, aold> reaches disk before the change of V reaches disk; U2. The log record <T, commit> reaches disk after all changes made by T reach disk. Algorithms for undo-logging Log recording 1. When T writes on A, add a log-record <T, A, aold> (in memory-log); 2. Before output(A), make sure the memory-log is flushed to disk-log at least once; 3. Add log-record <T, commit> to memory-log only when all output(A) related to T are done.

27 Undo-Logging Algorithms for undo-logging Log recording
Undo-logging rules: U1. The log record <T, V, aold> reaches disk before the change of V reaches disk; U2. The log record <T, commit> reaches disk after all changes made by T reach disk. Algorithms for undo-logging Log recording 1. When T writes on A, add a log-record <T, A, aold> (in memory-log); 2. Before output(A), make sure the memory-log is flushed to disk-log at least once; 3. Add log-record <T, commit> to memory-log only when all output(A) related to T are done.

28 Undo-Logging Algorithms for undo-logging Log recording
Undo-logging rules: U1. The log record <T, V, aold> reaches disk before the change of V reaches disk; U2. The log record <T, commit> reaches disk after all changes made by T reach disk. Algorithms for undo-logging Log recording 1. When T writes on A, add a log-record <T, A, aold> (in memory-log); 2. Before output(A), make sure the memory-log is flushed to disk-log at least once; 3. Add log-record <T, commit> to memory-log only when all output(A) related to T are done.

29 Undo-Logging Algorithms for undo-logging Log recording
Undo-logging rules: U1. The log record <T, V, aold> reaches disk before the change of V reaches disk; U2. The log record <T, commit> reaches disk after all changes made by T reach disk. Algorithms for undo-logging Log recording 1. When T writes on A, add a log-record <T, A, aold> (in memory-log); 2. Before output(A), make sure the memory-log is flushed to disk-log at least once; 3. Add log-record <T, commit> to memory-log only when all output(A) related to T are done. System recovery with disk-log 1. Scan the disk-log backwards; 2. Ignore T if see <T, commit>; 3. For each T with no <T, commit> For each log-record <T, A, aold> Undo the action by restoring the value of A back to aold; Add <T, abort> to disk-log.

30 Undo-Logging Algorithms for undo-logging Log recording
Undo-logging rules: U1. The log record <T, V, aold> reaches disk before the change of V reaches disk; U2. The log record <T, commit> reaches disk after all changes made by T reach disk. Algorithms for undo-logging Log recording 1. When T writes on A, add a log-record <T, A, aold> (in memory-log); 2. Before output(A), make sure the memory-log is flushed to disk-log at least once; 3. Add log-record <T, commit> to memory-log only when all output(A) related to T are done. System recovery with disk-log 1. Scan the disk-log backwards; 2. Ignore T if see <T, commit>; 3. For each T with no <T, commit> For each log-record <T, A, aold> Undo the action by restoring the value of A back to aold; Add <T, abort> to disk-log.

31 Undo-Logging Algorithms for undo-logging Log recording
Undo-logging rules: U1. The log record <T, V, aold> reaches disk before the change of V reaches disk; U2. The log record <T, commit> reaches disk after all changes made by T reach disk. Algorithms for undo-logging Log recording 1. When T writes on A, add a log-record <T, A, aold> (in memory-log); 2. Before output(A), make sure the memory-log is flushed to disk-log at least once; 3. Add log-record <T, commit> to memory-log only when all output(A) related to T are done. System recovery with disk-log 1. Scan the disk-log backwards; 2. Ignore T if see <T, commit>; 3. For each T with no <T, commit> For each log-record <T, A, aold> Undo the action by restoring the value of A back to aold; Add <T, abort> to disk-log.

32 Undo-Logging Algorithms for undo-logging Log recording
Undo-logging rules: U1. The log record <T, V, aold> reaches disk before the change of V reaches disk; U2. The log record <T, commit> reaches disk after all changes made by T reach disk. Algorithms for undo-logging Log recording 1. When T writes on A, add a log-record <T, A, aold> (in memory-log); 2. Before output(A), make sure the memory-log is flushed to disk-log at least once; 3. Add log-record <T, commit> to memory-log only when all output(A) related to T are done. System recovery with disk-log 1. Scan the disk-log backwards; 2. Ignore T if see <T, commit>; 3. For each T with no <T, commit> For each log-record <T, A, aold> Undo the action by restoring the value of A back to aold; Add <T, abort> to disk-log.

33 Undo-logging: Example
Log recording 1. When T writes on A, add a log-record <T, A, aold> (in memory-log); 2. Before output(A), make sure the memory-log is flushed to disk-log at least once; 3. Add log-record <T, commit> to memory-log only when all output(A) related to T are done. Undo-logging: Example T1: A  A  3 B  B  3 read (A,t); t  t3; write (A,t); read (B,t); t  t3; write (B,t); output (A); output (B); CPU A=10 B=10 C=30 memory disk 33

34 Undo-logging: log recording
1. When T writes on A, add a log-record <T, A, aold> (in memory-log); 2. Before output(A), make sure the memory-log is flushed to disk-log at least once; 3. Add log-record <T, commit> to memory-log only when all output(A) related to T are done. Undo-logging: log recording T: A  A  3 B  B  3 add-log: <T, start> read (A,t); t  t3; write (A,t); add-log: <T, A, 10> flush-log output (A); read (B,t); t  t3; write (B,t); add-log: <T, B, 10> output (B); add-log: <T, commit> CPU A=10 B=10 C=30 memory disk 34

35 Undo-logging: log recording
1. When T writes on A, add a log-record <T, A, aold> (in memory-log); 2. Before output(A), make sure the memory-log is flushed to disk-log at least once; 3. Add log-record <T, commit> to memory-log only when all output(A) related to T are done. Undo-logging: log recording T: A  A  3 B  B  3 add-log: <T, start> read (A,t); t  t3; write (A,t); add-log: <T, A, 10> read (B,t); t  t3; write (B,t); add-log: <T, B, 10> flush-log output (A); output (B); add-log: <T, commit> CPU A=10 B=10 C=30 memory disk 35

36 Undo-logging: log recording
1. When T writes on A, add a log-record <T, A, aold> (in memory-log); 2. Before output(A), make sure the memory-log is flushed to disk-log at least once; 3. Add log-record <T, commit> to memory-log only when all output(A) related to T are done. Undo-logging: log recording T: A  A  3 B  B  3 add-log: <T, start> read (A,t); t  t3; write (A,t); add-log: <T, A, 10> read (B,t); t  t3; write (B,t); add-log: <T, B, 10> flush-log output (A); output (B); add-log: <T, commit> CPU log A=10 B=10 C=30 <T, start> memory disk 36

37 Undo-logging: log recording
1. When T writes on A, add a log-record <T, A, aold> (in memory-log); 2. Before output(A), make sure the memory-log is flushed to disk-log at least once; 3. Add log-record <T, commit> to memory-log only when all output(A) related to T are done. Undo-logging: log recording T: A  A  3 B  B  3 add-log: <T, start> read (A,t); t  t3; write (A,t); add-log: <T, A, 10> read (B,t); t  t3; write (B,t); add-log: <T, B, 10> flush-log output (A); output (B); add-log: <T, commit> CPU log A=10 B=10 C=30 A=30 <T, start> <T, A, 10> memory disk 37

38 Undo-logging: log recording
1. When T writes on A, add a log-record <T, A, aold> (in memory-log); 2. Before output(A), make sure the memory-log is flushed to disk-log at least once; 3. Add log-record <T, commit> to memory-log only when all output(A) related to T are done. Undo-logging: log recording T: A  A  3 B  B  3 add-log: <T, start> read (A,t); t  t3; write (A,t); add-log: <T, A, 10> read (B,t); t  t3; write (B,t); add-log: <T, B, 10> flush-log output (A); output (B); add-log: <T, commit> CPU log A=10 B=10 C=30 A=30 <T, start> <T, A, 10> <T, B, 10> B=30 memory disk 38

39 Undo-logging: log recording
1. When T writes on A, add a log-record <T, A, aold> (in memory-log); 2. Before output(A), make sure the memory-log is flushed to disk-log at least once; 3. Add log-record <T, commit> to memory-log only when all output(A) related to T are done. Undo-logging: log recording T: A  A  3 B  B  3 add-log: <T, start> read (A,t); t  t3; write (A,t); add-log: <T, A, 10> read (B,t); t  t3; write (B,t); add-log: <T, B, 10> flush-log output (A); output (B); add-log: <T, commit> CPU log A=10 B=10 C=30 A=30 <T, start> <T, A, 10> <T, B, 10> <T, start> <T, A, 10> <T, B, 10> B=30 <T, start> <T, A, 10> <T, B, 10> memory disk 39

40 Undo-logging: log recording
1. When T writes on A, add a log-record <T, A, aold> (in memory-log); 2. Before output(A), make sure the memory-log is flushed to disk-log at least once; 3. Add log-record <T, commit> to memory-log only when all output(A) related to T are done. Undo-logging: log recording T: A  A  3 B  B  3 add-log: <T, start> read (A,t); t  t3; write (A,t); add-log: <T, A, 10> read (B,t); t  t3; write (B,t); add-log: <T, B, 10> flush-log output (A); output (B); add-log: <T, commit> CPU log A=10 B=10 C=30 A=30 A=30 <T, start> <T, A, 10> <T, B, 10> B=30 B=30 <T, start> <T, A, 10> <T, B, 10> memory disk 40

41 Undo-logging: log recording
1. When T writes on A, add a log-record <T, A, aold> (in memory-log); 2. Before output(A), make sure the memory-log is flushed to disk-log at least once; 3. Add log-record <T, commit> to memory-log only when all output(A) related to T are done. Undo-logging: log recording T: A  A  3 B  B  3 add-log: <T, start> read (A,t); t  t3; write (A,t); add-log: <T, A, 10> read (B,t); t  t3; write (B,t); add-log: <T, B, 10> flush-log output (A); output (B); add-log: <T, commit> CPU log A=30 B=30 C=30 A=30 <T, start> <T, A, 10> <T, B, 10> <T, commit> <T, start> <T, A, 10> <T, B, 10> <T, commit> B=30 <T, start> <T, A, 10> <T, B, 10> <T, start> <T, A, 10> <T, B, 10> memory disk 41

42 Undo-logging: Failure Recovery
CPU A=10 B=10 C=30 memory disk 42

43 Undo-logging: Failure Recovery
System recovery with disk-log 1. Scan the disk-log backwards; 2. Ignore T if see <T, commit>; 3. For each T with no <T, commit> For each log-record <T, A, aold> Undo the action by restoring the value of A back to aold; Add <T, abort> to disk-log. Undo-logging: Failure Recovery T: A  A  3 B  B  3 add-log: <T, start> read (A,t); t  t3; write (A,t); add-log: <T, A, 10> read (B,t); t  t3; write (B,t); add-log: <T, B, 10> flush-log output (A); output (B); add-log: <T, commit> CPU A=10 B=10 C=30 memory disk 43

44 crash occurs after this point,
System recovery with disk-log 1. Scan the disk-log backwards; 2. Ignore T if see <T, commit>; 3. For each T with no <T, commit> For each log-record <T, A, aold> Undo the action by restoring the value of A back to aold; Add <T, abort> to disk-log. Undo-logging: Failure Recovery T: A  A  3 B  B  3 add-log: <T, start> read (A,t); t  t3; write (A,t); add-log: <T, A, 10> read (B,t); t  t3; write (B,t); add-log: <T, B, 10> flush-log output (A); output (B); add-log: <T, commit> CPU A=10 B=10 C=30 crash occurs after this point, memory disk 44

45 crash occurs after this point,
System recovery with disk-log 1. Scan the disk-log backwards; 2. Ignore T if see <T, commit>; 3. For each T with no <T, commit> For each log-record <T, A, aold> Undo the action by restoring the value of A back to aold; Add <T, abort> to disk-log. Undo-logging: Failure Recovery T: A  A  3 B  B  3 add-log: <T, start> read (A,t); t  t3; write (A,t); add-log: <T, A, 10> read (B,t); t  t3; write (B,t); add-log: <T, B, 10> flush-log output (A); output (B); add-log: <T, commit> CPU log A=30 B=30 C=30 A=30 <T, start> <T, A, 10> <T, B, 10> <T, commit> B=30 crash occurs after this point, <T, start> <T, A, 10> <T, B, 10> <T, commit> memory disk 45

46 crash occurs after this point,
System recovery with disk-log 1. Scan the disk-log backwards; 2. Ignore T if see <T, commit>; 3. For each T with no <T, commit> For each log-record <T, A, aold> Undo the action by restoring the value of A back to aold; Add <T, abort> to disk-log. Undo-logging: Failure Recovery T: A  A  3 B  B  3 add-log: <T, start> read (A,t); t  t3; write (A,t); add-log: <T, A, 10> read (B,t); t  t3; write (B,t); add-log: <T, B, 10> flush-log output (A); output (B); add-log: <T, commit> CPU A=30 B=30 C=30 crash occurs after this point, <T, start> <T, A, 10> <T, B, 10> <T, commit> memory disk 46

47 crash occurs after this point,
System recovery with disk-log 1. Scan the disk-log backwards; 2. Ignore T if see <T, commit>; 3. For each T with no <T, commit> For each log-record <T, A, aold> Undo the action by restoring the value of A back to aold; Add <T, abort> to disk-log. Undo-logging: Failure Recovery T: A  A  3 B  B  3 add-log: <T, start> read (A,t); t  t3; write (A,t); add-log: <T, A, 10> read (B,t); t  t3; write (B,t); add-log: <T, B, 10> flush-log output (A); output (B); add-log: <T, commit> CPU A=30 B=30 C=30 crash occurs after this point, <T, start> <T, A, 10> <T, B, 10> <T, commit> memory disk 47

48 crash occurs at this point
System recovery with disk-log 1. Scan the disk-log backwards; 2. Ignore T if see <T, commit>; 3. For each T with no <T, commit> For each log-record <T, A, aold> Undo the action by restoring the value of A back to aold; Add <T, abort> to disk-log. Undo-logging: Failure Recovery T: A  A  3 B  B  3 add-log: <T, start> read (A,t); t  t3; write (A,t); add-log: <T, A, 10> read (B,t); t  t3; write (B,t); add-log: <T, B, 10> flush-log output (A); output (B); add-log: <T, commit> CPU log A=30 B=30 C=30 A=30 <T, start> <T, A, 10> <T, B, 10> B=30 <T, start> <T, A, 10> <T, B, 10> crash occurs at this point memory disk 48

49 crash occurs at this point
System recovery with disk-log 1. Scan the disk-log backwards; 2. Ignore T if see <T, commit>; 3. For each T with no <T, commit> For each log-record <T, A, aold> Undo the action by restoring the value of A back to aold; Add <T, abort> to disk-log. Undo-logging: Failure Recovery T: A  A  3 B  B  3 add-log: <T, start> read (A,t); t  t3; write (A,t); add-log: <T, A, 10> read (B,t); t  t3; write (B,t); add-log: <T, B, 10> flush-log output (A); output (B); add-log: <T, commit> CPU A=30 B=30 C=30 <T, start> <T, A, 10> <T, B, 10> crash occurs at this point memory disk 49

50 crash occurs at this point
System recovery with disk-log 1. Scan the disk-log backwards; 2. Ignore T if see <T, commit>; 3. For each T with no <T, commit> For each log-record <T, A, aold> Undo the action by restoring the value of A back to aold; Add <T, abort> to disk-log. Undo-logging: Failure Recovery T: A  A  3 B  B  3 add-log: <T, start> read (A,t); t  t3; write (A,t); add-log: <T, A, 10> read (B,t); t  t3; write (B,t); add-log: <T, B, 10> flush-log output (A); output (B); add-log: <T, commit> CPU A=10 B=10 C=30 <T, start> <T, A, 10> <T, B, 10> <T, abort> crash occurs at this point memory disk 50

51 crash occurs at this point
System recovery with disk-log 1. Scan the disk-log backwards; 2. Ignore T if see <T, commit>; 3. For each T with no <T, commit> For each log-record <T, A, aold> Undo the action by restoring the value of A back to aold; Add <T, abort> to disk-log. Undo-logging: Failure Recovery T: A  A  3 B  B  3 add-log: <T, start> read (A,t); t  t3; write (A,t); add-log: <T, A, 10> read (B,t); t  t3; write (B,t); add-log: <T, B, 10> flush-log output (A); output (B); add-log: <T, commit> CPU log A=30 B=10 C=30 A=30 <T, start> <T, A, 10> <T, B, 10> B=30 crash occurs at this point <T, start> <T, A, 10> <T, B, 10> memory disk 51

52 crash occurs at this point
System recovery with disk-log 1. Scan the disk-log backwards; 2. Ignore T if see <T, commit>; 3. For each T with no <T, commit> For each log-record <T, A, aold> Undo the action by restoring the value of A back to aold; Add <T, abort> to disk-log. Undo-logging: Failure Recovery T: A  A  3 B  B  3 add-log: <T, start> read (A,t); t  t3; write (A,t); add-log: <T, A, 10> read (B,t); t  t3; write (B,t); add-log: <T, B, 10> flush-log output (A); output (B); add-log: <T, commit> CPU log A=10 B=10 C=30 A=30 <T, start> <T, A, 10> <T, B, 10> B=30 crash occurs at this point <T, start> <T, A, 10> <T, B, 10> <T, abort> memory disk 52

53 crash occurs at this point
System recovery with disk-log 1. Scan the disk-log backwards; 2. Ignore T if see <T, commit>; 3. For each T with no <T, commit> For each log-record <T, A, aold> Undo the action by restoring the value of A back to aold; Add <T, abort> to disk-log. Undo-logging: Failure Recovery T: A  A  3 B  B  3 add-log: <T, start> read (A,t); t  t3; write (A,t); add-log: <T, A, 10> read (B,t); t  t3; write (B,t); add-log: <T, B, 10> flush-log output (A); output (B); add-log: <T, commit> CPU log A=10 B=10 C=30 A=30 <T, start> <T, A, 10> <T, B, 10> B=30 crash occurs at this point <T, start> <T, A, 10> <T, B, 10> memory disk 53

54 crash occurs at this point
System recovery with disk-log 1. Scan the disk-log backwards; 2. Ignore T if see <T, commit>; 3. For each T with no <T, commit> For each log-record <T, A, aold> Undo the action by restoring the value of A back to aold; Add <T, abort> to disk-log. Undo-logging: Failure Recovery T: A  A  3 B  B  3 add-log: <T, start> read (A,t); t  t3; write (A,t); add-log: <T, A, 10> read (B,t); t  t3; write (B,t); add-log: <T, B, 10> flush-log output (A); output (B); add-log: <T, commit> CPU log A=10 B=10 C=30 A=30 <T, start> <T, A, 10> <T, B, 10> B=30 crash occurs at this point <T, start> <T, A, 10> <T, B, 10> <T, abort> memory disk 54

55 Undo-logging: Failure Recovery
System recovery with disk-log 1. Scan the disk-log backwards; 2. Ignore T if see <T, commit>; 3. For each T with no <T, commit> For each log-record <T, A, aold> Undo the action by restoring the value of A back to aold; Add <T, abort> to disk-log. Undo-logging: Failure Recovery T: A  A  3 B  B  3 add-log: <T, start> read (A,t); t  t3; write (A,t); add-log: <T, A, 10> read (B,t); t  t3; write (B,t); add-log: <T, B, 10> flush-log output (A); output (B); add-log: <T, commit> CPU log A=10 B=10 C=30 A=30 <T, start> <T, A, 10> <T, B, 10> B=30 crash occurs before this point memory disk 55

56 Undo-logging: Failure Recovery
System recovery with disk-log 1. Scan the disk-log backwards; 2. Ignore T if see <T, commit>; 3. For each T with no <T, commit> For each log-record <T, A, aold> Undo the action by restoring the value of A back to aold; Add <T, abort> to disk-log. Undo-logging: Failure Recovery T: A  A  3 B  B  3 add-log: <T, start> read (A,t); t  t3; write (A,t); add-log: <T, A, 10> read (B,t); t  t3; write (B,t); add-log: <T, B, 10> flush-log output (A); output (B); add-log: <T, commit> CPU log A=10 B=10 C=30 A=30 <T, start> <T, A, 10> <T, B, 10> B=30 crash occurs before this point <T, start> <T, A, 10> memory disk 56

57 Undo-logging: Failure Recovery
System recovery with disk-log 1. Scan the disk-log backwards; 2. Ignore T if see <T, commit>; 3. For each T with no <T, commit> For each log-record <T, A, aold> Undo the action by restoring the value of A back to aold; Add <T, abort> to disk-log. Undo-logging: Failure Recovery T: A  A  3 B  B  3 add-log: <T, start> read (A,t); t  t3; write (A,t); add-log: <T, A, 10> read (B,t); t  t3; write (B,t); add-log: <T, B, 10> flush-log output (A); output (B); add-log: <T, commit> CPU A=10 B=10 C=30 crash occurs before this point <T, start> <T, A, 10> memory disk 57

58 Undo-logging: Failure Recovery
System recovery with disk-log 1. Scan the disk-log backwards; 2. Ignore T if see <T, commit>; 3. For each T with no <T, commit> For each log-record <T, A, aold> Undo the action by restoring the value of A back to aold; Add <T, abort> to disk-log. Undo-logging: Failure Recovery T: A  A  3 B  B  3 add-log: <T, start> read (A,t); t  t3; write (A,t); add-log: <T, A, 10> read (B,t); t  t3; write (B,t); add-log: <T, B, 10> flush-log output (A); output (B); add-log: <T, commit> CPU A=10 B=10 C=30 crash occurs before this point <T, start> <T, A, 10> memory disk 58

59 Undo-logging: Failure Recovery
System recovery with disk-log 1. Scan the disk-log backwards; 2. Ignore T if see <T, commit>; 3. For each T with no <T, commit> For each log-record <T, A, aold> Undo the action by restoring the value of A back to aold; Add <T, abort> to disk-log. Undo-logging: Failure Recovery T: A  A  3 B  B  3 add-log: <T, start> read (A,t); t  t3; write (A,t); add-log: <T, A, 10> read (B,t); t  t3; write (B,t); add-log: <T, B, 10> flush-log output (A); output (B); add-log: <T, commit> CPU A=10 B=10 C=30 crash occurs before this point <T, start> <T, A, 10> <T, abort> memory disk 59

60 Undo-logging: Failure Recovery
System recovery with disk-log 1. Scan the disk-log backwards; 2. Ignore T if see <T, commit>; 3. For each T with no <T, commit> For each log-record <T, A, aold> Undo the action by restoring the value of A back to aold; Add <T, abort> to disk-log. Undo-logging: Failure Recovery Remarks: To execute the recovery algorithm, we need to 60

61 Undo-logging: Failure Recovery
System recovery with disk-log 1. Scan the disk-log backwards; 2. Ignore T if see <T, commit>; 3. For each T with no <T, commit> For each log-record <T, A, aold> Undo the action by restoring the value of A back to aold; Add <T, abort> to disk-log. Undo-logging: Failure Recovery Remarks: To execute the recovery algorithm, we need to A.1 Read the disk-log into the main memory; 61

62 Undo-logging: Failure Recovery
System recovery with disk-log 1. Scan the disk-log backwards; 2. Ignore T if see <T, commit>; 3. For each T with no <T, commit> For each log-record <T, A, aold> Undo the action by restoring the value of A back to aold; Add <T, abort> to disk-log. Undo-logging: Failure Recovery Remarks: To execute the recovery algorithm, we need to A.1 Read the disk-log into the main memory; A.2 FOR each <T, A, aold> in step 3 DO write(A, aold); output(A); 62

63 Undo-logging: Failure Recovery
System recovery with disk-log 1. Scan the disk-log backwards; 2. Ignore T if see <T, commit>; 3. For each T with no <T, commit> For each log-record <T, A, aold> Undo the action by restoring the value of A back to aold; Add <T, abort> to disk-log. Undo-logging: Failure Recovery Remarks: To execute the recovery algorithm, we need to A.1 Read the disk-log into the main memory; A.2 FOR each <T, A, aold> in step 3 DO write(A, aold); output(A); What if the system crashes again during Undo? 63

64 Undo-logging: Failure Recovery
System recovery with disk-log 1. Scan the disk-log backwards; 2. Ignore T if see <T, commit>; 3. For each T with no <T, commit> For each log-record <T, A, aold> Undo the action by restoring the value of A back to aold; Add <T, abort> to disk-log. Undo-logging: Failure Recovery Remarks: To execute the recovery algorithm, we need to A.1 Read the disk-log into the main memory; A.2 FOR each <T, A, aold> in step 3 DO write(A, aold); output(A); What if the system crashes again during Undo? * The disk-log remains; 64

65 Undo-logging: Failure Recovery
System recovery with disk-log 1. Scan the disk-log backwards; 2. Ignore T if see <T, commit>; 3. For each T with no <T, commit> For each log-record <T, A, aold> Undo the action by restoring the value of A back to aold; Add <T, abort> to disk-log. Undo-logging: Failure Recovery Remarks: To execute the recovery algorithm, we need to A.1 Read the disk-log into the main memory; A.2 FOR each <T, A, aold> in step 3 DO write(A, aold); output(A); What if the system crashes again during Undo? * The disk-log remains; * We can simply repeat steps A.1 and A.2; 65

66 Undo-logging: Failure Recovery
System recovery with disk-log 1. Scan the disk-log backwards; 2. Ignore T if see <T, commit>; 3. For each T with no <T, commit> For each log-record <T, A, aold> Undo the action by restoring the value of A back to aold; Add <T, abort> to disk-log. Undo-logging: Failure Recovery Remarks: To execute the recovery algorithm, we need to A.1 Read the disk-log into the main memory; A.2 FOR each <T, A, aold> in step 3 DO write(A, aold); output(A); What if the system crashes again during Undo? * The disk-log remains; * We can simply repeat steps A.1 and A.2; * Some <T, A, aold> may have been undone in step 3 before the second crash, but re-Undo them would not hurt. 66

67 crash occurs at this point
System recovery with disk-log 1. Scan the disk-log backwards; 2. Ignore T if see <T, commit>; 3. For each T with no <T, commit> For each log-record <T, A, aold> Undo the action by restoring the value of A back to aold; Add <T, abort> to disk-log. Undo-logging: Failure Recovery T: A  A  3 B  B  3 add-log: <T, start> read (A,t); t  t3; write (A,t); add-log: <T, A, 10> read (B,t); t  t3; write (B,t); add-log: <T, B, 10> flush-log output (A); output (B); add-log: <T, commit> CPU log A=30 B=30 C=30 A=30 <T, start> <T, A, 10> <T, B, 10> B=30 <T, start> <T, A, 10> <T, B, 10> crash occurs at this point memory disk 67

68 crash occurs at this point
System recovery with disk-log 1. Scan the disk-log backwards; 2. Ignore T if see <T, commit>; 3. For each T with no <T, commit> For each log-record <T, A, aold> Undo the action by restoring the value of A back to aold; Add <T, abort> to disk-log. Undo-logging: Failure Recovery T: A  A  3 B  B  3 add-log: <T, start> read (A,t); t  t3; write (A,t); add-log: <T, A, 10> read (B,t); t  t3; write (B,t); add-log: <T, B, 10> flush-log output (A); output (B); add-log: <T, commit> CPU A=30 B=30 C=30 <T, start> <T, A, 10> <T, B, 10> crash occurs at this point memory disk 68

69 crash occurs at this point
System recovery with disk-log 1. Scan the disk-log backwards; 2. Ignore T if see <T, commit>; 3. For each T with no <T, commit> For each log-record <T, A, aold> Undo the action by restoring the value of A back to aold; Add <T, abort> to disk-log. Undo-logging: Failure Recovery T: A  A  3 B  B  3 add-log: <T, start> read (A,t); t  t3; write (A,t); add-log: <T, A, 10> read (B,t); t  t3; write (B,t); add-log: <T, B, 10> flush-log output (A); output (B); add-log: <T, commit> CPU A=30 B=30 C=30 <T, start> <T, A, 10> <T, B, 10> <T, start> <T, A, 10> <T, B, 10> crash occurs at this point memory disk 69

70 crash occurs at this point
System recovery with disk-log 1. Scan the disk-log backwards; 2. Ignore T if see <T, commit>; 3. For each T with no <T, commit> For each log-record <T, A, aold> Undo the action by restoring the value of A back to aold; Add <T, abort> to disk-log. Undo-logging: Failure Recovery T: A  A  3 B  B  3 add-log: <T, start> read (A,t); t  t3; write (A,t); add-log: <T, A, 10> read (B,t); t  t3; write (B,t); add-log: <T, B, 10> flush-log output (A); output (B); add-log: <T, commit> CPU A=30 B=10 C=30 <T, start> <T, A, 10> <T, B, 10> <T, start> <T, A, 10> <T, B, 10> crash occurs at this point memory disk 70

71 crash occurs at this point
System recovery with disk-log 1. Scan the disk-log backwards; 2. Ignore T if see <T, commit>; 3. For each T with no <T, commit> For each log-record <T, A, aold> Undo the action by restoring the value of A back to aold; Add <T, abort> to disk-log. Undo-logging: Failure Recovery T: A  A  3 B  B  3 add-log: <T, start> read (A,t); t  t3; write (A,t); add-log: <T, A, 10> read (B,t); t  t3; write (B,t); add-log: <T, B, 10> flush-log output (A); output (B); add-log: <T, commit> CPU A=30 B=10 C=30 <T, start> <T, A, 10> <T, B, 10> crash occurs at this point memory disk 71

72 crash occurs at this point
System recovery with disk-log 1. Scan the disk-log backwards; 2. Ignore T if see <T, commit>; 3. For each T with no <T, commit> For each log-record <T, A, aold> Undo the action by restoring the value of A back to aold; Add <T, abort> to disk-log. Undo-logging: Failure Recovery T: A  A  3 B  B  3 add-log: <T, start> read (A,t); t  t3; write (A,t); add-log: <T, A, 10> read (B,t); t  t3; write (B,t); add-log: <T, B, 10> flush-log output (A); output (B); add-log: <T, commit> CPU A=30 B=10 C=30 <T, start> <T, A, 10> <T, B, 10> <T, start> <T, A, 10> <T, B, 10> crash occurs at this point memory disk 72

73 crash occurs at this point
System recovery with disk-log 1. Scan the disk-log backwards; 2. Ignore T if see <T, commit>; 3. For each T with no <T, commit> For each log-record <T, A, aold> Undo the action by restoring the value of A back to aold; Add <T, abort> to disk-log. Undo-logging: Failure Recovery T: A  A  3 B  B  3 add-log: <T, start> read (A,t); t  t3; write (A,t); add-log: <T, A, 10> read (B,t); t  t3; write (B,t); add-log: <T, B, 10> flush-log output (A); output (B); add-log: <T, commit> CPU A=10 B=10 C=30 <T, start> <T, A, 10> <T, B, 10> <T, start> <T, A, 10> <T, B, 10> <T, abort> crash occurs at this point memory disk 73


Download ppt "CPSC-608 Database Systems"

Similar presentations


Ads by Google