24
1 Recovery Control (Chapter 17) Redo Logging CS4432: Database Systems II

Recovery Control (Chapter 17) Redo Logging

Embed Size (px)

DESCRIPTION

CS4432: Database Systems II. Recovery Control (Chapter 17) Redo Logging. Disadvantage of Undo Logging. This forces the DBMS to make many I/ Os Especially for small transactions. Cannot consider T committed and write this log rec until all T ’ s updates are written to disk. - PowerPoint PPT Presentation

Citation preview

Page 1: Recovery Control (Chapter 17) Redo Logging

1

Recovery Control (Chapter 17)Redo Logging

CS4432: Database Systems II

Page 2: Recovery Control (Chapter 17) Redo Logging

Disadvantage of Undo Logging

• This forces the DBMS to make many I/Os– Especially for small transactions

2

Cannot consider T committed and write this log rec until all T’s updates are written to disk

Page 3: Recovery Control (Chapter 17) Redo Logging

Rules for Redo Logging

3

• For every write action, generate redo log record.

– <T, X, v>: Transaction T has modified X and new value is v

• Flush log at commit.

• Before modifying any value X on disk (Output(X))

– All log records of T (including commit) must be on disk

before X is modified on disk

• Write <END T> log record after DB modifications have

been written to disk.

Page 4: Recovery Control (Chapter 17) Redo Logging

Example

4

That is the new value

No Output can be done until the Log is flushed to disk containing all T’s records and its <Commit T>

Page 5: Recovery Control (Chapter 17) Redo Logging

Redo Logging: Recovery Rules

Check the log•T with no <Commit T>

– Can be ignored (do nothing)– Because T did not write anything to disk

•T with <End T>– Can be ignored (do nothing)– Because T wrote all its data to disk

•T with <Commit T> but no <End T>– Redo its actions (Start from <Start T> and move forward)

5

Page 6: Recovery Control (Chapter 17) Redo Logging

Example

6

<Commit T> is not written on disk yetDo Nothing

Page 7: Recovery Control (Chapter 17) Redo Logging

Example

7

<Commit T> is on disk, No <End T>Redo T

Copy 16 to A Copy 16 to B

Add <End T> to log and write to disk

Page 8: Recovery Control (Chapter 17) Redo Logging

Disadvantage of Redo Logging

• Delayed I/Os– Needs to keep all modified blocks in memory until T commits

• Bad especially for large transactions

8

Cannot write anything of T’s updates to disk until it commits.

Page 9: Recovery Control (Chapter 17) Redo Logging

9

Next: Undo/Redo Logging & Checkpoints

Page 10: Recovery Control (Chapter 17) Redo Logging

Undo/Redo Logging

• Stores more data in its log to offer more flexibility – Log record: <Ti, X, oldVal, newVal>

10

Transation Ti has updated X, the old value is oldVal and the new value is newVal

• In Recovery– Some transactions will be undone (incomplete ones)– Some transactions will be redone (complete ones)

Page 11: Recovery Control (Chapter 17) Redo Logging

Undo/Redo Logging

• For every write action, generate log record.

– <T, X, old, new>: Transaction T has modified X from old to new

• Before writing any object X to disk (Output(x)), its log

record must be on disk

11

Yes

Yes

A block containing X can now move to disk either before or after the commit

Page 12: Recovery Control (Chapter 17) Redo Logging

Example

12

At this point it is allowed to write either A or B to disk

At this point T is considered completed although some of its data are not written yet to disk

Page 13: Recovery Control (Chapter 17) Redo Logging

Undo/Redo Logging: Recovery Rules

• If <Commit T> is in the log (on disk)– It means T is be completed– Some data may be written to disk, others may not

• If <Commit T> is not in the log (not on disk)– Still some data may be written to disk

13

Redo T (top-down)

Undo T (bottom-up)

Page 14: Recovery Control (Chapter 17) Redo Logging

14

Redo Phase1.Decide on which transactions to redo (can be many)2.Take one forward pass (top-down) and redo them

Undo/Redo Logging: Recovery Rules

Undo Phase1.Decide on which transactions to undo (can be many)2.Take one backward pass (bottom-up) to undo them

Page 15: Recovery Control (Chapter 17) Redo Logging

15

Example

<START T1>

<T1,X1,u1,v1>

<START T2>

<T2, X2,u2,v2>

<START T3>

<T1,X3,u3,v3>

<COMMIT T2>

<T3,X4,u4,v4>

<T1,X5,u5,v5>

crash

Redo T2 Undo T1, T3

Log on disk

Page 16: Recovery Control (Chapter 17) Redo Logging

Example

16

• The <Commit T> record is not written yet to disk• T is considered incomplete and will be undone

- Return B to 8- Return A to 8

Page 17: Recovery Control (Chapter 17) Redo Logging

Example

17

• The <Commit T> record is on disk• T is considered complete and will be redone

- Copy 16 to A- Copy 16 to B

Page 18: Recovery Control (Chapter 17) Redo Logging

18

Recovery Control (Chapter 17)Checkpointing

CS4432: Database Systems II

Page 19: Recovery Control (Chapter 17) Redo Logging

Checkpointing• When restart from a crash

– Recovery Manager needs to check the entire log to decide• Which Trnx to undo (if Undo logging)• Which Trnx to redo (if Redo logging)• Which Trnx ro undo/redo (if Undo/Redo logging)

• Checking the entire log is very expensive

• Need points before which everything is guaranteed to be correct – These points are called “checkpoints”

19

Page 20: Recovery Control (Chapter 17) Redo Logging

20

Recovery is very, very SLOW !

log:

First T1 wrote A,B LastRecord Committed a year ago Record(1 year ago) --> STILL, Need to redo after crash!!

... ... ...

Crash

Page 21: Recovery Control (Chapter 17) Redo Logging

2121

Solution: Checkpoint Periodically:(1) Do not accept new transactions(2) Wait until all transactions finish (commit or

abort)(3) Flush all log records to disk (log)(4) Flush all buffers to disk (DB)

(5) Write “checkpoint” record on disk (log)(6) Resume transaction processing

•simple checkpoint

Page 22: Recovery Control (Chapter 17) Redo Logging

2222

Example: what to do at recovery?

Undo or Redo log (disk):

<T1

,A,1

6>

<T1

,com

mit

>

Ch

eck

poin

t

<T2

,B,1

7>

<T2

,com

mit

>

<T3

,C,2

1>

Crash... ... ... ...

...

...

Check only to the last checkpoint

Page 23: Recovery Control (Chapter 17) Redo Logging

23

More Complex Checkpointing Mechanism

• The simple mechanism does not accept new transactions during checkpointing

• May not be acceptable for some systems

• A more complex mechanism allows accepting new transactions while doing the checkpointing

Page 24: Recovery Control (Chapter 17) Redo Logging

We Are Done…