transaction management

43
Transaction Management by Benjamin Nguyen

Upload: zora

Post on 23-Jan-2016

51 views

Category:

Documents


0 download

DESCRIPTION

Transaction Management. by Benjamin Nguyen. Overview. Transaction Properties of transaction Pessimistic & optimistic techniques Locking No lock techniques Oracle recovery tools. Transaction. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Transaction Management

Transaction Management

by Benjamin Nguyen

Page 2: Transaction Management

Overview

• Transaction

• Properties of transaction

• Pessimistic & optimistic techniques– Locking– No lock techniques

• Oracle recovery tools

Page 3: Transaction Management

Transaction

• An action, or series of actions, carried out by a single user or application program, which reads or updates the contents of the database

Page 4: Transaction Management

Properties of Transaction

• ACID– Atomicity: ‘all or nothing’ property.

(Responsible by DBMS recovery subsystem)

– Consistency: database must be transform from one consistent state to another consistent state.

Page 5: Transaction Management

Properties of Transaction (cont.)

• ACID– Isolation: transaction execute independently of one

another. (Responsible by concurrency control)

– Durability: The effects of a successfully completed (committed) transaction are permanently recorded in the database and must not be lost because of a subsequent failure (Responsible by recovery subsystem)

Page 6: Transaction Management

Over view of Database

Page 7: Transaction Management

Pessimistic & Optimistic techniques

• Pessimistic– Check for conflict when read/write

• Optimistic– Only check for conflict when the transaction

wishes to commit

Page 8: Transaction Management

Pessimistic & Optimistic techniques

• Pessimistic– Using locking techniques

• Optimistic– The concurrency control that does not use

lock and it involve the following phases:• Read phase• Validation phase• Write phase

Page 9: Transaction Management

Optimistic Techniques

Read Validation

commit

write

Read phase Write phase

Page 10: Transaction Management

Read phase

• Extends from start of transaction to just before commit

• Read from database

• Store in local variable

Page 11: Transaction Management

Validation phase

• Follow the read phase

• Purpose is to ensure that data is still current.

Page 12: Transaction Management

Write phase

• Follow after validation

• Updated variable from local variable can now be applied to database

Page 13: Transaction Management

Pessimistic techniques

• Using locking technique to reduce conflict and ensure data consistency.– The lost update problem

Page 14: Transaction Management

The lost update problem

T1 T2

balx = $0 balx = $100

Page 15: Transaction Management

The lost update problem

T1 T2

balx = $100 balx = $200

Page 16: Transaction Management

The lost update problem

T1 T2

balx = $90 balx = $200

Page 17: Transaction Management

The lost update problem

T1 T2

balx = $90 balx = $200

bal should be = (100+100 -10) = $190

Since T1 committed after T2, it written over the value of T2

Page 18: Transaction Management

The uncommitted dependency (or dirty read) problem

T3Balx should be $90

Page 19: Transaction Management

The inconsistent analysis problem

Page 20: Transaction Management

How to deal with these problem?

• Serial schedule– A schedule where the operations of each transaction

are executed consecutively without any interleaved operations from the other transaction

• Locking technique– A procedure used to control concurrent access to

data. When one transaction is accessing the database, a lock may deny access to other transactions to prevent incorrect results.

Page 21: Transaction Management

Serializability

Serial

Not serial

Page 22: Transaction Management

Serializability (cont.)

• The objective of serializability is to find nonserial schedules that allow transactions to execute concurrently without interfering with one another– Ex:

• two transaction that read data only• Two transaction that read or update separate data

item

Page 23: Transaction Management

Serialiability (cont.)

• 2 types of serializability:

– Conflict serializability– Non-conflict serializable

Page 24: Transaction Management

Rules for constructing precedence (or serialization) graph

1. Create a node for each transaction

Create a directed edge Ti->Tj if 2. Tj reads the value of an item written by Ti

3. Tj writes a value into an item after it has been read by Ti

4. Tj writes a value into an item after it has been written by Tj

Page 25: Transaction Management

Precedence graph

T9 T10

Step 1

Page 26: Transaction Management

Precedence graph

T9 T10

Rule 2

Create a directed edge Ti->Tj, if Tj reads the value of an item written by Ti

Page 27: Transaction Management

Precedence graph

T9 T10

Rule 2

Create a directed edge Ti->Tj, if Tj reads the value of an item written by Ti

Page 28: Transaction Management

Precedence graph (cont.)

T7 T8

Rule2

Page 29: Transaction Management

Precedence graph (cont.)

T7 T8

Rule2

Page 30: Transaction Management

Lock

• 2 types of Lock:– Shared lock (read only lock)

• If a transaction has a shared lock on a data item, it can read the item but not update it.

– Exclusive lock (read/update lock)• If a transaction has an exclusive lock on a data

item, it can both read and update the item

Page 31: Transaction Management

Example of Lock

Page 32: Transaction Management

Deadlock

• An impasse that may result when two (or more) transactions are each waiting for locks to be released that are held by the other

Page 33: Transaction Management

How to handle deadlock

• 3 methods– Timeouts– Deadlock prevention (not very popular

because it is too complicated)• Wait-die• Wound-wait

– Deadlock detection (using wait-for graph)

Page 34: Transaction Management

Rules to construct wait-for graph

1. Create a node for each transaction

2. Create a directed edge Ti->Tj, if transaction Ti is waiting to lock an item that is currently locked by Tj

Page 35: Transaction Management

Wait-for graph (WFG)

T17 T18

X Y

lock

Page 36: Transaction Management

Wait-for graph (WFG)

T17 T18

X Y

locklock

Page 37: Transaction Management

Wait-for graph (WFG)

T17 T18

X Y

locklock

Page 38: Transaction Management

Wait-for graph (WFG)

T17 T18

X Y

locklock

Page 39: Transaction Management

Recovery

• Generally there are four different types of media that can be use for storage– Main memory– Magnetic disk– Magnetic tape– Optical disk

Page 40: Transaction Management

Types of media

Degree of reliability

Optical diskMagnetic tapeMagnetic diskMain memory

Page 41: Transaction Management

Recovery (cont.)

• Oracle provides various tools for system recovery– Recovery manager

• Provide you with way to create back up of your data

• Help you restore you data incase of failure

– Instance recover• After a crash, Oracle use the information in the

control file to recover the database to the consistent state before the crash

Page 42: Transaction Management

Recovery (cont.)

– Standby database• Allow a standby database to be maintained in the

event of the primary database failing

Page 43: Transaction Management

End!