Docsity

The Log - E-Commerce - Lecture Slides, Slides of Fundamentals of E-Commerce

Toggle sidebar
bg1
The Log
•A sequential file of records describing updates:
–address of updated page
–id of transaction that did the update
–before-image and after-image of the page
•Whenever you update the cache, also update the
log
•Log records for Commit(Ti) and Abort(Ti)
•Some older systems separated before-images and
after-images into separate log files.
•If opi conflicts with and executes before opk, then
opi’s log record must precede opk’s log record
recovery will replay operations in log
-
record
-
order
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download The Log - E-Commerce - Lecture Slides and more Slides Fundamentals of E-Commerce in PDF only on Docsity!

The Log

A sequential file of records describing updates:^ –

address of updated page

id of transaction that did the update

before-image and after-image of the page

Whenever you update the cache, also update thelog

Log records for Commit(T

) and Abort(Ti

)i

Some older systems separated before-images andafter-images into separate log files.

If op

i^

conflicts with and executes before op

k

, then

op

’s log record must precede opi

k

’s log record

recovery will replay operations in log

  • record
  • order

The Log (cont’d)

To update records on a page:^ –

Fetch(P)

read P into cache

Pin(P)

ensure P isn’t flushed

write lock (P)

for two-phase locking

write latch (P)

get exclusive access to P

update P

update P in cache

log the update to P

append it to the log

unlatch (P)

release exclusive access

Unpin(P)

allow P to be flushed

Recovery Manager Model

Stable Database

Log

Read,Write

Pin, Unpin

Fetch Cache Manager

Cache

Read, Write

Recovery Manager

FlushDeallocate

Transaction 1

Transaction 2

Transaction

N

Commit, Abort, Restart

Read,Write

Flush, dealloc for normal operat’n Restart uses Fetch, Pin, Unpin

Implementing Abort(T)

Suppose T wrote page P.

If P was not transferred to stable storage,then deallocate its cache slot

If it was transferred, then P’s before-image must be in stable storage (else you couldn’t undo after asystem failure)

Undo Rule - Do not flush an uncommitted update of P until P’s before-image is stable. (Ensures undo ispossible.)^ –

Write-Ahead Log Protocol - Do not … until P’s^ before-image is in the log

Implementing Commit(T)

Commit must be atomic. So it must beimplemented by a disk write.

Suppose T wrote P, T committed, and then thesystem fails. P must be in stable storage.

Redo rule - Don’t commit a transaction until the after-images of all pages it wrote are in stablestorage (in the database or log). (Ensures redo ispossible.)^ –

Often called the Force-At-Commit rule

Avoiding Redo

To avoid redo, flush all of T’s updates to the stabledatabase before it commits. (They must be in stable storage.)^ –

Usually called a Force algorithm, because updates are^ forced to disk before commit.

It’s easy, because you don’t need stable bookkeeping ofafter-images

But it’s inefficient for hot pages. (Consider TPC-A/B.)

Conversely, a recovery algorithm requires redo if a transaction may commit before all of its updates arein the stable database.

Implementing Restart

To recover from a system failure^ –

Abort transactions that were active at the failure

For every committed transaction, redo updates that arein the log but not the stable database

Resume normal processing of transactions

Idempotent operation - many executions of the operation have the same effect as one execution

Restart must be idempotent. If it’s interrupted by afailure, then it re-executes from the beginning.

Restart contributes to unavailability. So make it fast!