transaction management

Post on 23-Jan-2016

51 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

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

Transaction Management

by Benjamin Nguyen

Overview

• Transaction

• Properties of transaction

• Pessimistic & optimistic techniques– Locking– No lock techniques

• Oracle recovery tools

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

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.

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)

Over view of Database

Pessimistic & Optimistic techniques

• Pessimistic– Check for conflict when read/write

• Optimistic– Only check for conflict when the transaction

wishes to commit

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

Optimistic Techniques

Read Validation

commit

write

Read phase Write phase

Read phase

• Extends from start of transaction to just before commit

• Read from database

• Store in local variable

Validation phase

• Follow the read phase

• Purpose is to ensure that data is still current.

Write phase

• Follow after validation

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

Pessimistic techniques

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

The lost update problem

T1 T2

balx = $0 balx = $100

The lost update problem

T1 T2

balx = $100 balx = $200

The lost update problem

T1 T2

balx = $90 balx = $200

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

The uncommitted dependency (or dirty read) problem

T3Balx should be $90

The inconsistent analysis problem

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.

Serializability

Serial

Not serial

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

Serialiability (cont.)

• 2 types of serializability:

– Conflict serializability– Non-conflict serializable

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

Precedence graph

T9 T10

Step 1

Precedence graph

T9 T10

Rule 2

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

Precedence graph

T9 T10

Rule 2

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

Precedence graph (cont.)

T7 T8

Rule2

Precedence graph (cont.)

T7 T8

Rule2

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

Example of Lock

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

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)

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

Wait-for graph (WFG)

T17 T18

X Y

lock

Wait-for graph (WFG)

T17 T18

X Y

locklock

Wait-for graph (WFG)

T17 T18

X Y

locklock

Wait-for graph (WFG)

T17 T18

X Y

locklock

Recovery

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

Types of media

Degree of reliability

Optical diskMagnetic tapeMagnetic diskMain memory

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

Recovery (cont.)

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

event of the primary database failing

End!

top related