3. 1.1 Transaction
logical unit of work it consist of one or more operations that must be completed
together.It either be successfully complete or fail.
1.1.1 Commit
A transaction is committed if it is completely successful and makes changes in
data.
1.1.2 Rollback
if transaction failed and leave the data unchanged it is said the data has rolled
back.
1.2 Transaction properties(ACID properties)
1.2.1 Atomicity
A transaction must completely succeed or completely fail. If any statement fail
the entire transaction fails completely.
1.2.2 Consistency
After completion the transaction leaves the data in a consistent state. For example
money should never be “created “ or “deleted” without an deposit or withdrawal.
4. 1.2.3 Isolation
All transactions that modify the data are isolated from each other. A modifying
transaction can access the data only after the completion of other transaction
1.2.4 Durability
Durability means that the modifications made by a transaction are permanent
and persistent.
5. 1.3 Concurrency
Concurrency is a situation in which two users access the same piece of data at
the same time. It occurs very commonly but sometimes create some problems.
1.3.1 Lost update problem
Problem arises when two or more transactions update the same data. Each
transaction unaware of other transactions . The last update overwrites.
TIME TEAM A STOCK TABLE TEAM B
9:00 Qty=100
10:30 Retrieve Qty
Qty=100
Retrieve Qty
Qty=100
10:31 Update=Qty-90
10:32 Qty=10
10:33 Update=Qty+30
Qty=130
6. 1.3.2. Uncommitted Dependency Problem
In above example team B update the quantity 100 to 150
at time T1 and team A retrieve this update value at t2.Team
B rollbacks the action while making quantity 100 again .So,
the value of Team A becomes wrong at T3.
TIME TEAM A TEAM B
T1 - Update qty
T2 Retrieve qty -
T3 - Rollback
7. 1.3.3 Inconsistent Analysis Problems
problem occurs when one transaction reading the several values from the
DB but another transaction update these some of them during the executing
of the first transaction.
TIME TEAM A TEAM B
T1 Retrieve acc-1:Sum=40 -
T2 Retrieve acc-2:Sum=90 -
T3 Retrieve acc-3
T4 Update acc-3=0
T5 Retrieve acc-1
T6 Update acc-1=50
T7 Commit
T8 Retrieve acc-3:Sum=90
Three accounts Acc-1:40 Acc-2: 50 Acc-3: 30
8. 1.4 Resource locking
When a user access the data the second user has to wait until the first user
has finishes his work.
For example
USER 1 USER 2
1 Lock the item
2 retrieve the item
3 reduce item by 10
4 update the item
5 unlock the item
1 Lock the item
2 retrieve the item
3 reduce item by 10
4 update the item
5 unlock the item
Sequence of processing commands
by CPU
1 Lock the item user 1
2 retrieve the item user 1
3 lock the item for user 2.
already locked so user 2 has to wait
until user 1 unlock
4 reduce item by 10 for user 1
5 update the item for user 1
6 unlock the item for user 1
7 lock the item for user 2
8 retrieve item for user 2
9 reduce item by 20 for user 2
10 update the item for user 2
11 Unlock the item for user 2
9. 1.4.1 Lock terminology
1. Implicit lock
Type of lock placed automatically by DBMS.
2. Explicit lock
Placed by application program by issuing a command.
3. Exclusive lock
Type of lock that locks item for any type of access no other can read or update.
4. Shared lock
Locks an item from change but not from read is called share lock.
5. Lock Granularity
The level of lock applied on an item is known as lock granularity
Levels
a. Row level(smallest lock granularity)
b. Page level
c. Table level
d. Database level(largest lock granularity)
10. 5. Deadlock
Deadlock is a situation in which two transaction wait for completion of each
other.
USER 1 USER 2
1 Lock item A
2 Retrieve item A
3 Lock the item B
1 Lock item B
2 Retrieve item B
3 Lock the item A
Sequence processing by command in CPU
1 Lock the item A for user 1.
2 Lock the item B for user 2.
3 Retrieve A for user 1.
4 Retrieve item B for user 2.
5 Put user 1 in wait for user 2.
6 Put user 2 in wait for user 1
11. 5.1 Solution of deadlock
1 Deadlock prevention
In this type users allow to issue only one lock request at a time.If user A and B
at once in the first line deadlock will not occurs.
2 Deadlock detection & recovery
If one transaction of user 2 is aborted then the item will be released from the lock
and the user 1 will be able to complete his work.
When a transaction is aborted then all changes made by that transaction should
be undone.
12. 6. Types of Distributed DBMS
6.1 Homogeneous DDBMS
Means that the DB technology is the same or at least compatible to each .
It simplify the data sharing among different users.
Characteristics of Homogeneous DDBMS
i. Data distributed across all the nodes.
ii. The same DBMS used.
iii. All date manage by the DDBMS there is no exclusively local data.
iv. All users access the DB through database definition.
v. The global schema is the union of local DB schemas.
13. 6.2 Heterogeneous DDBMS
Different DBMS used at each node. Much more difficult to manage.
Characteristics of Heterogeneous DDBMS
i. Data distributed across all the nodes.
ii. Different DBMS used at each location.
iii. A global schema exist which allow local user to access the data
iv. Some users require only local access to databases which cab be accomplished
using only local data DBMS and schema.