CPSC-608 Database Systems Fall 2018 Instructor: Jianer Chen Office: HRBB 315C Phone: 845-4259 Email: chen@cse.tamu.edu Notes #33
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
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.
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
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
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
Computational Model CPU T1: A A 3 B B 3 read (A,t); t t3; write (A,t); read (B,t); t t3; 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
Computational Model CPU T1: A A 3 B B 3 read (A,t); t t3; write (A,t); read (B,t); t t3; 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
Computational Model CPU T1: A A 3 B B 3 read (A,t); t t3; write (A,t); read (B,t); t t3; 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
Computational Model CPU T1: A A 3 B B 3 read (A,t); t t3; write (A,t); read (B,t); t t3; 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
Computational Model CPU T1: A A 3 B B 3 read (A,t); t t3; write (A,t); read (B,t); t t3; 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
When should log be copied to disk? Computational Model T1: A A 3 B B 3 read (A,t); t t3; write (A,t); read (B,t); t t3; 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
Computational Model CPU T1: A A 3 B B 3 read (A,t); t t3; write (A,t); read (B,t); t t3; 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
Computational Model CPU T1: A A 3 B B 3 read (A,t); t t3; write (A,t); read (B,t); t t3; 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
Computational Model CPU T1: A A 3 B B 3 read (A,t); t t3; write (A,t); read (B,t); t t3; 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
Computational Model CPU T1: A A 3 B B 3 read (A,t); t t3; write (A,t); read (B,t); t t3; 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
When should log be copied to disk? Computational Model T1: A A 3 B B 3 read (A,t); t t3; write (A,t); read (B,t); t t3; 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
When should log be copied to disk? Computational Model T1: A A 3 B B 3 read (A,t); t t3; write (A,t); read (B,t); t t3; 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
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
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
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
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
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.
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.
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
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.
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.
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.
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.
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.
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.
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.
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 t3; write (A,t); read (B,t); t t3; write (B,t); output (A); output (B); CPU A=10 B=10 C=30 memory disk 33
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 t3; write (A,t); add-log: <T, A, 10> flush-log output (A); read (B,t); t t3; write (B,t); add-log: <T, B, 10> output (B); add-log: <T, commit> CPU A=10 B=10 C=30 memory disk 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 t3; write (A,t); add-log: <T, A, 10> read (B,t); t t3; 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
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 t3; write (A,t); add-log: <T, A, 10> read (B,t); t t3; 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
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 t3; write (A,t); add-log: <T, A, 10> read (B,t); t t3; 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
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 t3; write (A,t); add-log: <T, A, 10> read (B,t); t t3; 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
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 t3; write (A,t); add-log: <T, A, 10> read (B,t); t t3; 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
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 t3; write (A,t); add-log: <T, A, 10> read (B,t); t t3; 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
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 t3; write (A,t); add-log: <T, A, 10> read (B,t); t t3; 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
Undo-logging: Failure Recovery CPU A=10 B=10 C=30 memory disk 42
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 t3; write (A,t); add-log: <T, A, 10> read (B,t); t t3; 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
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 t3; write (A,t); add-log: <T, A, 10> read (B,t); t t3; 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
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 t3; write (A,t); add-log: <T, A, 10> read (B,t); t t3; 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
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 t3; write (A,t); add-log: <T, A, 10> read (B,t); t t3; 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
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 t3; write (A,t); add-log: <T, A, 10> read (B,t); t t3; 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
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 t3; write (A,t); add-log: <T, A, 10> read (B,t); t t3; 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
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 t3; write (A,t); add-log: <T, A, 10> read (B,t); t t3; 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
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 t3; write (A,t); add-log: <T, A, 10> read (B,t); t t3; 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
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 t3; write (A,t); add-log: <T, A, 10> read (B,t); t t3; 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
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 t3; write (A,t); add-log: <T, A, 10> read (B,t); t t3; 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
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 t3; write (A,t); add-log: <T, A, 10> read (B,t); t t3; 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
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 t3; write (A,t); add-log: <T, A, 10> read (B,t); t t3; 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
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 t3; write (A,t); add-log: <T, A, 10> read (B,t); t t3; 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
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 t3; write (A,t); add-log: <T, A, 10> read (B,t); t t3; 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
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 t3; write (A,t); add-log: <T, A, 10> read (B,t); t t3; 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
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 t3; write (A,t); add-log: <T, A, 10> read (B,t); t t3; 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
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 t3; write (A,t); add-log: <T, A, 10> read (B,t); t t3; 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
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
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
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
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
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
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
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
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 t3; write (A,t); add-log: <T, A, 10> read (B,t); t t3; 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
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 t3; write (A,t); add-log: <T, A, 10> read (B,t); t t3; 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
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 t3; write (A,t); add-log: <T, A, 10> read (B,t); t t3; 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
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 t3; write (A,t); add-log: <T, A, 10> read (B,t); t t3; 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
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 t3; write (A,t); add-log: <T, A, 10> read (B,t); t t3; 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
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 t3; write (A,t); add-log: <T, A, 10> read (B,t); t t3; 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
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 t3; write (A,t); add-log: <T, A, 10> read (B,t); t t3; 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