38
What is Concurrent Process (CP)? What is Concurrent Process (CP)? Multiple users access databases and use Multiple users access databases and use computer systems computer systems simultaneously. simultaneously. Example: Airline reservation system. Example: Airline reservation system. An airline reservation system is used by An airline reservation system is used by hundreds of travel agents and reservation hundreds of travel agents and reservation clerks concurrently. clerks concurrently. Why Concurrent Process? Why Concurrent Process? Better transaction throughput and Better transaction throughput and response time response time Better utilization of resource Better utilization of resource Introduction Introduction

What is Concurrent Process (CP)? Multiple users access databases and use computer systems Multiple users access databases and use computer systems simultaneously

Embed Size (px)

Citation preview

Page 1: What is Concurrent Process (CP)? Multiple users access databases and use computer systems Multiple users access databases and use computer systems simultaneously

What is Concurrent Process (CP)?What is Concurrent Process (CP)?• Multiple users access databases and use computer systems Multiple users access databases and use computer systems

simultaneously.simultaneously.

• Example: Airline reservation system.Example: Airline reservation system.– An airline reservation system is used by hundreds of travel agents An airline reservation system is used by hundreds of travel agents and reservation clerks concurrently.and reservation clerks concurrently.

Why Concurrent Process?Why Concurrent Process?• Better transaction throughput and response timeBetter transaction throughput and response time

• Better utilization of resourceBetter utilization of resource

IntroductionIntroduction

Page 2: What is Concurrent Process (CP)? Multiple users access databases and use computer systems Multiple users access databases and use computer systems simultaneously

TransactionTransaction• What is Transaction?What is Transaction?• A sequence of many actions which are considered to be oneA sequence of many actions which are considered to be one atomic unit of work.atomic unit of work.• Basic operations a transaction can include “actions”:Basic operations a transaction can include “actions”:

– Reads, writesReads, writes– Special actions: commit, abortSpecial actions: commit, abort

• ACID properties of transactionACID properties of transaction• AAtomicitytomicity:: Transaction is either performed in its entirety or not performed at all, Transaction is either performed in its entirety or not performed at all,

this should be DBMS’ responsibilitythis should be DBMS’ responsibility

• CConsistencyonsistency:: Transaction must take the database from one consistent state to Transaction must take the database from one consistent state to another. It is user’s responsibility to insure consistencyanother. It is user’s responsibility to insure consistency

• IIsolationsolation:: Transaction should appear as though it is being executed in isolation from Transaction should appear as though it is being executed in isolation from other transactionssother transactionss

• DDurabilityurability:: Changes applied to the database by a committed transaction must persist, Changes applied to the database by a committed transaction must persist, even if the system fail before all changes reflected on diskeven if the system fail before all changes reflected on disk

Page 3: What is Concurrent Process (CP)? Multiple users access databases and use computer systems Multiple users access databases and use computer systems simultaneously

Concurrent TransactionsConcurrent Transactions

interleaved processing parallel processing

t1 t2 t1 t2

time

CPU1

CPU2

A

B

A

B

CPU1

Page 4: What is Concurrent Process (CP)? Multiple users access databases and use computer systems Multiple users access databases and use computer systems simultaneously

SchedulesSchedules

• What is SchedulesWhat is Schedules– A schedule S of n transactions T1,T2,…Tn is an ordering of the operations of A schedule S of n transactions T1,T2,…Tn is an ordering of the operations of

the transactions subject to the constraint that, for each transaction Ti that the transactions subject to the constraint that, for each transaction Ti that participates in S, the operations of Ti in S must appear in the same order in participates in S, the operations of Ti in S must appear in the same order in which they occur in Ti.which they occur in Ti.

– Example: SExample: Saa: r1(A),r2(A),w1(A),w2(A), a1,c2;: r1(A),r2(A),w1(A),w2(A), a1,c2;

T1T1 T2T2

Read(A)Read(A)

Write(A)Write(A)

Abort T1Abort T1

Read(A)Read(A)

Write(A)Write(A)

Commit T2Commit T2

Page 5: What is Concurrent Process (CP)? Multiple users access databases and use computer systems Multiple users access databases and use computer systems simultaneously

Oops, something’s wrongOops, something’s wrong• Reserving a seat for a flightReserving a seat for a flight• If concurrent access to data in DBMS, two users may try to book the same seat If concurrent access to data in DBMS, two users may try to book the same seat

simultaneouslysimultaneously

Agent 1 findsseat 35G empty Agent 2 finds

seat 35G empty

time

Agent 1 setsseat 35G occupied

Agent 2 setsseat 35G occupied

Page 6: What is Concurrent Process (CP)? Multiple users access databases and use computer systems Multiple users access databases and use computer systems simultaneously

Another exampleAnother example• Problems can occur when concurrent transactions execute in an uncontrolled Problems can occur when concurrent transactions execute in an uncontrolled

manner.manner.• Examples of one problem.Examples of one problem.

– A original equals to 100, after execute T1 and T2, A is supposed to be 100+10-A original equals to 100, after execute T1 and T2, A is supposed to be 100+10-8=1028=102

Add 10 To AAdd 10 To A Minus 8 from AMinus 8 from A

T1T1 T2T2

Read(A)Read(A)

A=A+10A=A+10

Write(A)Write(A)

Read(A)Read(A)

A=A-8A=A-8

Write(A)Write(A)

Value of A Value of A on the diskon the disk

100100

100100

100100

100100

110110

9292

Page 7: What is Concurrent Process (CP)? Multiple users access databases and use computer systems Multiple users access databases and use computer systems simultaneously

What Can Go Wrong?What Can Go Wrong?

• Concurrent process may end up violating Isolation property of Concurrent process may end up violating Isolation property of transaction if not carefully scheduledtransaction if not carefully scheduled

• Transaction may be aborted before committedTransaction may be aborted before committed- undo the uncommitted transactions- undo the uncommitted transactions

- undo transactions that sees the uncommitted change before the crash- undo transactions that sees the uncommitted change before the crash

Page 8: What is Concurrent Process (CP)? Multiple users access databases and use computer systems Multiple users access databases and use computer systems simultaneously

Conflict operationsConflict operations• Two operations in a schedule are said to be Two operations in a schedule are said to be conflict conflict if they satisfy if they satisfy

all three of the following conditions:all three of the following conditions:(1)(1) They belong to different transactionsThey belong to different transactions

(2)(2) They access the same item A;They access the same item A;

(3)(3) at least one of the operations is a write(A)at least one of the operations is a write(A)

Example in Sa: r1(A),r2(A),w1(A),w2(A), a1,c2;Example in Sa: r1(A),r2(A),w1(A),w2(A), a1,c2;

– r1(A),w2(A) conflict, so do r2(A),w1(A), r1(A),w2(A) conflict, so do r2(A),w1(A),

– r1(A), w1(A) do not conflict because they belong to the same r1(A), w1(A) do not conflict because they belong to the same transaction,transaction,

– r1(A),r2(A) do not conflict because they are both read operations.r1(A),r2(A) do not conflict because they are both read operations.

Page 9: What is Concurrent Process (CP)? Multiple users access databases and use computer systems Multiple users access databases and use computer systems simultaneously

Serializability of schedulesSerializability of schedules• Serial Serial

– A schedule S is A schedule S is serial serial if, for every transaction T participating in the schedule, if, for every transaction T participating in the schedule, all the operations of T are executed consecutively in the schedule.( No all the operations of T are executed consecutively in the schedule.( No interleaving occurs in a serial schedule)interleaving occurs in a serial schedule)

• SerializableSerializable– A schedule S of n transactions is A schedule S of n transactions is serializableserializable if it is if it is equivalentequivalent to some to some serialserial

schedule of the same n transactions.schedule of the same n transactions.

• schedules are conflict equivalent if:schedules are conflict equivalent if:– they have the same sets of actions, and they have the same sets of actions, and – each pair of conflicting actions is ordered in the same wayeach pair of conflicting actions is ordered in the same way

• schedules are conflict equivalent if:schedules are conflict equivalent if:– they have the same sets of actions, and they have the same sets of actions, and – each pair of conflicting actions is ordered in the same wayeach pair of conflicting actions is ordered in the same way

• Conflict SerializableConflict Serializable– A schedule is said to be conflict serializable if it is conflict equivalent to a A schedule is said to be conflict serializable if it is conflict equivalent to a

serial scheduleserial schedule

Page 10: What is Concurrent Process (CP)? Multiple users access databases and use computer systems Multiple users access databases and use computer systems simultaneously

Characterizing Characterizing SchedulesSchedules1. Avoid cascading abort(ACA)1. Avoid cascading abort(ACA)• Aborting T1 requires aborting T2!Aborting T1 requires aborting T2!

– Cascading AbortCascading Abort• An ACA (avoids cascading abort)An ACA (avoids cascading abort)

– A X act only reads data from A X act only reads data from committed X acts.committed X acts.

2.2. recoverablerecoverable• Aborting T1 requires aborting T2!Aborting T1 requires aborting T2!

– – But T2 has already committed!But T2 has already committed!• A recoverable schedule is one in A recoverable schedule is one in

which this cannot happen.which this cannot happen.– – i.e. a X act commits only after all i.e. a X act commits only after all the X acts it “depends on” (i.e. it the X acts it “depends on” (i.e. it reads from) commit.reads from) commit.– – ACA implies recoverable (but not ACA implies recoverable (but not vice-versa!).vice-versa!).

3. strict schedule3. strict schedule

T1T1 T2T2

Read(Read(A)A)

Write(Write(A)A)

AbortAbort

Read(Read(A)A)

Write(Write(A)A)

T1T1 T2T2

Read(Read(A)A)

Write(Write(A)A)

commicommitt

Read(Read(A)A)

Write(Write(A)A)T1T1 T2T2

Read(ARead(A))

Write(Write(A)A)

AbortAbort

Read(Read(A)A)

Write(Write(A)A)

CommiCommitt

T1T1 T2T2

Read(Read(A)A)

Write(Write(A)A)

CommiCommitt

Read(Read(A)A)

Write(Write(A)A)

CommiCommitt

T1T1 T2T2

Read(Read(A)A)

Write(Write(A)A)

CommiCommitt

Read(Read(A)A)

Write(Write(A)A)

CommiCommitt

No No Yes Yes

Page 11: What is Concurrent Process (CP)? Multiple users access databases and use computer systems Multiple users access databases and use computer systems simultaneously

Venn Diagram for SchedulesVenn Diagram for Schedules

Serial

Strict

ACA

Recoverable

View SerializableAll Schedules

Conflict Serializable

Page 12: What is Concurrent Process (CP)? Multiple users access databases and use computer systems Multiple users access databases and use computer systems simultaneously

ExampleExample

T1:W(X), T2:R(Y), T1:R(Y), T2:R(X), C2, T1:W(X), T2:R(Y), T1:R(Y), T2:R(X), C2, C1C1

• serializable: Yes, equivalent to T1,T2serializable: Yes, equivalent to T1,T2• conflict-serializable: Yes, conflict-conflict-serializable: Yes, conflict-

equivalent to T1,T2equivalent to T1,T2• recoverable: No. Yes, if C1 and C2 are recoverable: No. Yes, if C1 and C2 are

switched.switched.• ACA: No. Yes, if T1 commits before T2 ACA: No. Yes, if T1 commits before T2

writes X.writes X.

Page 13: What is Concurrent Process (CP)? Multiple users access databases and use computer systems Multiple users access databases and use computer systems simultaneously

Sample Transaction Sample Transaction (informal)(informal)• Example: Move $40 from checking to Example: Move $40 from checking to

savings accountsavings account• To user, appears as one activityTo user, appears as one activity• To database:To database:

– Read balance of checking account: read( X)Read balance of checking account: read( X)– Read balance of savings account: read (Y)Read balance of savings account: read (Y)– Subtract $40 from XSubtract $40 from X– Add $40 to YAdd $40 to Y– Write new value of X back to diskWrite new value of X back to disk– Write new value of Y back to diskWrite new value of Y back to disk

Page 14: What is Concurrent Process (CP)? Multiple users access databases and use computer systems Multiple users access databases and use computer systems simultaneously

Sample Transaction Sample Transaction (Formal)(Formal)

T1T1

read_item(X);read_item(X);read_item(Y); read_item(Y); X:=X-40;X:=X-40;Y:=Y+40;Y:=Y+40;write _item(X);write _item(X);write_item(Y);write_item(Y);

t0

tk

Page 15: What is Concurrent Process (CP)? Multiple users access databases and use computer systems Multiple users access databases and use computer systems simultaneously

Focus on concurrency Focus on concurrency controlcontrol

• Real DBMS does not test for serializabilityReal DBMS does not test for serializability– Very inefficient since transactions are continuously Very inefficient since transactions are continuously

arrivingarriving

– Would require a lot of undoingWould require a lot of undoing

• Solution: concurrency protocolsSolution: concurrency protocols

• If followed by every transaction, and enforced If followed by every transaction, and enforced by transaction processing system, guarantee by transaction processing system, guarantee serializability of schedulesserializability of schedules

Page 16: What is Concurrent Process (CP)? Multiple users access databases and use computer systems Multiple users access databases and use computer systems simultaneously

Concurrency Control Through Concurrency Control Through LocksLocks

• Lock:Lock: variable associated with each variable associated with each data itemdata item– Describes status of item wrt operations that Describes status of item wrt operations that

can be performed on itcan be performed on it

• Binary locks: Locked/unlockedBinary locks: Locked/unlocked• Multiple-mode locks: Read/writeMultiple-mode locks: Read/write• Three operationsThree operations

– read_lock(X)read_lock(X)– write_lock(X)write_lock(X)– unlock(X)unlock(X)

• Each data item can be in one of three Each data item can be in one of three lock stateslock states

Page 17: What is Concurrent Process (CP)? Multiple users access databases and use computer systems Multiple users access databases and use computer systems simultaneously

Two TransactionsTwo TransactionsT1T1

read_lock(Y);read_lock(Y);

read_item(Y);read_item(Y);

unlock(Y);unlock(Y);

write_lock(X);write_lock(X);

read_item(X);read_item(X);

X:=X+Y;X:=X+Y;

write_item(X);write_item(X);

unlock(X);unlock(X);

T2T2

read_lock(X);read_lock(X);

read_item(X);read_item(X);

unlock(X);unlock(X);

write_lock(Y);write_lock(Y);

read_item(Y);read_item(Y);

Y:=X+Y;Y:=X+Y;

write_item(Y);write_item(Y);

unlock(Y);unlock(Y);

Let’s assume serial schedule S1: T1;T2Let’s assume serial schedule S1: T1;T2

Initial values: X=20, Y=30 Initial values: X=20, Y=30 Result: X=50, Y=80 Result: X=50, Y=80

Page 18: What is Concurrent Process (CP)? Multiple users access databases and use computer systems Multiple users access databases and use computer systems simultaneously

Locks Alone Don’t Do the Locks Alone Don’t Do the Trick!Trick!

T1T1

read_lock(Y);read_lock(Y);read_item(Y);read_item(Y);unlock(Y);unlock(Y);

write_lock(X);write_lock(X);read_item(X);read_item(X);X:=X+Y;X:=X+Y;write_item(X);write_item(X);unlock(X);unlock(X);

T2T2

read_lock(X);read_lock(X);read_item(X);read_item(X);unlock(X);unlock(X);write_lock(Y);write_lock(Y);read_item(Y);read_item(Y);Y:=X+Y;Y:=X+Y;write_item(Y);write_item(Y);unlock(Y);unlock(Y);Non-serializable!Non-serializable!

Result: X=50, Y=50Result: X=50, Y=50

unlocked too early!

Let’s run T1 and T2 in interleafed fashionLet’s run T1 and T2 in interleafed fashion

Schedule S

Page 19: What is Concurrent Process (CP)? Multiple users access databases and use computer systems Multiple users access databases and use computer systems simultaneously

Two-Phase Locking (2PL)Two-Phase Locking (2PL)

• Def.: Transaction is said to follow Def.: Transaction is said to follow the the two-phase-locking protocoltwo-phase-locking protocol if if all locking operations precede the all locking operations precede the firstfirst unlock operation unlock operation

Page 20: What is Concurrent Process (CP)? Multiple users access databases and use computer systems Multiple users access databases and use computer systems simultaneously

ExampleExampleT1’T1’

read_lock(Y);read_lock(Y);

read_item(Y);read_item(Y);

write_lock(X);write_lock(X);

unlock(Y);unlock(Y);

read_item(X);read_item(X);

X:=X+Y;X:=X+Y;

write_item(X);write_item(X);

unlock(X);unlock(X);

T2’T2’read_lock(X);read_lock(X);

read_item(X);read_item(X);

write_lock(Y);write_lock(Y);

unlock(X);unlock(X);

read_item(Y);read_item(Y);

Y:=X+Y;Y:=X+Y;

write_item(Y);write_item(Y);

unlock(Y);unlock(Y);

• Both T1’ and T2’ follow the 2PL protocolBoth T1’ and T2’ follow the 2PL protocol• Any schedule including T1’ and T2’ is guaranteed to be serializableAny schedule including T1’ and T2’ is guaranteed to be serializable• Limits the amount of concurrencyLimits the amount of concurrency

Page 21: What is Concurrent Process (CP)? Multiple users access databases and use computer systems Multiple users access databases and use computer systems simultaneously

Variations to the Basic Variations to the Basic ProtocolProtocol

• Previous technique knows as Previous technique knows as basic basic 2PL2PL

• ConservativeConservative 2PL (static) 2PL: Lock 2PL (static) 2PL: Lock all items needed BEFORE all items needed BEFORE execution begins by predeclaring execution begins by predeclaring its read and write setits read and write set– If any of the items in read or write set If any of the items in read or write set

is already locked (by other is already locked (by other transactions), transaction waits (does transactions), transaction waits (does not acquire any locks)not acquire any locks)

– Deadlock free but not very realisticDeadlock free but not very realistic

Page 22: What is Concurrent Process (CP)? Multiple users access databases and use computer systems Multiple users access databases and use computer systems simultaneously

Variations to the Basic Variations to the Basic ProtocolProtocol• StrictStrict 2PL: Transaction does not 2PL: Transaction does not

release its write locks until AFTER release its write locks until AFTER it aborts/commitsit aborts/commits– Not deadlock free but guarantees Not deadlock free but guarantees

recoverable schedules (strict recoverable schedules (strict schedule: transaction can neither schedule: transaction can neither read/write X until last transaction read/write X until last transaction that wrote X has that wrote X has committed/aborted)committed/aborted)

– Most popular variation of 2PLMost popular variation of 2PL

Page 23: What is Concurrent Process (CP)? Multiple users access databases and use computer systems Multiple users access databases and use computer systems simultaneously

Concluding RemarksConcluding Remarks

• Concurrency control subsystem is Concurrency control subsystem is responsible for inserting locks at right responsible for inserting locks at right places into your transactionplaces into your transaction– Strict 2PL is widely usedStrict 2PL is widely used– Requires use of waiting queueRequires use of waiting queue

• All 2PL locking protocols guarantee All 2PL locking protocols guarantee serializabilityserializability

• Does not permit all possible serial Does not permit all possible serial schedulesschedules

Page 24: What is Concurrent Process (CP)? Multiple users access databases and use computer systems Multiple users access databases and use computer systems simultaneously

Why “Database Recovery Why “Database Recovery Techniques”?Techniques”?

• AACICIDD properties of Transaction properties of Transaction

Time

T1T2

T3

Crash

Database system should guaranteeDatabase system should guarantee

- DDurability : Applied changes by transactions urability : Applied changes by transactions must not be lost. ~ T3must not be lost. ~ T3

- AAtomicity : Transactions can be aborted.tomicity : Transactions can be aborted.

~ T1, T2~ T1, T2

System crashTransaction errorSystem errorLocal errorDisk failureCatastrophe

Page 25: What is Concurrent Process (CP)? Multiple users access databases and use computer systems Multiple users access databases and use computer systems simultaneously

Basic Idea : “Logging”Basic Idea : “Logging”

• Undo/Redo by the Log Undo/Redo by the Log recover Non-catastrophic failure recover Non-catastrophic failure

Time

T1T2

T3

Crash

System LogSystem Log

- keeps info of changes - keeps info of changes applied by transactions applied by transactions

CheckpointBackup

• Full DB Backup Full DB Backup > Differential Backup> Differential Backup > > (Transaction) Log(Transaction) Log

Catastrophic failureCatastrophic failure

Page 26: What is Concurrent Process (CP)? Multiple users access databases and use computer systems Multiple users access databases and use computer systems simultaneously

Physical View Physical View - How they work -- How they work - (1) (1)

Action :Action :

1)1) CheckCheck the directory the directory whetherwhether in the cache in the cache

2) If none, copy from 2) If none, copy from disk pagesdisk pages to to the cachethe cache

DiskMemory

DBMS cache

(buffers)

Disk pages/blocks

(address:A,a,1)(address:B,b,0)

A

B a

b

Directory

copy

flush

3) For the copy, old buffers needs to be 3) For the copy, old buffers needs to be flushed flushed from from the cachethe cache to to the disk pagesthe disk pages

B’

Page 27: What is Concurrent Process (CP)? Multiple users access databases and use computer systems Multiple users access databases and use computer systems simultaneously

Physical View Physical View - How they work -- How they work - (2) (2)

DiskMemory

DBMS cache

(buffers)

Disk pages/blocks

(address:A,a,1)(address:B,b,0)

A

B a

b

Directory

copy

flush

4) Flush only if 4) Flush only if a dirty bita dirty bit is 1 is 1

Dirty bit : (in the directory) whether there is Dirty bit : (in the directory) whether there is a change after copy to the cachea change after copy to the cache 1 – updated in the cache1 – updated in the cache 0 – not updated in the cache (no need to 0 – not updated in the cache (no need to

flush) flush)

update

B’

Page 28: What is Concurrent Process (CP)? Multiple users access databases and use computer systems Multiple users access databases and use computer systems simultaneously

Physical View Physical View - How they work -- How they work - (3) (3)

DiskMemory

DBMS cache

(buffers)

Disk pages/blocks

A

B a

b

copy

flush

A-a : A-a : “in-place updating”“in-place updating” - when flushing, overwrite at the same - when flushing, overwrite at the same locationlocation - - logginglogging is required is requiredB-b : B-b : “shadowing”“shadowing”

B’

Page 29: What is Concurrent Process (CP)? Multiple users access databases and use computer systems Multiple users access databases and use computer systems simultaneously

Physical View Physical View - How they work -- How they work - (4) (4)

DiskMemory

DBMS cache

Data blocks

Bb

(1) copy (from the disk to the cache)

(2) update the cached data, record it in the log(3) flush the log and the data (from the cache to the disk)

copy

flush

Log blocks

update

B’ Logblocks

Datablocks

update

Page 30: What is Concurrent Process (CP)? Multiple users access databases and use computer systems Multiple users access databases and use computer systems simultaneously

WAL : Write-Ahead Logging (1)WAL : Write-Ahead Logging (1)• in-place updating in-place updating A log A log is necessaryis necessary

BFIM (BeFore IMage)BFIM (BeFore IMage) – overwrite – – overwrite – AFIM (AFter)AFIM (AFter)

DiskMemory

DBMS cache

Data blocks

copy

2) flush

Log blocks

update

Logblocks

Datablocks

update

Aa

BFIM

BFIMAFIM

BFIM

• WAL (Write-Ahead Logging)WAL (Write-Ahead Logging)

Log entries flushed Log entries flushed before overwritingbefore overwriting main data main data

1) flush

UNDO-type log record

Page 31: What is Concurrent Process (CP)? Multiple users access databases and use computer systems Multiple users access databases and use computer systems simultaneously

WAL : Write-Ahead Logging (2)WAL : Write-Ahead Logging (2)• WAL protocol requires WAL protocol requires UNDOUNDO and and REDOREDO

Time

Tcommit

LogLog

- BFIM cannot be overwritten by AFIM on diskBFIM cannot be overwritten by AFIM on disk until all until all UNDO-type logUNDO-type log have force-written to disk. have force-written to disk.

- The commit operation cannot be completedThe commit operation cannot be completed until all until all UNDO/REDO-type logUNDO/REDO-type log have force-written. have force-written.

UNDO

REDO

Page 32: What is Concurrent Process (CP)? Multiple users access databases and use computer systems Multiple users access databases and use computer systems simultaneously

Steal & No-Force (1)Steal & No-Force (1)• Typical DBTypical DB employsemploys aa steal/no-forcesteal/no-force strategystrategy

Time

T1T2

T3

commitcommit

cache

Updated data by T2

cache Can be Used for other transactions (T3)

before T2 commits

• StealSteal strategy : a transaction strategy : a transaction cancan be written to disk be written to disk before it commitsbefore it commits

Advantage : Advantage : buffer space saving buffer space saving

Page 33: What is Concurrent Process (CP)? Multiple users access databases and use computer systems Multiple users access databases and use computer systems simultaneously

Steal & No-Force (2)Steal & No-Force (2)

Time

T1T2

T3

commitcommit

cache

Updated data by T2

cache

If T3 needs the same data, it must be copied again

when T2 commits

• No-ForceNo-Force strategy : a transaction strategy : a transaction need notneed not to be to be

written to disk written to disk immediatelyimmediately when it commitswhen it commits

Advantage : Advantage : I/O operations saving I/O operations saving

Force strategyForce strategy

Page 34: What is Concurrent Process (CP)? Multiple users access databases and use computer systems Multiple users access databases and use computer systems simultaneously

CheckpointingCheckpointing• Checkpoint Checkpoint - All DMBS buffers modified are wrote out to disk.- All DMBS buffers modified are wrote out to disk. - A record is written into the log. (- A record is written into the log. ([checkpoint][checkpoint])) - Periodically done- Periodically done (e.g. every n min. or every n transaction(e.g. every n min. or every n transaction

Time

T1T2

T3

Crash

Checkpoint

Page 35: What is Concurrent Process (CP)? Multiple users access databases and use computer systems Multiple users access databases and use computer systems simultaneously

Transaction Rollback (1)Transaction Rollback (1)

• Rollback / Roll fowardRollback / Roll foward

Time

T1T2

T3

Crash

T4

T5

1 : Not necesary

2 : Roll foward

3 : Rollback

4 : Roll forward

5 : Roll back

Checkpoint

- Steal : transaction may be written on disk Steal : transaction may be written on disk before it commits before it commits

Recovery method

Page 36: What is Concurrent Process (CP)? Multiple users access databases and use computer systems Multiple users access databases and use computer systems simultaneously

• example :example :

NamNamee

AccouAccountnt

Mr.AMr.A $10$10

Mr.BMr.B $2,000$2,000

Mr.CMr.C $30,00$30,0000

Transaction Rollback (2)Transaction Rollback (2)

TimeT2

Checkpoint Crash

T1 : A company pays salary to employees i) transfer $2,000 to Mr. A’s account ii) transfer $2,500 to Mr B’s account …

write(A)

read(A)

T1read(B)read(A) write(B)

write(C)read(C)write(A)

T2 : Mr.A pays the monthly rent. i) withdraw $1,500 from Mr.A’s account ii) transfer $1,500 to Mr.C’s account

Page 37: What is Concurrent Process (CP)? Multiple users access databases and use computer systems Multiple users access databases and use computer systems simultaneously

• Cascading RollbackCascading RollbackTransaction Rollback (3)Transaction Rollback (3)

System LogSystem Log[checkpoint][checkpoint][start_transaction, T1][start_transaction, T1][read_item, T1, A][read_item, T1, A][write_item, T1, A, 10, 2010][write_item, T1, A, 10, 2010][start_transaction, T2][start_transaction, T2][read_item, T2, A][read_item, T2, A][write_item, T2, A, 2010, 510][write_item, T2, A, 2010, 510][read_item, T1, B][read_item, T1, B][read_item, T2, C][read_item, T2, C][write_item, T2, C, 1500, [write_item, T2, C, 1500,

31500]31500]~~~ CRASH ~~~~ ~~~ CRASH ~~~~

T2

Checkpoint Crash

w(A)

r(A)T1

r (B)r(A)

w(C)r(C)w(A)

AA$10$10

$10$10$2,01$2,01

00

$2,01$2,0100

$510$510

CC$30,000$30,000

$30,000$30,000$31,500$31,500

-T1 is interrupted (needs rollback)

-T2 uses value modified by T1 (also needs rollback)

Page 38: What is Concurrent Process (CP)? Multiple users access databases and use computer systems Multiple users access databases and use computer systems simultaneously

Categorization of Recovery AlgorithmCategorization of Recovery Algorithm

• Deferred update – the No-UNDO/REDO algorithmDeferred update – the No-UNDO/REDO algorithm

• Immediate update – the UNDO/REDO algorithmImmediate update – the UNDO/REDO algorithm