+ All Categories
Home > Documents > Transaction Processing Concepts

Transaction Processing Concepts

Date post: 25-Feb-2016
Category:
Upload: efrem
View: 78 times
Download: 4 times
Share this document with a friend
Description:
Transaction Processing Concepts. 1. Introduction To transaction Processing. 1.1 Single User VS Multi User Systems One criteria to classify Database is according to number of user that concurrently connect to the system. Single User: only one user use the system in each time - PowerPoint PPT Presentation
36
Transaction Processing Concepts
Transcript
Page 1: Transaction Processing Concepts

Transaction Processing Concepts

Page 2: Transaction Processing Concepts

1. Introduction To transaction Processing

• 1.1 Single User VS Multi User Systems– One criteria to classify Database is according to

number of user that concurrently connect to the system.

• Single User: only one user use the system in each time• Multi User: many users use the system in the same

time

Page 3: Transaction Processing Concepts

What is a Transaction?

• A transaction is a unit of program execution that accesses and possibly updates various data items.

• A transaction must see a consistent database.

• During transaction execution the database may be inconsistent.

• When the transaction is committed, the database must be consistent.

Page 4: Transaction Processing Concepts

– Transaction is an executing program that forms a logical unit of database processing.

– A transaction include one or more database access operations.– The database operation can be embedded within an

application or can be specified by high level query language.

– Specified boundary by Begin and End transaction statements

– If the database operations in a transaction do not update the database, it is called “Read-only transaction”

Page 5: Transaction Processing Concepts

Example of transaction

• Let Ti be a transaction that transfer money from account A (5000) to account B. The transaction can be defined as

– Ti: read (A) (withdraw from A)A := A – 5000write (A); (update A)read (B) (deposit B)B := B + 5000write (B) (update B)

Page 6: Transaction Processing Concepts

Example Of Transfer• Transaction to transfer 5000 from Checking account A to Saving account

B:1. read(A)2. A := A – 50003. write(A)4. read(B)5. B := B + 50006. write(B)

• Consistency requirement – the sum of A and B is unchanged by the execution of the transaction.

• Atomicity requirement — if the transaction fails after step 3 and before step 6, the system should ensure that its updates are not reflected in the database, else an inconsistency will result.

Page 7: Transaction Processing Concepts

Transfer Example (Cont.)

• Durability requirement — once the user has been notified that the transaction has completed (i.e., the transfer of the 5000 has taken place), the updates to the database by the transaction must persist despite failures.

• Isolation requirement — if between steps 3 and 6, another transaction is allowed to access the partially updated database, it will see an inconsistent database.

Page 8: Transaction Processing Concepts

Desirable properties of transaction : ACID properties

• To ensure integrity of data, we require that the database system maintain the following properties of the transactions:

– Atomicity.

– Consistency preservation.

– Isolation.

– Durability or permanency.

Page 9: Transaction Processing Concepts

ACID• Atomicity. Either all operations of the transaction are reflected properly in

the database, or none are.

• Consistency. Execution of a transaction in isolations (that is, with no other transaction executing concurrently)

• Isolation. Even though multiple transactions may execute concurrently, the system guarantees that, for every pair of transactions Ti and Tj, it appears to Ti that – either Tj finished execution before Ti started, – or Tj started execution after Ti finished. – Thus, each transaction is unaware of other transactions executing concurrently in

the system.(Execution of transaction should not be interfered with by any other transactions executing concurrently)

• Durability. After a transaction completes successfully, the changes it has made to the database persist, even if there are system failures. (The changes must not be lost because of any failure)

Page 10: Transaction Processing Concepts

Consistency• Consistency.

– The consistency requirement here is that the sum of A and B be unchanged by the execution of the transaction.

– Without consistency requirement, money could be created or destroyed by the transaction.

– It can be verified, • If the database is consistency before an execution of the

transaction, the database remains consistent after the execution of the transaction.

Page 11: Transaction Processing Concepts

Atomicity

• Atomicity. Either all operations of the transaction are reflected properly in the database, or none are.– State before the execution of transaction Ti

• The value of A = 50,000• The value of B = 100

– Failure occur (ex. Hardware failure)• Failure happen after the WRITE(A) operation• (at this moment A = 50000 – 5000 = 45000)• And the value of B = 100 (inconsistency state)• In consistency state A = 45000 and B = (5100)

Page 12: Transaction Processing Concepts

(cont.)

– Idea behind ensuring atomicity is following: • The database system keeps track of the old values of

any data on which a transaction performs a write • If the transaction does not complete, the DBMS

restores the old values to make it appear as though the transaction have never execute.

Page 13: Transaction Processing Concepts

Durability or permanency

• Durability or permanency. After a transaction completes successfully, the changes it has made to the database persist, even if there are system failures.

• These changes must not be lost because of any failure• ensures that, transaction has been committed, that

transaction’s updates do not get lost, even if there is a system failure

Page 14: Transaction Processing Concepts

Isolation

• Isolation. Even though multiple transactions may execute concurrently, the system guarantees that, • for every pair of transactions Ti and Tj, • it appears to Ti that either Tj finished execution before Ti

started, • or Tj started execution after Ti finished. • Thus, each transaction is unaware of other transactions

executing concurrently in the system. • ( Execution of transaction should not be interfered

with by any other transactions executing concurrently )

Page 15: Transaction Processing Concepts

State of transaction• Active, the initial state; the transaction stays in this state

while it is executing.• Partially committed, after the final statement has been

executed• Failed, after the discovery that normal execution can no

longer proceed.• Aborted, after the transaction has been rolled backed and the

database has been restored to its state prior to the start of transaction.

• Committed, after successful completion

Page 16: Transaction Processing Concepts

State diagram of a transition

A transaction must be in one of these states.

Partially Committed

Aborted(Terminate)

Active

BeginTransaction

ReadWrite

Abort

Failed

Abort

committedCommit

Page 17: Transaction Processing Concepts

• The transaction has committed only if it has entered the committed state.

• The transaction has aborted only if it has entered the aborted state.

• The transaction is said to have terminated if has either committed or aborted.

Page 18: Transaction Processing Concepts

Concurrency Control

Page 19: Transaction Processing Concepts

Concurrent Executions

• Transaction processing permit– Multiple transactions to run concurrently.– Multiple transactions to update data concurrently

• Cause– Complications with consistency of data

Page 20: Transaction Processing Concepts

Reason for allowing concurrency

• Improved throughput of transactions and system resource utilization

• Reduced waiting time of transactions

Page 21: Transaction Processing Concepts

Concurrent Executions

• Multiple transactions are allowed to run concurrently in the system. Advantages are:– increased processor and disk utilization, leading to better

transaction throughput: one transaction can be using the CPU while another is reading from or writing to the disk

– reduced waiting time for transactions: short transactions need not wait behind long ones.

Page 22: Transaction Processing Concepts

Possible Problems

• Lost update problem• Temporary update problem• Incorrect summary problem

Page 23: Transaction Processing Concepts

Lost update problemT1 T2

Read_item(A) A := A – 50 Read_item(A)

temp := 0.1*A A:= A-temp

Write_item(A)Read_item(B)

Write_item(A) Read_item(B)

B := B + 50Write_item(B)

B := B + temp Write_item(B)

A = 1000, B =2000

A = 950A = 950

temp = 95

A=950-95 = 855A = 950

B = 2000A = 855

B = 2000B = 2050

B = 2050B = 2095

B = 2095

A = 1000

Page 24: Transaction Processing Concepts

Temporary update problem

T1 T2

- Write_item(R)

Read_item(R) -

- RollBack

R = 1000

R = 1000

R = 3000

R = 3000

Page 25: Transaction Processing Concepts

Inconsistency problem

T1 T2Read_item(A) SUM = Sum+A Read_item(B) SUM = A + B Read_item(C)

C = C - 10Write_item(C)

Read_item(A)A = A + 10Write_item(A)

COMMITRead_item(C)SUM = SUM + C

A = 40 , B = 50, C = 30

A = 40

Sum = 40

B = 50

SUM = 40+50 = 90

C = 30

C = 30-10 =20

C = 20

A = 40A = 40+10 =50

A = 50

C = 20

Sum = 90 + 20 = 110

A+B+C = 40+50+30 = 120

AfterA+B+C = 50+50+20 = 120

Page 26: Transaction Processing Concepts

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– must preserve the order in which the instructions appear in each

individual transaction.

Page 27: Transaction Processing Concepts

Example Schedules

• Let T1 transfer $50 from A to B, and T2 transfer 10% of the balance from A to B. The following is a serial schedule (Schedule 1 in the text), in which T1 is followed by T2.

Page 28: Transaction Processing Concepts

Cont.

• Let T1 and T2 be the transactions defined previously. The following schedule is not a serial schedule, but it is equivalent to Schedule 1.

Page 29: Transaction Processing Concepts

Cont.

• The following concurrent schedule does not preserve the value of the the sum A + B.

Page 30: Transaction Processing Concepts

Serializability

• Basic Assumption – Each transaction preserves database consistency.

• Thus serial execution of a set of transactions preserves database consistency.

• A (possibly concurrent) schedule is serializable if it is equivalent to a serial schedule. Different forms of schedule equivalence give rise to the notions of:1. conflict serializability2. view serializability

Page 31: Transaction Processing Concepts

Conflict Serializability

• Instructions li and lj of transactions Ti and Tj respectively, conflict if and only if there exists some item Q accessed by both li and lj, and at least one of these instructions wrote Q.1. li = read(Q), lj = read(Q). li and lj don’t conflict.2. li = read(Q), lj = write(Q). They conflict.3. li = write(Q), lj = read(Q). They conflict4. li = write(Q), lj = write(Q). They conflict

Page 32: Transaction Processing Concepts

Conflict Serializability (Cont.)• If a schedule S can be transformed into a schedule S´ by a series of swaps

of non-conflicting instructions, we say that S and S´ are conflict equivalent.

• We say that a schedule S is conflict serializable if it is conflict equivalent to a serial schedule

• Example of a schedule that is not conflict serializable:T3 T4

read(Q)write(Q)

write(Q)

We are unable to swap instructions in the above schedule to obtain either the serial schedule < T3, T4 >, or the serial schedule < T4, T3 >.

Page 33: Transaction Processing Concepts

Conflict Serializability (Cont.)

• Schedule 3 below can be transformed into Schedule 1, a serial schedule where T2 follows T1, by series of swaps of non-conflicting instructions. Therefore Schedule 3 is conflict serializable.

Page 34: Transaction Processing Concepts

View Serializability• Let S and S´ be two schedules with the same set of transactions. S and S´

are view equivalent if the following three conditions are met:1. For each data item Q, if transaction Ti reads the initial value of Q in

schedule S, then transaction Ti must, in schedule S´, also read the initial value of Q.

2. For each data item Q if transaction Ti executes read(Q) in schedule S, and that value was produced by transaction Tj (if any), then transaction Ti must in schedule S´ also read the value of Q that was produced by transaction Tj .

3. For each data item Q, the transaction (if any) that performs the final write(Q) operation in schedule S must perform the final write(Q) operation in schedule S´.

As can be seen, view equivalence is also based purely on readsand writes alone.

Page 35: Transaction Processing Concepts

View Serializability (Cont.)

• A schedule S is view serializable it is view equivalent to a serial schedule.• Every conflict serializable schedule is also view serializable.• Schedule 9 (from text) — a schedule which is view-serializable but not

conflict serializable.Every view serializable schedule that is not conflict serializable has blind writes.

Page 36: Transaction Processing Concepts

Recommended