• 검색 결과가 없습니다.

CHAPTER 15

N/A
N/A
Protected

Academic year: 2022

Share "CHAPTER 15"

Copied!
33
0
0

로드 중.... (전체 텍스트 보기)

전체 글

(1)

Intro to DB

CHAPTER 15

TRANSACTION MNGMNT

(2)

Chapter 15: Transactions

ƒ Transaction Concept

ƒ Transaction State

ƒ Implementation of Atomicity and Durability

ƒ Concurrent Executions

ƒ Serializability

ƒ Recoverability

ƒ Implementation of Isolation

ƒ Testing for Serializability

(3)

Transactions

ƒ What is a transaction?

à Logical unit of work (user view)

à A program unit that accesses and possibly updates various p g p y p data items (system view)

DBMS i i (ACID i )

à DBMS must guarantee certain properties (ACID properties) for units of works declared as a DB transaction

(4)

Examples of Transactions

ƒ Banks

à Withdraw $100 to account A.

à Transfer $50 from account A to B.

ƒ Schools

à Register course #409.433 for student #4321.g

ƒ Airlines

à Check if two seats are available on flight #453Check if two seats are available on flight #453.

à Reserve the two seats on flight #453.

ƒ Companies

ƒ Companies

à Increase every employee’s salary by 5%.

(5)

Dangers for Transactions

ƒ Various types of failure

à system crash

à disk failure

à system error

ƒ Delayed disk write y

à disk access is performed in chunks: page (block)

à i.e., write operation performed after the right amount of data , p p g has been gathered

à buffer manager may pin a page

(6)

Properties of a Transaction

ACID properties

ƒ Atomicity

“all or nothing”

ƒ Consistency (Correctness)

Move from a consistent state to another consistent state Move from a consistent state to another consistent state

ƒ Isolation

Should not be interfered by other transactions (concurrency) Should not be interfered by other transactions (concurrency)

ƒ Durability

The effect of a completed transaction should be durable &

public

(7)

Atomicity

ƒ All or nothing

“ ”

Transfer $50 from account A to account B

Begin transaction

Roll back

read(A,a) a = a-50

i ( )

crash

write(A,a) read(B,b) b = b+50

Roll forward

b = b+50 write(B,b) End Transaction End Transaction

(8)

Consistency

ƒ Move from a consistent state to another consistent state

Withdraw $100 from account A

Begin transaction read(A,a) a = a-100

write(A,a) What if A only had $20?

End Transaction

ƒ Responsibility of programmer

(9)

Isolation

ƒ Should not be interfered by other transactions (concurrency)

Transaction T1

Begin transaction

Transaction T2

Begin transaction Begin transaction

read(A,a1) a1 = a1-50

Begin transaction read(A,a2)

a2 = a2-100 write(A,a1)

read(B,b1) b1 = b1+50

a2 a2 100 write(A,a2) End Transaction write(B,b1)

End Transaction

ƒ Serial Execution VS Concurrent Execution

(10)

Durability

ƒ The effect of a completed transaction should be durable &

p blic public

Wi hd $100 f A

Withdraw $100 from account A

Begin transactiong read (A,a) a = a-100 a a 100 write(A,a) End Transaction

...

*buffer flush*

crash

(11)

Transaction States

ll committed

partially  committed

i active

aborted failed

(12)

Transaction States

(Cont.)

ƒ Active: the initial state, transaction stays in this state while it is e ec ting

executing

ƒ Partially committed: the final statement has been executed

F il d l i l d

ƒ Failed: normal execution can no longer proceed

ƒ Aborted: transaction has been rolled back and the database t d t it t t i t th t t f th t ti

restored to its state prior to the start of the transaction.

à Two options after it has been aborted:

‚ restart the transaction – only if no internal logical errorrestart the transaction only if no internal logical error

‚ kill the transaction

ƒ Committed: after successful completion.

(13)

Implementation of Atomicity and Durability

ƒ The recovery-management component of a database system implements the s pport for atomicit and d rabilit

implements the support for atomicity and durability.

ƒ The shadow-database scheme:

à ass me that only one transaction is active at a time à assume that only one transaction is active at a time.

à a pointer called db_pointer always points to the current consistent copy of the database.

à all updates are made on a shadow copy of the database, and db_pointer is made to point to the updated shadow copy only after the transaction reaches partial commit and all updated pages have been flushed to disk reaches partial commit and all updated pages have been flushed to disk.

à in case transaction fails, old consistent copy pointed to by db_pointer can be used, and the shadow copy can be deleted.

(14)

The Shadow Database Scheme

ƒ Assumes disks to not fail

ƒ Useful for text editors, but extremely inefficient for large

databases: executing a single transaction requires copying the entire database

entire database.

ƒ Will see better schemes in Chapter 17. (Log-based schemes)

(15)

Concurrent Executions

ƒ Multiple transactions are allowed to run concurrently in h

the system

à increased processor and disk utilization

à reduced average response time

ƒ Concurrency control schemes – mechanisms to achieve y isolation

à to control the interaction among the concurrent transactions g in order to prevent them from destroying the consistency of the database

à (Chapter 16)

(16)

Schedules

ƒ Schedules

à sequences that indicate the chronological order in which instructions of concurrent transactions are executed

à a schedule for a set of transactions must consist of all instructions of those transactions

h d i hi h h i i i

à must preserve the order in which the instructions appear in each individual transaction.

(17)

Example Schedules

ƒ Let T1 transfer $50 from A to B and T transfer 10% of the B, and T2 transfer 10% of the balance from A to B.

ƒ The following is a serial

ƒ The following is a serial schedule in which T1 is followed by Ty 22.

(18)

Example Schedule

(Cont.)

ƒ Let T1 and T2 be the transactions defined transactions defined previously.

ƒ Schedule 3 is not a serial

ƒ Schedule 3 is not a serial schedule, but it is equivalent to Sch.1.

ƒ In both Schedule 1 and 3, the sum , A+B is preserved.

Schedule 3 (fig 15.5)

(19)

Example Schedules

(Cont.)

ƒ Schedule 4 does not preserve the value of the the sum A + the value of the the sum A + B.

(20)

Serializability

ƒ Basic Assumption – Each transaction preserves database consistenc

consistency.

à Thus serial execution of a set of transactions preserves database consistency.y

ƒ A (possibly concurrent) schedule is serializable if it is equivalent to a serial schedule.

1. conflict serializability

2. view serializability (not covered in this semester)

ƒ We ignore operations other than read and write instructions.

(21)

A Serializable Schedule

(22)

Implementation of Isolation

(from Chap 16)

ƒ Schedules must be serializable and recoverable (for database consistenc )

consistency)

à and preferably cascadeless

ƒ A policy in which only one transaction can execute at a time

ƒ A policy in which only one transaction can execute at a time generates serial schedules, but provides a poor degree of concurrency.y

ƒ Concurrency-control schemes tradeoff between the amount of concurrency they allow and the amount of overhead that they incur.

(23)

Lock-Based Protocols

(from Chap 16)

ƒ A lock is a mechanism to control concurrent access to a data item

item

ƒ Two modes :

1 l i (X) d b h d d i

1. exclusive (X) mode: both read and write (lock-X instruction)

2 shared (S) mode: only read

2. shared (S) mode: only read (lock-S instruction)

ƒ Lock requests are made to concurrency-control managerq y g

ƒ Transaction can proceed only after request is granted.

(24)

Granting of Locks

(from Chap 16)

ƒ Lock-compatibility matrix

ƒ A transaction may be granted a lock on an item if the requested lock is compatible with lock(s) already held on the item by other p ( ) y y transactions

ƒ Any number of transactions can hold shared locks on an item

ƒ If any transaction holds an exclusive on the item no other transaction may hold any lock on the item.

(25)

Example (

from Chap 16) T2: lock-S(A);

read (A);

unlock(A);

lock-S(B);

read (B);

unlock(B);

display(A+B)

ƒ Locking as above is not sufficient to guarantee serializability

if A and B get updated in-between the read of A and B, the g p , displayed sum would be wrong.

(26)

Two-Phase Locking Protocol

(from Chap 16)

ƒ Locking Protocol

à A set of rules followed by all transactions while requesting

à A set of rules followed by all transactions while requesting and releasing locks

à Locking protocols restrict the set of possible schedules.

ƒ 2PL

à Phase 1: Growing Phase

b k

‚ transaction may obtain locks

 can acquire a lock-S or lock-X on item

 can convert a lock-S to a lock-X (upgrade)

‚ transaction may not release locks

à Phase 2: Shrinking Phase

‚ transaction may release lockstransaction may release locks

 can release a lock-S or lock-X

 can convert a lock-X to a lock-S (downgrade)

‚ transaction may not obtain locks

‚ transaction may not obtain locks

(27)

Example

(from Chap 16)

(28)

Features of 2PL

(from Chap 16)

ƒ Serializability: the protocol assures (conflict) serializability

à It can be shown that the transactions can be serialized in theIt can be shown that the transactions can be serialized in the order of their lock points (i.e. the point where a transaction acquired its final lock)

acquired its final lock).

à There can be conflict serializable schedules that cannot be obtained if two-phase locking is used

obtained if two phase locking is used

ƒ Deadlocks: Two-phase locking does not ensure freedom from deadlocks

from deadlocks

à starvation also possible

C di llb k i ibl d h l ki

ƒ Cascading rollback: is possible under two-phase locking

(29)

Recoverability

ƒ Need to address the effect of transaction failures on concurrently running transactions

concurrently running transactions

ƒ Recoverable schedule

à if a transaction Tjj reads a data item previously written by a transaction Tp y y ii , , à the commit of Ti appears before the commit of Tj.

ƒ The following schedule (Schedule 11) is not recoverable if T9

i i di l f h d

commits immediately after the read

(30)

Cascading Rollback

ƒ A single transaction failure can lead to a series of transaction rollbacks

rollbacks.

ƒ Example: If T10 fails, T11 and T12 must also be rolled back.

Can lead to the undoing of a significant amount of work

(31)

Cascadeless Schedules

ƒ Cascading rollbacks cannot occur if

f h i f i T d T

à for each pair of transactions Ti and Tj

à such that Tj reads a data item previously written by Ti, à the commit of Tthe commit of Tii appears before the read of Tappears before the read of Tjj

ƒ Every cascadeless schedule is also recoverableEvery cascadeless schedule is also recoverable

ƒ It is desirable to restrict the schedules to those that are

ƒ It is desirable to restrict the schedules to those that are cascadeless

(32)

Strict / Rigorous 2PL

(from Chap 16)

ƒ Strict 2PL

à To avoid cascading roll-back

à A transaction must hold all its exclusive locks until it it / b t

commits/aborts

ƒ Rigorous 2PL

ƒ Rigorous 2PL

à all locks are held until commit/abort

à transactions can be serialized in the order in which they commit

à transactions can be serialized in the order in which they commit

(33)

END OF CHAPTER 15

참조

관련 문서

“Well it‟s a it‟s a it‟s a place and it‟s a g-girl and a boy + and the-they‟ve got obviously something which is made some made made made well it‟s just beginning to go

frequency of the first channel in the group is used as the fundamental frequency for all channels in the group, and all phase measurements are relative to the phase reference

• Changed the name to Clock tool example use case: Configure LPSPI to SPLL BUS_CLK at 48 MHz and peripheral clock at 24MHz FIRC in RUN mode on S32K14x on page 15. •

The “Asset Allocation” portfolio assumes the following weights: 25% in the S&P 500, 10% in the Russell 2000, 15% in the MSCI EAFE, 5% in the MSCI EME, 25% in the

Consider a cross section of large flow through which all streamlines are precisely straight and parallel. i) Forces, normal to the streamlines, on the element of fluid

The purpose of this study is to evaluate the marginal and internal fit of coping made by CAD/CAM using different scanning methods.. Zirconia coping was made

This study, made up of 6 chapters in all, aims to handle the details and problems of the spouse inheritance system under existing law, as well as to review the draft of

- Relate the mixing length to velocity gradient using the similarity rule - Turbulent fluctuations are similar at all point of the field of flow. - Velocity is characteristics