Docsity

Log-Based Recovery: Implementation and Optimization, Slides of Fundamentals of E-Commerce

Toggle sidebar
bg1
3. Log-based Recovery
•Logging is the most popular mechanism for
implementing recovery algorithms.
•The recovery manager implements
–Commit - by writing a commit record to the log and
flushing the log (satisfies the Redo Rule)
–Abort - by using the transaction’s log records to restore
before-images
–Restart - by scanning the log and undoing and redoing
operations as necessary
•The algorithms are fast since they use sequential log
I/O in place of random database I/O. They greatly
affect TP and Restart performance.
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Log-Based Recovery: Implementation and Optimization and more Slides Fundamentals of E-Commerce in PDF only on Docsity!

3. Log-based Recovery

-^

Logging is the most popular mechanism forimplementing recovery algorithms.

-^

The recovery manager implements^ –

Commit - by writing a commit record to the log and^ flushing the log (satisfies the Redo Rule)

Abort - by using the transaction’s log records to restorebefore-images

Restart - by scanning the log and undoing and redoingoperations as necessary

-^

The algorithms are fast since they use sequential logI/O in place of random database I/O. They greatlyaffect TP and Restart performance.

Implementing Commit

-^

Every commit requires a log flush.

-^

If you can do

K

log flushes per second, then

K

is

your maximum transaction throughput

-^

Group Commit Optimization - when processingcommit, if the last log page isn’t full, delay theflush to give it time to fill

-^

If there are multiple data managers on a system,then each data mgr must flush its log to commit^ –

If each data mgr isn’t using its log’s update bandwidth,then a shared log saves log flushes

A good idea, but rarely supported commercially

Satisfying the Undo Rule

•^

To implement the Write-Ahead Log Protocol, tag eachcache slot with the log sequence number (LSN) of the lastupdate record to that slot’s page. Page

Dirty

Cache

Pin

LSN

Bit

Address

Count

P

47

P

21

Log Start^ End

On diskMainMemory

•^

Cache manager won’t flush a page P until P’s last updatedrecord, pointed to by LSN, is on disk.

-^

P’s last log record is usually stable before Flush(P),so this rarely costs an extra flush

-^

LSN must be updated while latch is held on P’s slot

Implementing Restart (rev 1)

-^

Assume undo and redo are required

-^

Scan the log backwards, starting at the end.^ –

How do you find the end?

-^

Construct a commit list and recovered-page-listduring the scan (assuming page level logging)

-^

Commit(T) record => add T to commit list

-^

Update record for P by T^ –

if P is not in the recovered-page-list then

•^

add P to the recovered-page-list

-^

if T is in the commit list, then redo the update,else undo the update

Restart Algorithm (rev 2)

-^

No need to redo records before last checkpoint, so^ –

Starting with the last checkpoint, scan forward in thelog.

Redo all update records. Process all aborts.^ Maintain list of active transactions (initialized to contentof checkpoint record).

After you’re done scanning, abort all active transactions

-^

Restart time is proportional to the amount of logafter the last checkpoint.

-^

Reduce restart time by checkpointing frequently.

-^

Thus, checkpointing must be cheap.

Fuzzy Checkpointing

•^

Make checkpoints cheap by avoiding synchronized flushingof dirty cache at checkpoint time.^ –

Stop accepting new update, commit, and abortoperations

Make a list of all dirty pages in cache

Make list of [active transaction, pointer to last logrecord]

Append a checkpoint record to log; include the list

Resume normal processing

Initiate low priority flush of all dirty pages

-^

Don’t checkpoint again until all of the last checkpoint’sdirty pages are flushed

-^

Restart begins at second

  • to
  • last (penultimate) checkpoint.

LSN-based logging

•^

Each database page P’s header has the LSN of the last logrecord whose operation updated P.

-^

Restart compares log record and page LSN before redoingthe log record’s update U.^ –

Redo the update only if LSN(P) < LSN(U)

-^

Undo is a problem. If U’s transaction aborts and you undoU, what LSN to put on the page?^ –

Suppose T

1

and T

2

update records x and y on P

w

[x] w 1

[y] c 2

2

a^1

(what LSN does a

1

put on P?)

not LSN before w

[x] (which says w 1

[y] didn’t run) 2

not w

[y] (which says w 2

[x] wasn’t aborted) 1