Docsity

Notes on Transactions - Intermediate Computer Systems | CS 5410, Exams of Computer Science

Partial preview of the text

Download Notes on Transactions - Intermediate Computer Systems | CS 5410 and more Exams Computer Science in PDF only on Docsity!

i

Ken

Birman

Cornell

University.

CS

Fall^ 2008.

Transactions^ y^ The^

most^ important

reliability

technology

for

client‐

server^

systems

N^ t

t^

i^ d^

th^

i^ ti^

f^ th^ t^

i

y^ Now

start^ an

in‐depth

examination

of^ the

topic

y^ How^ transactional

systems

really^ work

y^ Implementation

considerations Implementation

considerations y^ Limitations

and^ performance

challenges

y^ Scalability

of^ transactional

systems

y^ Traditionally

covered

in^ multiple

lectures,

but^ with

the^ cloud

emphasis

in^ CS

this^ year,

compressed

into^ a^

single^

one

compressed

into^ a^

single^

one

Transactions

on^ a

singleg

database:^ y^ In^ a^

client/server

architecture,

y^ A^ transaction

is^ an^ execution

of^ a^ single

program

of^ the^ application(client)

at^ the^

server.

y^ Seen^ at

the^ server

as^ a^ series

of^ reads

and^ writes.

y^ We^ want

this^ setup

to^ work

when

y^ There

are^ multiple

simultaneous

client^ transactions

running

at^ the^ server running

at^ the^ server

y^ Client/Server

could^ fail

at^ any^ time.

Transactions

The^

ACID

Properties

y^ Are^ the

four^ desirable

properties

for^ reliable

handling

of

concurrent

transactions. y^ Atomicity

y y The “All^ or^ Nothing”

behavior.

y^ C:^ stands

for^ either y^ Concurrency:

Transactions

can^ be^ executed

concurrently

Concurrency:

Transactions

can^ be^ executed

concurrently

y^ …^ or^ Consistency:

Each^ transaction,

if^ executed

by^ itself,

maintains

the^ correctness

of^ the^ database.

y^ Isolation

(Serializability) y^ Isolation

(Serializability) y Concurrent^ transaction

execution

should^ be

equivalent

(in

effect)^ to

a^ serialized

execution.

y^ Durabilityy^ Durability^ y^ Once

a^ transaction

is^ done ,^ it

stays^ done.

The^

transactional

model

y^ Applications

are^ coded

in^ a^ stylized

way:

y^ begin^ transaction y^ Perform

a^ series^ of

read^ update

operations

y^ Perform

a^ series^ of

read ,^ update

operations

y^ Terminate

by^ commit

or^ abort.

y^ Terminology^ y^ The

application

is^ the^ transaction

manager

y^ The^ data

manager is

presented

with^ operations

from

concurrently

active^ t

ransactions co cu^

e t y act ve t a sact o s y^ It^ schedules them

in^ an^ interleaved

but^ serializable

order

A^ side

remark

y^ Each

transaction

is^ built

up^ incrementally

y^ Application

runs y^ And^ as

it^ runs,

it^ issues

operations

y^ The^ data

manager

sees^ them

one^ by^

one

B^ f^

lk^ if

k^

h^ h l

hi

y^ But^ often

we^ talk

as^ if^ we

knew^

the^ whole

thing^

at

one^ time^ y^ We’re

careful^

to^ do^ this

in^ ways

that^ make

sense

y^ We re

careful^

to^ do^ this

in^ ways

that^ make

sense

y^ In^ any

case,^ we

usually

don’t^ need

to^ say^ anything

until^ a

“commit”

is^ issued

Typical

transactional

program

begin^ transaction;x^ =^ read(“x

‐values”,

y^ =^ read(“y

‐values”,

z^ =^ x+y;write(“z

‐values”,

z,^ ....);

commit

transaction;

What

about

the

locks?

y^ Unlike

other^

kinds^ of

distributed

systems,

transactional

systems

typically

lock^ the

data^ they

accessaccess y They^ obtain

these^

locks^ as

they^ run:

y^ Before

accessing

“x”^ get^

a^ lock^ on

“x”

Before^ accessing

x^ get^

a^ lock^ on

x

y^ Usually

we^ assume

that^ the

application

knows^

enough

to

get^ the^ right

kind^ of

lock.^ It

is^ not^ good

to^ get^ a

read

lock^ if^ you

’ll^ later^

need^ to

update

the^ object

lock^ if^ you ll

later^ need

to^ update

the^ object

y^ In^ clever

applications,

one^ lock

will^ often

cover

many^ objectsy^

j

Examples

of^ lock

coverage

y^ We^ could

have^ one

lock^ per

object

y^ …^ or^ one

lock^ for

the^ whole

database l^ k^ f^

f^ bj

y^ …^ or^ one

lock^ for

a^ category

of^ objects

y^ In^ a^ tree,

we^ could

have^ one

lock^ for^ the

whole^ tree

associated

with

the^ root y In^ a^ table

we^ could

have^ one

lock^ for^ row,

or^ one^ for

each^ column,

or

one^ for^ the

whole^ table y^ All^ transactions

must^ use

the^ same

rules!

All^ transactions

must^ use

the^ same

rules!

y^ And^ if

you^ will

update

the^ object,

the^ lock

must^ be

a^ “write”

lock,^ not

a^ “read”

lock

Transactional

Execution

Log

y^ As^ the

transaction

runs,^ it

creates

a^ history

of^ its

actions.

Suppose

we^ were

to^ write

down^

the

f^

i^ i^

f

sequence

of^ operations

it^ performs.

y^ Data

manager

does^ this,

one^ by

one

y^ This^

yields^ a

“schedule”

y^ Operations

and^ order

they^ executed C^ i f^

d^ i^

hi h^

i

y^ Can^ infer

order^ in

which^ transactions

ran

y^ Scheduling

is^ called

“concurrency

control”

Serializability^ y^ Means

that^ effect

of^ the^

interleaved

execution

is

indistinguishable

from^ some

possible

serial

i^ f^

h^

i^ d^

i

execution

of^ the

committed

transactions

y^ For^ example:

T1^ and

T2^ are

interleaved

but^ it^

“looks

lik ”^ T^

b f^

T

like”^ T

ran^ before

T

y^ Idea^

is^ that^

transactions

can^ be

coded

to^ be^ correct

if^ run^ in

isolation

and^ yet

will^ run

correctly

when

if^ run^ in

isolation

,^ and^ yet

will^ run

correctly

when

executed

concurrently

(and^ hence

gain^ a^

speedup)

Need

for^

serializable

execution

T:^ R(X) R^1^1

(Y) W(X) commit 1

1 T:^ R(X) W2^2^2

(X) W2(Y) commit

2 (^ )^ (^ 2 2 2 )^ (^ )^2

2 DB:^ R(X) R^1

(X) W(X) R(Y) W 2 1

(X) W2(Y) commit 1

commit^1

Data manager interleaves operations to improve concurrency

Serializable

execution T: R(X) R(Y) W(X) commit 1 1 1 1

1 T:^ R(X) W2^2^2

(X) W2(Y) commit

2 (^ )^ (^ 2 2 2 )^ (^ )^2

2 DB:^ R(X) W^2

(X) R(X) W(X) W2 2 1 1

(Y) R(Y) commit 1

commit^2

Data manager interleaves operations to improve concurrency but schedules them so thatit looks as if one transaction ran at a time

This schedule “looks” like T

ran first 2

it looks as if one transaction ran at a time. This schedule

looks^ like T

ran first. 2

Atomicity

considerations

y^ If^ application

(“transaction

manager”)

crashes,

treat^ as

an^ abort

y^ If^ data

manager

crashes,

abort^

any^ non

‐committed

transactions,

but^ committed

state^ is

persistent

b^ d^

l^

ff^

h^ d

b

y^ Aborted

transactions

leave^ no

effect,^ either

in^ database

itself^ or

in^ terms

of^ indirect

side‐effects

y^ Only^ need

to^ consider

committed

operations

in

Only^ need

to^ consider

committed

operations

in

determining

serializability