Docsity

Shadow Paging - E-Commerce - Lecture Slides, Slides of Fundamentals of E-Commerce

Toggle sidebar
bg1
1
1/11/05 1
2. Atom icity &
Durability Using
Shadow Paging
Tran saction Pro c essing
1
/
11
/
05 2
Introduction
•To get started on the Jav a-C# project, you need
to implem ent atom icity and durab ility in a
centralized resource manager (i.e. a database).
•The recom m ended approach is shadow ing.
•This section provides a quick introduction.
•A more thorough explanation of the overall topic
of database recovery will be presented in a
couple of w eeks.
1
/
11
/
05 3
Review of Atom icity & Durab ility
•Atom icity -a transaction is all-or-nothing
•Durability –the results of a co m m itted
transaction will survive failures
•Problem
–The on ly hardw are operation that is atom ic with
resp ect to failure and whose result is durable is
“write one disk block”
–But the database doesn’t fit on one disk block!
1
/
11
/
05 4
Shadow ing in a Nutsh ell
•The database is a tree whose rootis a single disk block
•There are two co pies of the tree, the master and shadow
•The root points to the master copy
•U pdates are applied to the sha d o w co py
•To install the updates, overwrite the root so it points to
the sh a do w , thereby sw apping the master and sh ad o w
–Before writing the root, none of the tran saction’s updates are
part of the disk -resident database
–After writing the root, all of the tran saction’s updates are part
of the disk -resident datab ase
–Which m eans the transaction is atom ic and durable
1
/
11
/
05 5
More Specifically …
•The databaseconsists of a set of files
•E ach file consists of a page table P and
a set of pagesthat P points to.
•A master page points to each file’s
master page table.
•A ssum e transactions run serially. I.e., at most
one transaction runs at any given time.
•A ssum e that for each page table the tran saction
has a private shadow co py in main-memory.
1
/
11
/
05 6
Initial State of Files a and b
Pt
T[a]
1
2
3
...
Pt
T[b]
1
2
3
...
a
b
P1a
Pt
1[a]
1
2
3
...
Pt
1[b]
1
2
3
...
P2a
P1b
P2b
Initial
State
D
I
S
K
Main
Memory
For T
Master
Docsity.com
pf3

Partial preview of the text

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

1/11/ 05 1

2.A tom icity &

D urability U sing

Shadow Paging

Transaction Processing

1/11/ 05 2

Introduction

  • To getstarted on the Java-C# project,you need

to im plem entatom icity and durability in a

centralized resource m anager(i.e.a database).

  • The recom m ended approach is shadowing.
  • This section provides a quick introduction.
  • A m ore thorough explanation ofthe overalltopic

ofdatabase recovery w illbe presented in a

couple ofw eeks.

1/11/ 05 3

Review ofA tom icity & D urability

  • A tom icity -a transaction is all-or-nothing
  • D urability – the results ofa com m itted

transaction w illsurvive failures

  • Problem
    • The only hardw are operation thatisatom ic w ith respectto failure and w hose resultis durable is “w rite one disk block”
    • Butthe database doesn’tfiton one disk block!

1/11/ 05 4

Shadow ing in a N utshell

  • The database is a tree w hose rootisa single disk block
  • There are tw o copies ofthe tree,the m asterand shadow
  • The rootpoints to the m astercopy
  • U pdates are applied to the shadow copy
  • To installthe updates,overw rite the rootso itpoints to the shadow ,thereby sw apping the m asterand shadow
  • Before w riting the root,none ofthe transaction’s updates are partofthe disk-residentdatabase
  • Afterw riting the root,allofthe transaction’s updatesare part ofthe disk-residentdatabase
  • W hich m eansthe transaction is atom ic and durable

1/11/ 05 5

M ore Specifically …

  • The databaseconsists ofa setoffiles
  • Each file consists ofa page tableP and

a setofpagesthatP points to.

  • A m aster pagepoints to each file’s

m aster page table.

  • A ssum e transactions run serially.I.e.,atm ost

one transaction runs atany given tim e.

  • A ssum e thatforeach page table the transaction

has a private shadow copy in m ain-m em ory.

1/11/ 05 6

InitialState ofFiles a and b

PtT [a] 1 2 3 ... PtT [b] 1 2 3 ...

a b

Pt 1 [a] P1a 1 2 3 ... Pt 1 [b] 1 2 3 ...

P2a

P1b

P2b

Initial

D State

I

S

K

M ain M em ory For T

M aster

2

1/11/ 05 7

To W rite a Page Pi

  • Transaction w rites a shadow copy ofpage Pi to

disk (i.e.does notoverw rite the m astercopy).

  • Transaction updates its page table to pointto

the shadow copy ofPi

  • Transaction m arks Pi’s entry in the page table

(to rem em berw hich pages w ere updated)

1/11/ 05 8

A fterW riting Page P2b

PtT [a] 1 2 3 ... PtT [b] 1 2 3 ...

a b

Pt 1 [a] P1a 1 2 3 ... Pt 1 [b] 1 2 3 ...

P2a

P1b

P2b O ld

Initial D State

I

S

K

M ain M em ory For T

M aster

P2b N ew

1/11/ 05 9

A fterW riting Page P1a

PtT [a] 1 2 3 ... PtT [b] 1 2 3 ...

a b

P1a O ld

Pt 1 [a] 1 2 3 ... Pt 1 [b] 1 2 3 ...

P2a

P1b

P2b O ld

Initial D State

I

S

K

M ain M em ory For T

M aster

P2b N ew

P1a N ew

1/11/ 05 10

W hatifthe System Fails?

  • M ain m em ory is lost
  • The currenttransaction is effectively aborted
  • Butthe database is stillconsistent

1/11/ 05 11

To Com m it

PtT [a] 1 2 3 ... PtT [b] 1 2 3 ...

a b

P1a O ld

Pt 1 [a] 1 2 3 ... Pt 1 [b] 1 2 3 ...

P2a

P1b

P2b O ld

Initial D State

I

S

K

M aster

P2b N ew

P1a N ew

1.Firstcopy PtT [a]and PtT[b]to disk

1/11/ 05 12

To Com m it(cont’d)

PtT [a] 1 2 3 ... PtT [b] 1 2 3 ...

a b

P1a O ld

Pt 1 [a] 1 2 3 ...

Pt 1 [b] 1 2 3 ...

P2a

P1b

P2b O ld

Initial D State

I

S

K

M aster

P2b N ew

P1a N ew

2.Then overw rite M asterto pointto the new Pt’s.