7.CSI2004-ADBMS Class Module1 Transaction Processing
7.CSI2004-ADBMS Class Module1 Transaction Processing
Management Systems
Transaction Processing
Transaction Concept
Transaction manager
Transaction processing monitor
TP monitor
Commit
Rollback
Transaction Concept
BEGIN TRANSACTION;
UPDATE ACC 123 { BAL:=BAL-$100 };
IF any arror occurred THEN
GO TO UNDO;
END IF;
UPDATE ACC 456 { BAL:=BAL+$100 };
IF any error occurred THEN
GO TO UNDO;
END IF;
COMMIT;
GO TO FINISH;
UNDO:
ROLLBACK;
FINISH:
RETURN;
ACID Properties
ACID Properties
To preserve integrity of data, the database system must ensure:
Atomicity. Either all operations of the transaction are
properly reflected in the database or none are.
Consistency. Execution of a transaction in isolation
preserves the consistency of the database.
Isolation. Although multiple transactions may execute
concurrently, each transaction must be unaware of other
concurrently executing transactions. Intermediate
transaction results must be hidden from other concurrently
executed transactions.
That is, 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.
Durability. After a transaction completes successfully,
the changes it has made to the database persist, even if
there are system failures.
Example of Fund Transfer
Transaction to transfer $50 from account A to account
B:
1. read(A)
2. A := A – 50
3. write(A)
4. read(B)
5. B := B + 50
6. write(B)
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.
Consistency requirement – the sum of A and B is
unchanged by the execution of the transaction.
Example of Fund Transfer
Isolation requirement — if between steps 3 and 6,
another transaction is allowed to access the partially
updated database, it will see an inconsistent database
(the sum A + B will be less than it should be).
Can be ensured trivially by running transactions serially,
that is one after the other. However, executing multiple
transactions concurrently has significant benefits.
Durability requirement — once the user has been
notified that the transaction has completed (i.e., the
transfer of the $50 has taken place), the updates to the
database by the transaction must persist despite failures.
Transaction States
Transaction States
Transaction States
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 back and
the database 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 error
kill the transaction
Committed, after successful completion.
Transaction Processing - Problems
Transaction Processing Systems
Transaction processing systems are systems with
large databases and hundreds of concurrent users
executing database transactions.
19
The Temporary Update (or Dirty Read) Problem
Four possibilities
RR noproblem
RW nonrepeatable read
inconsistent analysis problem
WR dirty read
uncommitted dependency problem
WW dirty write
The lost update problem
Schedules
Schedules
Schedule – a sequence of instructions that specify 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.
A transaction that successfully completes its execution
will have a commit instructions as the last statement
by default transaction assumed to execute commit
instruction as its last step
A transaction that fails to successfully complete its
execution will have an abort instruction as the last
statement
Schedule 1
T1 transfer $50 from A to B
T2 transfer 10% of the balance from A to B.
A serial schedule in which T1 is followed by T2 :
Let A=$1000
B=$2000
Before transaction
A+B=$3000
A=$855
B=$2145
After transaction
A+B=$3000
Schedule 2
Before transaction
A+B=$3000
After transaction
A+B=$3000
Schedule 3
Let T1 and T2 be the transactions defined previously. The
following schedule is not a serial schedule, but it is
equivalent to Schedule 1.
A=$855
B=$2145
Before transaction
A+B=$3000
After transaction
A+B=$3000
A=$950
B=$2100
Before transaction
A+B=$3000
After transaction
A+B=$3050
Schedules based on Serializability
Serializable Schedule
Schedule:
Set of instructions
Serial schedule Executing the transactions one
at a time with no interleaving
Interleaved schedule Non serial schedule
Equivalent schedule Two schedules are
equivalent if and only if, no matter what the initial
state of the database, they are guaranteed to
produce the same result as each other
Serializable:
A given execution of a given set of transactions is
serializable, if and only if it is equivalent to
some serial execution of the same transaction
Serializable Schedule
T1 T2
T2 T1
Schedule 3 Schedule 6
Conflict Serializability
Example of a schedule that is not conflict serializable:
T1 T2 T3
R1(A)
R2(A)
R1(B)
R2(B)
R3(B)
W1(A)
W2(B)
EXAMPLE
Steps:
R2(X) , W3(X)
R2(X) , W1(X)
W3(X) , W1(X)
W3(X) , R4(X)
W1(X) , R4(X)
W2(Y) , R4(Y)
EXAMPLE
Check whether the given schedule S is conflict serializable or no
Solution
1. List all the conflicting operations
R2(X) , W3(X)
R2(X) , W1(X)
W3(X) , W1(X)
W3(X) , R4(X)
W1(X) , R4(X)
W2(Y) , R4(Y)
2. Determine the dependency between the transactions-
R2(X) , W3(X) (T2 → T3)
R2(X) , W1(X) (T2 → T1)
W3(X) , W1(X) (T3 → T1)
W3(X) , R4(X) (T3 → T4)
W1(X) , R4(X) (T1 → T4)
W2(Y) , R4(Y) (T2 → T4)
3. Draw the precedence graph
EXAMPLE
Check whether the given schedule S is conflict serializable or no
Solution
1. List all the conflicting operations
R2(X) , W3(X)
R2(X) , W1(X)
W3(X) , W1(X)
W3(X) , R4(X)
W1(X) , R4(X)
W2(Y) , R4(Y)
2. Determine the dependency between the transactions-
R2(X) , W3(X) (T2 → T3)
R2(X) , W1(X) (T2 → T1)
W3(X) , W1(X) (T3 → T1)
W3(X) , R4(X) (T3 → T4)
W1(X) , R4(X) (T1 → T4)
W2(Y) , R4(Y) (T2 → T4) There exists no cycles in the precedence
3. Draw the precedence graph graph. So, the given schedule S is conflict
serializable