Principles of Computer System Design Saltzer & Kaashoek 2009 

advertisement
Principles of Computer System Design  Saltzer & Kaashoek
2009
proc edureTRANSFER (deb it_ac co unt, cred it_ac co unt, amo unt)
GET dbd ata, de bit_a cc ount

dbd ata  dbd ata - amo unt
PUT (dbd ata, deb it_ac co unt
)
GET crda ta, cred it_ac co unt

crda ta crda ta + amo unt
PUT (crda ta, cred it_ac co unt
)
Principles of Computer System Design  Saltzer & Kaashoek
2009
Human use r
gen erati ng
requ ests
Interface
Typical instruction
across this interface
Calen dar m anag er
layer inte rface
Add new e ve nt o n
Feb ruary 27
Ja va lan guag e
layer inte rface
nextch = ins tring [j];
Calen dar
Progra m
Ja va
Interpreter
Mach ine lang uage
layer inte rface
add R1,R2
hard wa re
Principles of Computer System Design  Saltzer & Kaashoek
2009
All-or-nothing atomicity
A s e que nce of ste ps is an
all-or-nothing actionif, fr om the point of vie w of its
invoke r, the se que nce always e ithe r
completes
,
or
aborts in such a way that it appe ars that the se que nce had ne ve r be e n
unde rtake n in the first place . That bac
is, itks out.
Principles of Computer System Design  Saltzer & Kaashoek
2009
Before-or-after atomicity
Concurre nt actions hav
e thebefore-or-after property if their effect om
fr the point of
view of their inv
okers is the same as if the actions occurr
ed eithercompletely befor
e
or completely after
one another
.
Principles of Computer System Design  Saltzer & Kaashoek
2009
pr ocedureTRANSFER (r efer encede bit_a ccount, r efer encecre dit_a ccount, am ount)
de bit_a ccount de bit_a ccount- am ount
cre dit_a ccount cre dit_a ccount+ am ount
TRANSFER
(A, B, $1 0)
TRANSFER
(B, C, $2 5)
Principles of Computer System Design  Saltzer & Kaashoek
2009
Thre ad # 2 (deb it_ac co untis B)
2–1
R EAD B
.
.
.
2–2
WR ITE B
Thre ad # 1 (cred it_ac co untis B)
1–1
R EAD B
.
.
.
1–2
WR ITE B
co rrect resu lt:
ca se 1 : Thre ad # 1: R EAD B
Thre ad # 2:
Val ue o f B: 100
ca se 2 : Thre ad # 1:
Thre ad # 2: R EAD B
Val ue o f B: 100
wrong resul ts:
ca se 3 : Thre ad # 1: READ B
Thre ad # 2:
Val ue o f B: 100
ca se 4 : Thre ad # 1: READ B
Thre ad # 2:
Val ue o f B: 100
tim e
WRITE
B
READ
B
WR ITE
B
110
85
READ
WRITE
B
WR ITE
B
B
75
85
WRITE
REA D
B
B
WR ITE
B
110
R EAD
B
W RITE
75
WR ITE
B
B
75
ca se 5 : Thre ad # 1:
Thre ad # 2: REA D B
Val ue o f B: 100
REA D
ca se 6 : Thre ad # 1:
Thre ad # 2: REA D B
Val ue o f B: 100
R EAD
B
WR ITE
110
B
WR ITE
B
110
B
75
W RITE
W RITE
B
B
75
110
Principles of Computer System Design  Saltzer & Kaashoek
2009
ol d system
state
a cti on
ne w system
state
actio n #1
ol d system actio n #2
state
ne w system
state
actio n #3
Principles of Computer System Design  Saltzer & Kaashoek
2009
AA# 3
AA #2
AA
#1
fin al
sta te
A
AA# 3
AA
#2
old syste m
sta te
AA #2
AA# 3
AA# 1
fin al
sta te
B
fin al
sta te
C
Principles of Computer System Design  Saltzer & Kaashoek
2009
pr ocedureAUDIT ()
sum  0
for each W  in ba nk.acco unts
sum  sum + W.b alan ce
if (sum ° 0) call for inv estigatio n
// i n thread 2
// TRANSFER , in thread 1
de bit_a ccount de bit_a ccount - am ount
…
…
AUDIT
cre dit_a ccount cre dit_a ccount+ am ount
…
()
Principles of Computer System Design  Saltzer & Kaashoek
2009
Atomicity
An action isatomic if there is no way for a higher layer to discover the intern
structure of its implementation
.
Principles of Computer System Design  Saltzer & Kaashoek
2009
pr ocedureALMOST _ALL _OR_NOTHING _PUT (da ta, al l_or_n othin g_s ecto)r
C AR EFU L _PUT (da ta, al l_or_n othin g_s ecto.S1)
r
C AR EFU L _PUT (da ta, al l_or_n othin g_s ecto.S2)
r
// Co mmit p oint.
C AR EFU L _PUT (da ta, al l_or_n othin g_s ecto.S3)
r
pr ocedureALL _OR _NOTHING _GET (r efer enceda ta, al l_or_n othin g_s ecto)r
C AR EFU L _GET (da ta1, al l_or_n othin g_s ecto.S1
r )
C AR EFU L _GET (da ta2, al l_or_n othin g_s ecto.S2
r )
C AR EFU L _GET (da ta3, al l_or_n othin g_s ecto.S3
r )
if da ta1 = da ta2 then da ta  da ta1
// Return ne w v alue .
else da ta  da ta3
// Return ol d val ue.
Principles of Computer System Design  Saltzer & Kaashoek
2009
pr ocedureALL _OR _NOTHING _PUT (da ta, all_or_n othin g_s ecto)r
C HECK _AND _R EPAIR (all_or_n othin g_s ecto)r
ALMOST _ALL _OR_NOTHING _ PUT (da ta, all_or_n othin g_s ecto )r
pr ocedureC HECK _AND _R EPAIR (all_or_n othin g_s ecto)//
r Ens ure co pies matc h.
C AR EFUL _GET (da ta1, all_or_n othin g_s ecto.S1
r )
C AR EFUL _GET (da ta2, all_or_n othin g_s ecto.S2
r )
C AR EFUL _GET (da ta3, all_or_n othin g_s ecto.S3
r )
if (da ta1 = da ta2) and (da ta2 = da ta3) r etur n // State 1 o r 7 , no repa ir
if (da ta1 = da ta2)
C AR EFUL _PUT (da ta1, all_or_n othin g_s ecto.S3
r ) r etur n // State 5 o r 6 .
if (da ta2 = da ta3)
C AR EFUL _PUT (da ta2, all_or_n othin g_s ecto.S1
r ) r etur n // State 2 o r 3 .
C AR EFUL _PUT (da ta1, all_or_n othin g_s ecto.S2)
r
// State 4, g o to s tate 5
C AR EFUL _PUT (da ta1, all_or_n othin g_s ecto.S3)
r
// State 5, g o to s tate 7
da ta sta te:
s ecto r S1
s ecto r S2
s ecto r S3
1
ol d
ol d
ol d
2
ba d
ol d
ol d
3
ne w
ol d
ol d
4
ne w
ba d
ol d
5
ne w
ne w
ol d
6
ne w
ne w
ba d
7
ne w
ne w
ne w
Principles of Computer System Design  Saltzer & Kaashoek
2009
__ _
__ _
__ _
begin all- or- nothing ac tion
__ _
__ _
__ _
arbi tra ry seq uenc e of
__ _
lo we r-la yer ac tions
__ _
end all- or- nothing ac tion
__ _
__ _
__ _
}
Principles of Computer System Design  Saltzer & Kaashoek
2009
__ _
__ _
__ _
__ _
__ _
__ _
__ _
__ _
__ _
__ _
__ _
__ _
__ _
firs t step of all-o r-no thing action
}
Pr e-commit disc ipline
: ca n bac k ou t,
le avin g no trac e
Com m it p oint
}
Post- commit discipline
: co mple tion is in evita ble
la st s tep of a ll-or-nothing ac tion
Principles of Computer System Design  Saltzer & Kaashoek
2009
The golden rule of atomicity
Nev er modify the o nly copy !
Principles of Computer System Design  Saltzer & Kaashoek
2009
Va riabl e A:
7
20
5
29
History of earli er versi ons
11 2
14
16
Te ntative
ne xt versio n
Curren t versi on
Principles of Computer System Design  Saltzer & Kaashoek
2009
All -or-nothing Jo urnal Stora ge System
NEW_A CTION
REA D
Cell Storag e
System
R EAD _C UR RENT _VA LU E
W RITE
WR ITE _NEW _VA LU E
Jo urnal
Stora ge
Manag er
– cata logs
AL LOC ATE
COM MIT
DEAL L OCATE
– vers ions
– o utcome
records
AB ORT
Principles of Computer System Design  Saltzer & Kaashoek
2009
al l-or-no thin g
actio n
commi ts
no n-existent
commi tted
pe ndin g
ne w all-o r-noth ing
actio n is
create d
al l-or-no thin g
actio n
ab orts
di sca rded
ab orted
ou tco me re cord
state no l onge r
of any i ntere st
Principles of Computer System Design  Saltzer & Kaashoek
2009
pr ocedureNEW _ACTION ()
id  NEW _OUTCOME _R EC OR D ()
id .outc ome_ re cord.s tate PENDING
r etur n id
pr ocedureC OMM IT (r efer enceid)
id .outc ome_ re cord.s tate C OMM ITTED
pr ocedureABOR T (r efer enceid)
id .outc ome_ re cord.s tate ABOR TED
Principles of Computer System Design  Saltzer & Kaashoek
2009
Object A
value :
7
all -or-nothing 03
action id:
110 1:
co mmitted
24
15
110 1
142 3
142 3:
abo rted
75
179 4
179 4:
pen ding
outcom e
records
Principles of Computer System Design  Saltzer & Kaashoek
2009
pr ocedureR EAD _C UR RENT _VALUE (da ta_id , caller_id)
star ting at end of
da ta_id r epeat until beginning
v  pr eviousve rs ion of da ta_id
// Ge t next o lder ve rs ion
a v.a ctio n_id // Id entify the ac tiona tha t create d it
s  a.o utco me_rec ord.s tate
// Ch eck acti ona’s outc ome re cord
if s = C OMM ITTED then
r etur n v.va lue
else skip v
// Co ntinu e bac kward s earch
signal (“Tried to re ad an unin itial ize d varia ble!”)
pr ocedureWR ITE _NEW _VALUE (r efer enceda ta_id, ne w_ valu e, ca ller_id
)
if c alle r_ id.ou tcom e_rec ord
.s tate = PENDING
append new version
v to da ta_id
v.v alue  ne w_ valu e
v.a ctio n_id  c alle r_ id
else s ignal(“Tried to write outs ide o f an al l-or-n othin g ac tion!”)
Principles of Computer System Design  Saltzer & Kaashoek
2009
pr ocedureTRANSFER (r efer encede bit_a cc ount, r efer encec re dit_a cc ount, am ount)
my _id  NEW _ ACTION ()
xv alue  R EAD _C UR RENT _VALUE (de bit_a cc ount, m y_id)
xv alue  xv alue - am ount
WR ITE _ NEW _VALUE (de bit_a cc ount, xv alue , my_id
)
yv alue  R EAD _C UR RENT _VALUE (c re dit_a cc ount, m y_id)
yv alue  yv alue + am ount
WR ITE _ NEW _VALUE (c re dit_a cc ount
, yv alue , my_id)
if xv alue > 0 then
C OMM IT (my _id)
else
ABOR T (my _id)
signal(“Negati ve trans fers a re not al lowed.”)
Principles of Computer System Design  Saltzer & Kaashoek
2009
Jo urnal Stora ge
Log
log
WRITE _NEW_V AL UE
ins tall
cu rrent
end of log
Cell
Stora ge
R EAD _CUR RENT _VA LUE
Principles of Computer System Design  Saltzer & Kaashoek
2009
Vo lati le s torag e
In -memo ry data base :
Ordin ary databas e:
High -perfo rmance
da taba se:
Ap plicati on
pro gram
Non-vol atil e storage
lo g
cell
storage
Ap plicati on
pro gram
lo g
cell
storage
Ap plicati on
pro gram
lo g
cell
storage
cach e
Principles of Computer System Design  Saltzer & Kaashoek
2009
Write-ahead-log protocol
Log the updatebefore installing it.
Principles of Computer System Design  Saltzer & Kaashoek
2009
pr ocedureTRANSFER (de bit_a cc ount, c re dit_a cc ount, am ount)
my _id  LOG ( BEGIN _TRANSAC TION )
db valu e.old GET (de bit_a cc ount)
db valu e.ne w  db valu e.old- am ount
c rv alue .old GET (c re dit_a cc ount, m y_id)
c rv alue .new c rv alue .old + am ount
LOG ( C HANGE , my _id,
“ PUT (de bit_a cc ount, db valu e.new)”,
//re do ac tion
“ PUT (de bit_a cc ount, db valu e.old)” )
//undo action
LOG ( C HANGE , my _id,
“ PUT (c re dit_a cc ount, c rv alue .new)”
//re do ac tion
“ PUT (c re dit_a cc ount, c rv alue .old)”)
//undo action
PUT (de bit_a cc ount, db valu e.new
)
// ins tall
PUT (c re dit_a cc ount
, c rv alue .new)
// ins tall
if db valu e.new > 0 then
LOG ( OUTCOME , C OMM IT , my _id)
else
LOG (OUTCOME , ABOR T , my _id)
signal(“Actio n not a llowed . Would mak e deb it ac cou nt neg ative .”)
LOG ( END _TRANSAC TION , my _id)
Principles of Computer System Design  Saltzer & Kaashoek
2009
typ e: C HANGE
action _id: 99 79
… redo _action:
PUT (de bit_a ccount, $9 0)
un do_a ctio n:
PUT (de bit_a ccount,$1 20)
ol der l og re cord s
typ e: OUTCOME
action _id: 99 74
status: COMM ITTED
typ e:
CHANGE
action _id: 99 79
redo _action:
PUT (cre dit_a ccount
, $4 0)
un do_a ctio n:
PUT (cre dit_a ccount
, $1 0)
ne we r log records
Principles of Computer System Design  Saltzer & Kaashoek
2009
pr ocedureABOR T (ac tion _id)
star ting at end of
lo g r epeat until beginning
lo g_rec ord pr evious rec ord of
lo g
if lo g_rec ord.id= ac tion _id then
if (lo g_rec ord.type= OUTCOME )
then signal (“Ca n’t ab ort an al re ady c omp leted acti on.”)
if (lo g_rec ord.type= C HANGE )
then per for mun do_a ctio nof lo g_rec ord
if (lo g_rec ord.type= BEGIN )
then break r epeat
LOG (ac tion _id, OUTCOME , ABOR TED )
// Bloc k future u ndos .
LOG (ac tion _id, END )
Principles of Computer System Design  Saltzer & Kaashoek
2009
pr ocedureR EC OVER ()// Reco very proc edu re for a vol atile , in-mem ory data bas e.
winn ers  NULL
star ting at end of
lo g r epeat until beginning
lo g_rec ord pr evious rec ord of
lo g
if (lo g_rec ord.type= OUTCOME )
then winn ers  winn ers + lo g_rec ord
// Set add ition .
star ting at beginning of
lo g r epeat until end
lo g_rec ord next rec ord oflo g
if (lo g_rec ord.type= C HANGE )
and (ou tcom e_rec ord find (lo g_rec ord.ac tion_ id)in winn ers)
and (ou tcom e_rec ord.sta tus= C OMM ITTED ) then
per for mlo g_rec ord.redo _ac tion
Principles of Computer System Design  Saltzer & Kaashoek
2009
pr ocedureR EC OVER ()// Reco very proc edu re for non-vo latil e ce ll me mory
c ompl eteds NULL
lo sers  NULL
star ting at end of
lo g r epeat until beginning
lo g_rec ord pr evious rec ord of
lo g
if (lo g_rec ord.type= END )
then c ompl eteds c ompl eteds + lo g_rec ord
// Set add ition .
if (lo g_rec ord.ac tion_ idis not in c ompl eteds) then
lo sers  lo sers + lo g_rec ord
// Add if n ot alrea dy in set.
if (lo g_rec ord.type= C HANGE ) then
per for mlo g_rec ord.und o_ac tion
star ting at beginning of
lo g r epeat until end
lo g_rec ord next rec ord oflo g
if (lo g_rec ord.type= C HANGE )
and (lo g_rec ord.ac tion_ id.
s tatus = C OMM ITTED ) then
per for mlo g_rec ord.redo_ acti on
for eac hlo g_rec ordin lo sers do
log (lo g_rec ord.ac tion_ id
, END )
// Show ac tion c omp leted .
Principles of Computer System Design  Saltzer & Kaashoek
2009
pr ocedureR EC OVER ()
// Reco very proc edu re for ro llba ck rec ove ry .
c ompl eteds NULL
lo sers  NULL
star ting at end of
lo g r epeat until beginning
// Perform un do s can .
lo g_rec ord pr evious rec ord of
lo g
if (lo g_rec ord.type= OUTCOME )
then c ompl eteds c ompl eteds + lo g_rec ord // Set add ition .
if (lo g_rec ord.ac tion_ idis not in c ompl eteds) then
lo sers  lo sers + lo g_rec ord
// New los er.
if (lo g_rec ord.type= C HANGE ) then
per for mlo g_rec ord.und o_ac tion
for eac hlo g_rec ordin lo sers do
log (lo g_rec ord.ac tion_ id
, OUTCOME , ABOR T )
// Bloc k future u ndos .
Principles of Computer System Design  Saltzer & Kaashoek
2009
pr ocedureBEGIN _TRANSAC TION ()
id  NEW _OUTCOME _R EC OR D ( PENDING )
// Crea te, initialize, a ssign
id .
prev ious_id id – 1
wait until prev ious_id .outcome_ re cord.state
° PENDING
r etur n id
Principles of Computer System Design  Saltzer & Kaashoek
2009
valu e of obj ect at end of transa cti on
Obje ct
1
2
A
0
+1 0
B
0
-10
C
0
D
0
ou tco me
record
state
3
4
+1 2
6
0
-6
-12
-4
+2
-2
-2
Comm itte d Comm itte d Comm itte d Ab orted
trans acti on 1:
2:
3:
4:
5:
6:
5
ini tiali ze
trans fer
trans fer
trans fer
trans fer
trans fer
Comm itte d Pen ding
a ll ac co unts to0
10 fromB to A
4 fromC to B
2 fromD to A (aborts )
6 fromB to C
10 fromA to B
Principles of Computer System Design  Saltzer & Kaashoek
2009
Obje ct
1
OU TC OME
record
state
2
Va lue of o bject a t en d of tran saction
3
6
4
5
7
A
0
+1 0
+1 0
+1 2
+1 2
0
0
B
0
-10
-6
-6
-12
-2
-2
C
0
0
-4
-4
+2
+2
+2
D
0
0
0
-2
-2
-2
-2
Comm itte d Comm itte d Comm itte d Ab orted Comm itte d Pen ding
Pen ding
Unchang ed val ue
Chan ged va lue
Principles of Computer System Design  Saltzer & Kaashoek
2009
pr ocedureR EAD _C UR RENT _VALUE (da ta_id, this_tran saction _id)
star ting at end ofda ta_id r epeat until beginning
v  pr eviousve rsion of da ta_id
la st_m odifier v.a ctio n_id
if la st_m odifier • this_tran saction _idthen skip v
// Keep searching
wait until (la st_m odifier.outcome_ re cord.state
° PENDING )
if (la st_m odifier.outcome_ re cord.state
= C OMM ITTED )
then r etur n v.state
else skip v
// Resu me search
signal (“Tried to re ad an unin itialize d varia ble”)
Principles of Computer System Design  Saltzer & Kaashoek
2009
pr ocedureNEW _VERSION (r efer enceda ta_id, thi s_tran sac tion _id)
if thi s_tran sac tion _id.o utco me_rec ord.ma rk _sta te
= MAR KED then
signal (“Tried to create new vers ion a fter anno unc ing m ark poi nt!”)
append new version
v to da ta_id
v.v alue  NULL
v.a ctio n_id trans ac tion_ id
pr ocedureWR ITE _VALUE (r efer enceda ta_id, ne w_ valu e, thi s_tran sac tion _id)
star ting at end of
da ta_id r epeat until beginning
v  pr eviousve rs ion of da ta_id
if v.a ctio n_id = thi s_tran sac tion _id
v.v alue  ne w_ valu e
r etur n
signal (“Tried to write wi thout c reatin g new ve rs ion !”))
Principles of Computer System Design  Saltzer & Kaashoek
2009
pr ocedureBEGIN _TRANSAC TION ()
id  NEW _OUTCOME _R EC OR D (PENDING )
prev ious_id id - 1
wait until (prev ious_id .outcome_ re cord.m ark_state
=
or (prev ious_id .outcome_ re cord.state
° PENDING )
r etur n id
MAR KED )
pr ocedureNEW _OUTCOME _R EC OR D (starting_ state)
ACQUIRE (ou tcom e_record_lo ck
)
// Ma ke thi s a b efore-or-after action.
id  TIC KET (ou tcom e_record_seque nce) r
allocateid .outcome_ re cord
id .outcome_ re cord.state starting_ state
id .outcome_ re cord.m ark_state
 NULL
R ELEASE (ou tcom e_record_lo ck
)
r etur n id
pr ocedureMAR K _POINT _ANNOUNC E (r efer encethis_tran saction _id)
this_tran saction _id.o utco me_record.ma rk _sta 
te MAR KED
Principles of Computer System Design  Saltzer & Kaashoek
2009
pr ocedureTRANSFER (r efer encede bit_a cc ount, r efer encec re dit_a cc ount,
am ount)
my _id  BEGIN _TRANSAC TION ()
NEW _VERSION (de bit_a cc ount
, my _id)
NEW _VERSION (c re dit_a cc ount
, my _id)
MAR K_POINT _ANNOUNC E (my _id);
xv alue  R EAD _C UR RENT _VALUE (de bit_a cc ount, my _id)
xv alue  xv alue - am ount
WR ITE_VALUE (de bit_a cc ount
, xv alue, my _id)
yv alue  R EAD _C UR RENT _VALUE (c re dit_a cc ount, my _id)
yv alue  yv alue + am ount
WR ITE_VALUE (c re dit_a cc ount
, yv alue, my _id)
if xv alue > 0 then
C OMM IT (my _id)
else
ABOR T (my _id)
signal(“Negati ve trans fers a re not al lowed.”)
Principles of Computer System Design  Saltzer & Kaashoek
2009
Va lue of o bject a t en d of tran saction
A
1
2
0
+1 0
3
4
5
+1 2
HWM=2
B
C
0
HWM=2
HWM=6
-10
H WM=3
0
-6
-4
HWM=3
D
0
H WM=5
H WM=5
-12
H WM=6
6
7
0
+2
HWM=7
-2
+2
-2
H WM=7
HWM=4
-4
Comm itte d Comm itte d Comm itte d Ab orted Comm itte d Pen ding Pen ding
Outcome state record
HWM=
Conflict: Mus t ab ort!
High -wa ter m ark
Conflict
Chan ged va lue
Principles of Computer System Design  Saltzer & Kaashoek
2009
pr ocedureR EAD _C UR RENT _VALUE (r efer enceda ta_id, va lue, c alle r_ id)
star ting at end of
da ta_id r epeatuntil beginning
v  pr eviousve rs ion of da ta_id
if v.a ctio n_id • c alle r_ id then skip v
examinev.a ctio n_id .outc ome_ re cord
if PENDING then
WAIT for v.a ctio n_id to C OMM IT or ABOR T
if C OMM ITTED then
v.h igh_ wa ter_mark max(v.h igh_ wa ter_mark, c alle r_ id)
r etur n v.v alue
else skip v
// Co ntinu e bac kward s earch
signal (“Tried to re ad an unin itial ize d varia ble!”)
Principles of Computer System Design  Saltzer & Kaashoek
2009
pr ocedureNEW _VERSION (r efer enceda ta_id, calle r_ id)
if (calle r_ id < da ta_id .high _water_ma rk
)
// Co nflict with la ter re ader.
or (calle r_ id < (LATEST _VERSION [da ta_id].action _id)) // Blind write con flict.
then ABOR T this transaction a ndterminate this thread
ad d new ve rsionv at e nd of da ta_id
v.va lue  0
v.a ctio n_id  calle r_ id
pr ocedureWR ITE _VALUE (r efer enceda ta_id, ne w_ valu e, calle r_ id)
locate ve rsionv of da ta_id .historysuc h that v.a ctio n_id = calle r_ id
(if no t found ,signal (“Tried to write without creatin g new ve rsion !”))
v.v alue  ne w_ valu e
Principles of Computer System Design  Saltzer & Kaashoek
2009
architectural ph ys ica l
in structio n
reg iste r
reg iste r
n
R5
42
n+ 1
R4
61
n+ 2
R5
29
0
th ree e ntrie s in the reord er bu ffer
12 7
ph ys ica l reg iste r fil e
with 128 regi sters
n
R5  R4  R2
n + 1 R4  R5 + R1
n + 2 R5  READ (117492)
// Write a result in register five .
// Use result in register five .
// Write content of a me mory cell in register five .
Principles of Computer System Design  Saltzer & Kaashoek
2009
proc edurePAY _INTER EST (refer enceac cou nt)
if ac cou nt.bal anc e> 0 then
inte re st = ac cou nt.bal anc e* 0.0 5
TRANSFER (ban k, ac cou nt, inte re st)
else
inte re st = ac cou nt.bal anc e* 0.1 5
TRANSFER (ac cou nt, ban k, inte re st)
proc edureMONTH _END _INTER EST :()
for A  each cu stom er_ac cou ntdo
PAY _INTER EST (A)
Principles of Computer System Design  Saltzer & Kaashoek
2009
MONTH _END _INTERES T
ou tco me:
su perio r:
PAY _INTERES T1
ou tco me:
su perio r:
su perio r:
no ne
PAY _INTERES T 2
(1st i nvo cation )
ou tco me:
COM MITTED
MO NTH _END _INTER EST
su perio r:
(2n d in vocati on)
PENDING
M ONTH_END _INTERES T
TR ANSFER2
TR ANSFER1
ou tco me:
PENDING
ou tco me:
COM MITTED
PA Y _INTER EST
su perio r:
PENDING
PA Y _INTER EST 2
1
OK fo r TR ANSFER 2
to rea d?
creato r: TRA NS FE R1
ne we st vers ion of
acco unt ba nk
Principles of Computer System Design  Saltzer & Kaashoek
2009
Fro m: Alice
To : Bob
Re: my tra nsa ctio n 91
if (C harles doe s Yand Dawn do es Z)then do X, please.
Principles of Computer System Design  Saltzer & Kaashoek
2009
Fro m:Alice
To : Bob
Re: my tra nsa ctio n 271
Pleas e do X a s pa rt o f my trans ac tion.
Fro m:Bob
To : Alice
Re: yo ur tra nsa ctio n 271
My pa rt X is read y to c ommit.
Two-ph ase -c omm it mes sa ge #1:
Fro m:Alice
To : Bob
Re: my tra nsa ctio n 271
PREPARE
to c omm it X.
Two-ph ase -c omm it mes sa ge #2:
Fro m:Bob
To :Alice
Re: yo ur tra nsa ctio n 271
I am PREPARED to c omm it my p art. Have y ou de cid ed to c omm it yet?
Two-ph ase -c omm it mes sa ge #3
Fro m:Alice
To :Bob
Re: my tra nsa ctio n 271
My trans ac tion c omm itted. T hank s for yo ur help .
Principles of Computer System Design  Saltzer & Kaashoek
2009
Coord inator
Al ice
Wo rker
Bob
Wo rker
Charl es
Wo rker
Dawn
lo g B EGIN
PREPA RE
X
PREPA RE
Y
PR EPARE
Z
lo g B EGIN
Bob is PR EPARE D
lo g PREPA RED
Charl es i s PR EPAR ED
Dawn i s PR EPAR ED
Ti me
lo g
C OMMITTED
C OMM IT
COM MIT
COMM IT
lo g C OMMITTED
Principles of Computer System Design  Saltzer & Kaashoek
2009
From :Juliu s C aes ar
To:Titu s Labie nus
Date:11 Jan uary
I propos e to c ross the Ru bic on an d attac k at d awn tomo rrow. OK?
From :Titu s Labie nus
To:Juliu s C aes ar;
Date:11 Jan uary
Agreed , dawn on the 12 th.
or
From :Titu s Labie nus
To: Juliu s C aes ar
Date:11 Jan uary
No. I am a wa iting
reinfo rc eme nts from Ga ul.
From :Juliu s C aes ar
To:Titu s Labie nus
Date:11 Jan uary
The die i s c ast.
Principles of Computer System Design  Saltzer & Kaashoek
2009
pr ocedureALL _OR _NOTHING _DUR ABLE _GET (r efer enceda ta, ato mic _se ctor)
ds  C AR EFU L _ GET (da ta, ato mic _se ctor.D0)
if ds = BAD then
ds  C AR EFU L _GET (da ta, ato mic _se ctor.D
1)
r etur n ds
pr ocedureALL _OR _NOTHING _DUR ABLE _PUT (ne w_ data, ato mic _se ctor)
SALVAGE (ato mic _se ctor)
ds  C AR EFU L _ PUT (ne w_ data, ato mic _se ctor.D0)
ds  C AR EFU L _ PUT (ne w_ data, ato mic _se ctor.D1)
r etur n ds
pr ocedureSALVAGE (ato mic _se ctor)
//Run thi s prog ra m eve ryTd s eco nds .
ds0  C AR EFU L _GET (da ta0, ato mic _se ctor.D
0)
ds1  C AR EFU L _GET (da ta1, ato mic _se ctor.D
1)
if ds 0 = BAD then
C AR EFU L _PUT (da ta1, ato mic _se ctor.D
0)
else if ds1 = BAD then
C AR EFU L _PUT (da ta0, ato mic _se ctor.D
1)
if da ta0 ° da ta1 then
C AR EFU L _PUT (da ta0, ato mic _se ctor.D
1)
D0:
data0
D1 :
data1
Principles of Computer System Design  Saltzer & Kaashoek
2009
Download