0% found this document useful (0 votes)
33 views

Transactions and Concurrency Control: Lecturer: Assistant Pro. Aslamzai Prepared By: Nazifa Kazimi Attendance #: 41

The document discusses transactions, distributed transactions, concurrency, and concurrency control techniques. It defines transactions as sequences of instructions that execute atomically and outlines the ACID properties. Distributed transactions can update multiple database sites and require techniques like two-phase commit to ensure atomicity. Concurrency control aims to enforce isolation and consistency when transactions execute concurrently through locking and timestamp-based approaches.

Uploaded by

sebghat aslamzai
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views

Transactions and Concurrency Control: Lecturer: Assistant Pro. Aslamzai Prepared By: Nazifa Kazimi Attendance #: 41

The document discusses transactions, distributed transactions, concurrency, and concurrency control techniques. It defines transactions as sequences of instructions that execute atomically and outlines the ACID properties. Distributed transactions can update multiple database sites and require techniques like two-phase commit to ensure atomicity. Concurrency control aims to enforce isolation and consistency when transactions execute concurrently through locking and timestamp-based approaches.

Uploaded by

sebghat aslamzai
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 30

1

Transactions and
Concurrency Control (CH16)
Lecturer: Assistant pro. Aslamzai

Prepared by: Nazifa Kazimi


Attendance #: 41
2
Outlines
• What is Transaction?
• ACID properties
• Distributed Transaction
• What is Concurrency?
• Schedule
• Concurrency control
Locking
• Failure model
• Deadlock
• Deadlock Prevention
3
Transaction
• Process is simply a set of instruction, some may execute some may
not execute, there may be a scope of failure.
• Even though we don’t rollback the entire process
• Transaction: In Database a sequence of instructions is process but it
become transaction when it performs a logical work and work always
happens in atomic nature.
4
How can we distinguish process from transaction?

For answering this question consider the following question:


• can we have partially execution of instructions?
• If answer is yes then it is a process.
• If answer is No then it is a transaction.

Or when a process meet the atomicity


Property, then it is transaction.
5
Transaction ACID properties
Our goal is to have consistent database.
• Atomicity: All or none of them. A transaction should execute atomic in nature.
Transaction management component of DB takes care of atomicity.

• Isolation: Only one transaction at a time. If two transaction have same output
when they execute in isolation and in concurrency, then we can say that they
enjoy isolation.
Or if two or more transactions are not effected by each other while they are
running concurrently, we can say that they are in isolation.
Concurrency control is a module which takes care of isolation.
6
ACID continue…
• Durability: changes must be committed to DB irrespective of hardware and
software failure. Recovery Management component take cares of Durability.

• Consistency: if the database is consistent, it should remain consistent after


execution of transaction.
if all three properties atomicity, isolation and durability take correctly,
Then the database is consistent.
Distributed transaction 7

• Till now you already got what is transaction,


But what do you think, what is distributed transaction?
Distributed Transaction 8

• Distributes transaction:
Transaction which is
Initiated in one site and
Can update or access
Multiple sites.
9
Distributed Transaction example
• Atomicity is
Important
feature
In distribute
Transaction
Too.
10
Distributed Transaction example
• Atomicity is
Important
feature
In distribute
Transaction
Too.
Two phase commit 11
12
Transaction state and lifetime
13
Transaction state and lifetime
• Active: until and unless a transaction is in execution.
• Failure: when a transaction is executing, if there occur some failure
You can not continue with normal execution. You automatically switch to failure
state.
• Partially committed: whatever changes the transaction has done, are properly
executed but they are still stored in local buffer in main memory.
• Committed: if you are in partially committed sate and you are sure you done
everything correctly, then you go to committed state. When switching in this
state database will be updated according to your changes.
14
Continue…
• Failure: when the system face to failures.
• Aborted state: when the transaction face to some failure, you can go to aborted
state. In this state all changes will be cleared because the changes are still in local
buffer.

• Tip: Either you committed or aborted, in both case the system is in consistent
state
15
Why should we have multiple transaction?

Advantages of concurrency:
• Waiting time
• Response time
• Resource utilization
• Efficiency

But in applying concurrency, there is some issues.


16
Problems with concurrency
• Dirty read: when an uncommitted transaction read value from local buffer which
was written by other uncommitted transaction.
17
Problems with concurrency
• Lost update( Write –Write conflict) problem
18
Schedule
• Schedule: is a set of instructions which are executing concurrently.
1. The total instructions in a schedule should be totally equal to n1+n2
In which:
N1 = number of instruction in T1
N2 = number of instruction in T2
2. Can not change the order of independent transaction in schedule.
19
Schedule continue…

Serial Schedule
Non-Serial Schedule
20
Concurrency Control
• Concurrency control: is the process of managing simultaneous execution of
transactions in shared database, to ensure the serializability of transactions.

Purpose of Concurrency Control:


1. To enforce isolation
2. To preserve database consistency
3. To resolve read-write and write-write conflicts. (conflict operations)

Concurrency control in distributed system: in DBMS, has to deal with replicated


data. It is done by Single lock manager and Distributed lock manager.
21
Continue…
How to control concurrency?
Lock based concurrency control
a. Binary: locked or unlocked
b. Shared/read and Exclusive/Write lock

Read Write
Read Shared Exclusive
Write Exclusive Exclusive
22
Simple locking scheme
• Simple locking: lock before you access, Release after you access.
Lock Types:
1. Shared/Read lock------- lock-s(x)
2. Exclusive/Write/Read lock-------lock-x(x)
23
Transaction failure
1. System failure or system crash
2. Transaction or system error
3. Concurrency control enforcement: assume in when deadlock occurs,
in order to control concurrency, the system will enforce one transaction
to fail
4. Local errors or exceptions
5. Disk failure
24
Recoverable and Non-Recoverable
Recoverable: means that if we can go to previous stable state while we face to
failure.

Tip: committed transaction never


Can be recoverable, although it T1 fails

May be possible from logs but


It is expensive.
T1 fails at this point( before committing)

Recoverable
25
Deadlock
• A system is in a deadlock state if there exists a set of transactions such
that every transaction in the set is waiting for another transaction in
the set.
26
Necessary condition in Deadlock
• Hold and Wait
• Mutual Exclusion
when T1 has non-sharable lock and T2 request for it.
• No preemption
Means you are done with transaction but you are still holding lock.
• Circular waiting

Note: We can prevent deadlock by Advanced Locking.


27
Deadlock Prevention
1. Advance Locking
2. Ordering Data item
3. Timestamp based
a. Wait-die
b. wound-wait
28
Timestamp Base
1)Wait-die 2)Wound-Wait
If Ts(Ti) < Ts(Tj) If Ts(Ti) > Ts(Tj)
wait ---- Ti waits wait ---- Ti waits
Else Else
Ti kills/wound Tj
Ti is rollback
Tj is terminated
29
References
• George Coulouris, J. D., Tim Kindberg, Gordon Blair. DISTRIBUTED
SYSTEMS concepts and Design. 676-720.
• ALLAVENA, A. (Spring 2002). Transactions in Distributed Systems.
• https://en.wikipedia.org/w/index.php?
title=Distributed_transaction&oldid=818821419
30

You might also like