CS411 - Transaction Management - Note 1

T reatat 8 8 8 8 tt2 16 8 8 8 writeat 16 16 8 8

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: rrectness Principle • There exists a notion of correctness for the database • Explicit constraints (e.g. foreign keys) • Implicit conditions (e.g. sum of sales = sum of invoices) • Correctness principle: Transaction will be programmed such that: if a transaction starts in a correct database state, it ends in a correct database state. • Consequence: we only need to guarantee that transactions are atomic, and run (as if) in isolation. Recovery (5 of 8) Transaction Management (29 of 61) Primitive Operations of Transactions • INPUT(X) • read element X to memory buffer • READ(X,t) • copy element X to transaction local variable t • WRITE(X,t) • copy transaction local variable t to element X • OUTPUT(X) • write element X to disk Recovery (6 of 8) Transaction Management (30 of 61) Example READ(A,t); t := t*2; WRITE(A,t); READ(B,t); t := t*2; WRITE(B,t) Action t Mem A Disk A Disk B 8 INPUT(A) Mem B 8 8 READ(A,t) 8 8 8 8 t:=t*2 16 8 8 8 WRITE(A,t) 16 16 8 8 INPUT(B) 16 16 8 8 8 READ(B,t) 8 16 8 8 8 t:=t*2 16 16 8 8 8 WRITE(B,t) 16 16 16 8 8 OUTPUT(A) 16 16 16 16 8 OUTPUT(B) 16 16 16 16 16 Recovery (7 of 8) Transaction Management (31 of 61) The Log • An append- only file containing log records • Note: multiple transactions run concurrently, log records are interleaved • After a system crash, use log to: • Redo some transaction that did commit. • Undo other transactions that did not commit. Recovery (8 of 8) Transaction Management (32 of 61) Undo Logging Undo Logging (0 of 13) Transaction Management (33 of 61) Undo Logging Log records • <START T> • transaction T has begun • <COMMIT T> • T has committed • <ABORT T> • T has aborted • <T,X,v> • T has updated element X, and its old value was v Undo Logging (1 of 13) Transaction Management (34 of 61) Undo- Logging Rules U1: If T modifies X, then <T,X,v> entry must be written to log before X is written to disk U2: If T commits, then <COMMIT T> entry must be written to log only after all changes by T are written to disk • Hence: OUTPUTs are done early (before commit) Undo Logging (2 of 13) Transaction Management (35 of 61) Action T Mem A Mem B Disk A Disk B Log <START T> REAT(A,t) 8 8 8 8 t:=t*2 16 8 8 8 WRITE(A,t) 16 16 8 8 READ(B,t) 8 16 8 8 8 t:=t*2 16 16 8 8 8 WRITE(B,t) 16 16 16 8 8 OUTPUT(A) 16 16 16 16 8 OUTPUT(B) 16 16 16 16 <T,A,8> 16 <T,B,8> <COMMIT T> Undo Logging (3 of 13) Transaction Management (36 of 61) Recovery with Undo Log After system’s crash, run recovery manager • Idea 1. Decide for each transaction T whether it is completed or not • <START T>….<COMMIT T>…. = yes • <START T>….<ABORT T>……. = yes • <START T>……………………… = no • Idea 2. Undo all modifications by incompleted transactions Undo...
View Full Document

Ask a homework question - tutors are online