Unit -4 - part 1
Unit -4 - part 1
UNIT – IV
Slide 1- 1
Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe
What is ATM Transaction?
Transaction processing systems are systems with large databases and hundreds
of concurrent users executing database transactions.
Examples of such systems include
Banking, credit card processing, online retail purchasing and stock markets
It is multiuser if many users can use the system— and hence access the
database—concurrently.
For example,
an airline reservations system is used by hundreds of users and travel agents
concurrently.
Database systems used in banks, insurance agencies, stock exchanges,
supermarkets, and many other applications are multiuser systems.
In these systems,
database processing.
A transaction is an action or series of actions by a single user to perform
Solution:
The first operation reads X's value from database and stores it in a buffer.
The second operation will decrease the value of X by 500. So buffer will
contain 3500.
The third operation will write the buffer's value to the database. So X's final
value will be 3500.
For example: If in the above transaction, the debit transaction fails after
executing operation 2 then X's value will remain 4000 in the database which is
not acceptable by the bank.
interactively
embedded within a program (most transactions)
It states that all operations of the transaction take place at once if not, the
transaction is aborted.
There is no midway, i.e., the transaction cannot occur partially.
Each transaction is treated as one unit and either run to completion or is not
executed at all.
Example: Let's assume that following transaction T consisting of T1 and T2. A consists
of Rs 600 and B consists of Rs 300. Transfer Rs 100 from account A to account B.
T1 T2
Read(A) Read(B)
A:= A-100 Y:= Y+100
Write(A) Write(B)
The integrity constraints are maintained so that the database is consistent before
and after the transaction.
The execution of a transaction will leave a database in either its prior stable
state or a new stable state.
The consistent property of database states that every transaction sees a
consistent database instance.
The transaction is used to transform the database from one consistent state to
another consistent state.
For example: The total amount must be maintained before or after the
transaction.
It shows that the data which is used at the time of execution of a transaction
cannot be used by the second transaction until the first one is completed.
Example:
In isolation, if the transaction T1 is being executed and using the data item
X, then that data item can't be accessed by any other transaction T2 until the
transaction T1 ends.
The concurrency control subsystem of the DBMS enforced the isolation
property.
In the partially committed state, a transaction executes its final operation, but
the data is still not saved to the database.
In the total mark calculation example, a final display of the total marks step is
executed in this state.
Committed
A transaction is said to be in a committed state if it executes all its operations
successfully.
In this state, all the effects are now permanently saved on the database system.
If any of the checks made by the database recovery system fails, then the
transaction is said to be in the failed state.
In the example of total mark calculation, if the database is not able to fire a
query to fetch the marks, then the transaction will fail to execute.
If any of the checks fail and the transaction has reached a failed state then the
database recovery system will make sure that the database is in its previous
consistent state. If not then it will abort or roll back the transaction to bring the
database into a consistent state.
If the transaction fails in the middle of the transaction then before executing the
transaction, all the executed transactions are rolled back to its consistent state.
After aborting the transaction, the database recovery module will select one of
the two operations:
Re-start the transaction
Uncommitted dependency
Incorrect analysis.
Transaction 2
UPDATE accounts SET balance = balance * 0.005;
We'll summarize their interactions with the DBMS in the following form:
Schedule S:
r1(A), r2(A), w1(A), w2(A), r2(B), w2(B)
If account A starts with $200
If account B starts with $100
We can trace what would happen with Schedule S.
Schedule S is very bad! (At least, it's bad if you're the bank!)
We withdrew $100 from account A,
But somehow the database has recorded that our account now holds $201.
Serial schedule
Our idea is a serial schedule, in which all operations by a transaction are
grouped together.
For our two transactions, • There are only two ways to arrange their operations
to get a serial schedule:
Serial schedule
Problem :
In practice, a serial schedule isn't realistic, because it means we must wait for
one transaction to complete before starting another.
Solution:
We would really prefer to interleave them — but we need to interleave the
transactions so that they work the same as some serial schedule.
serializable schedule
As an example, consider Schedule T, which has swapped the third and
fourth operations from S:
•
Schedule T: r1(A), r2(A), w2(A), w1(A), r2(B), w2(B)
Now, when these two relations are joined on the common column "EMP_ID",
then the resultant relation will look like:
Employee ⋈ Department