SlideShare a Scribd company logo
1 of 47
Rushdi Shams, Dept of CSE, KUET 1
› Action, or series of actions, carried out by
user or application, which reads or
updates contents of database.
› Transforms database from one consistent state to
another, although consistency may be violated
during transaction.
Rushdi Shams, Dept of CSE, KUET 2
 Can have one of two outcomes:
› Success - transaction commits and database reaches a
new consistent state.
› Failure - transaction aborts, and database must be
restored to consistent state before it started. Such a
transaction is rolled back or undone.
 Committed transaction cannot be aborted.
 Aborted transaction that is rolled back can be
restarted later.
Rushdi Shams, Dept of CSE, KUET 3
Rushdi Shams, Dept of CSE, KUET 4
 Process of managing simultaneous operations
on the database without having them interfere
with one another.
 Prevents interference when two or more users
are accessing database simultaneously and at
least one is updating data.
 Although two transactions may be correct in
themselves, interleaving of operations may
produce an incorrect result.
Rushdi Shams, Dept of CSE, KUET 5
 Three examples of potential problems caused
by concurrency:
1. Lost update problem.
2. Uncommitted dependency problem.
3. Inconsistent analysis problem.
Rushdi Shams, Dept of CSE, KUET 6
 Successfully completed update is overridden by
another user.
 T1 withdrawing £10 from an account with balx,
initially £100.
 T2 depositing £100 into same account.
 Serially, final balance would be £190.
Rushdi Shams, Dept of CSE, KUET 7
Rushdi Shams, Dept of CSE, KUET 8
 Occurs when one transaction can see
intermediate results of another transaction
before it has committed.
 T4 updates balx to £200 but it aborts, so balx
should be back at original value of £100.
 T3 has read new value of balx (£200) and uses
value as basis of £10 reduction, giving a new
balance of £190, instead of £90.
Rushdi Shams, Dept of CSE, KUET 9
Rushdi Shams, Dept of CSE, KUET 10
 Occurs when transaction reads several values but
second transaction updates some of them during
execution of first.
 Sometimes referred to as dirty read or
unrepeatable read.
 T6 is totaling balances of account x (£100), account
y (£50), and account z (£25).
 Meantime, T5 has transferred £10 from balx to balz,
so T6 now has wrong result (£10 too high).
Rushdi Shams, Dept of CSE, KUET 11
Rushdi Shams, Dept of CSE, KUET 12
 Objective of a concurrency control protocol is
to schedule transactions in such a way as to
avoid any interference.
 Could run transactions serially, but this limits
degree of concurrency or parallelism in system.
 Serializability identifies those executions of
transactions guaranteed to ensure consistency.
Rushdi Shams, Dept of CSE, KUET 13
 Sequence of reads/writes by set of concurrent
transactions.
 There are 2 types of scheduling-
1. Serial scheduling
2. Non serial scheduling
Rushdi Shams, Dept of CSE, KUET 14
› Schedule where operations of each transaction are
executed consecutively without any interleaved
operations from other transactions.
Rushdi Shams, Dept of CSE, KUET 15
 Schedule where operations from set of
concurrent transactions are interleaved.
Rushdi Shams, Dept of CSE, KUET 16
 Objective of serializability is to find nonserial
schedules that allow transactions to execute
concurrently without interfering with one
another.
 In other words, want to find nonserial
schedules that are equivalent to some serial
schedule. Such a schedule is called serializable.
Rushdi Shams, Dept of CSE, KUET 17
 In serializability, ordering of read/writes is
important:
1. If two transactions only read a data item, they do
not conflict and order is not important.
2. If two transactions either read or write completely
separate data items, they do not conflict and
order is not important.
3. If one transaction writes a data item and another
reads or writes same data item, order of execution
is important.
Rushdi Shams, Dept of CSE, KUET 18
Rushdi Shams, Dept of CSE, KUET 19
 Used to test for serializability
 Create
› node for each transaction;
› a directed edge Ti → Tj, if Tj reads the value of an
item written by Ti;
› a directed edge Ti → Tj, if Tj writes a value into an
item after it has been read by Ti.
 If precedence graph contains cycle you are in
trouble!!
Rushdi Shams, Dept of CSE, KUET 20
 T9 is transferring £100 from one account with
balance balx to another account with balance
baly.
 T10 is increasing balance of these two accounts
by 10%.
 Precedence graph has a cycle and so is not
serializable.
Rushdi Shams, Dept of CSE, KUET 21
Rushdi Shams, Dept of CSE, KUET 22
 Serializability identifies schedules that maintain
database consistency, assuming no transaction
fails.
 Could also examine recoverability of
transactions within schedule.
Rushdi Shams, Dept of CSE, KUET 23
 A schedule is recoverable if, for each pair of
transactions Ti and Tj, if Tj reads a data item
previously written by Ti, then the commit
operation of Ti precedes the commit operation
of Tj.
Rushdi Shams, Dept of CSE, KUET 24
1. Optimistic method:
› Based on assumption that conflict does not happen
very often.
› So we better let the transaction run to its
completion and then check at commit time to see if
there is a conflict.
› If there is, the offending transaction simply starts
again from the beginning.
Rushdi Shams, Dept of CSE, KUET 25
2. Timestamping:
› For any given database request, the system
compares the timestamp of the requesting
transaction with the timestamp of the transaction
that last retrieved or updated the requested record.
› If there is a conflict, the requesting transaction can
simply be restarted (with new timestamp).
Rushdi Shams, Dept of CSE, KUET 26
3. Locking:
› When a transaction needs an assurance that
transaction will not be affected by others, it
requires a lock on that object.
› Then the first transaction is able to carry out its
processing without fear of others’ interference.
Rushdi Shams, Dept of CSE, KUET 27
 Exclusive Lock (XLock): If anybody is
having exclusive lock, the other users
will go into wait list until the exclusive
lock holder releases it.
 Shared Lock (SLock): If anybody has
shared lock, the other users with
request shared lock can also have access
to it.
Rushdi Shams, Dept of CSE, KUET 28
If A has XLock,
then if B wants XLock, B has to wait
then if B wants SLock, B has to wait
then if B wants NoLock, B can see it
If A has SLock,
then if B wants XLock, B has to wait
then if B wants SLock, B gets permission
then if B wants NoLock, B can see it
If A has NoLock,
then if B wants XLock, B will be granted
then if B wants SLock, B will be granted
then if B wants NoLock, B will be granted
 Xlock= Exclusive Lock
 SLock= Shared Lock
Rushdi Shams, Dept of CSE, KUET 29
 If transaction has shared lock on item, can read
but not update item.
 If transaction has exclusive lock on item, can
both read and update item.
 Reads cannot conflict, so more than one
transaction can hold shared locks
simultaneously on same item.
Rushdi Shams, Dept of CSE, KUET 30
 Problem is that transactions release locks too
soon, resulting in loss of total isolation and
atomicity.
 To guarantee serializability, need an additional
protocol concerning the positioning of lock and
unlock operations in every transaction.
Rushdi Shams, Dept of CSE, KUET 31
 Transaction follows 2PL protocol if all locking
operations precede first unlock operation in the
transaction.
 Two phases for transaction:
› Growing phase - acquires all locks but cannot
release any locks.
› Shrinking phase - releases locks but cannot acquire
any new locks.
Rushdi Shams, Dept of CSE, KUET 32
Rushdi Shams, Dept of CSE, KUET 33
Rushdi Shams, Dept of CSE, KUET 34
Rushdi Shams, Dept of CSE, KUET 35
Rushdi Shams, Dept of CSE, KUET 36
 Transactions conform to 2PL.
 T14 aborts.
 Since T15 is dependent on T14, T15 must also be
rolled back. Since T16 is dependent on T15, it too
must be rolled back.
 This is called cascading rollback.
 To prevent this with 2PL, leave release of all
locks until end of transaction.
Rushdi Shams, Dept of CSE, KUET 37
 An impasse that may result when two (or more)
transactions are each waiting for locks held by
the other to be released.
 Deadlock is a situation in which two or more
transactions are in a simultaneous wait state;
each one waiting for one of the other to
release a lock before it can proceed.
Rushdi Shams, Dept of CSE, KUET 38
Rushdi Shams, Dept of CSE, KUET 39
 Deadlock should be transparent to user, so
DBMS should restart transaction(s).
 Three general techniques for handling
deadlock:
1. Timeouts.
2. Deadlock prevention.
3. Deadlock detection and recovery.
Rushdi Shams, Dept of CSE, KUET 40
 Transaction that requests lock will only wait for a
system-defined period of time.
 If lock has not been granted within this period, lock
request times out.
 In this case, DBMS assumes transaction may be
deadlocked, even though it may not be, and it
aborts and automatically restarts the transaction.
Rushdi Shams, Dept of CSE, KUET 41
 DBMS looks ahead to see if transaction would
cause deadlock and never allows deadlock to
occur.
 Wait-Die - only an older transaction can wait
for younger one, otherwise
If younger transaction requests lock held by older
one, younger one is aborted (dies) and restarted
with same timestamp.
Rushdi Shams, Dept of CSE, KUET 42
› Wound-Wait - only a younger transaction can wait
for an older one.
If older transaction requests lock held by younger
one, younger one is aborted (wounded).
Rushdi Shams, Dept of CSE, KUET 43
 DBMS allows deadlock to occur but recognizes it
and breaks it.
 Usually handled by construction of wait-for graph
(WFG) showing transaction dependencies:
› Create a node for each transaction.
› Create edge Ti -> Tj, if Ti waiting to lock item locked
by Tj.
 Deadlock exists if and only if WFG contains cycle.
Rushdi Shams, Dept of CSE, KUET 44
Rushdi Shams, Dept of CSE, KUET 45
 Selecting a victim – minimize cost.
 Rollback – return to some safe state, restart
transaction for that state.
 Starvation – same transaction may always be
picked as victim, include number of rollback
in cost factor.
Rushdi Shams, Dept of CSE, KUET 46
 Database Management Systems by R.
Ramakrishnan
 John Hall, Senior Lecturer, University of Bolton,
UK
 Operating Systems Concept (6th
Edition)
by Silberschatz, Galvin and Gagne
Rushdi Shams, Dept of CSE, KUET 47

More Related Content

What's hot

16. Concurrency Control in DBMS
16. Concurrency Control in DBMS16. Concurrency Control in DBMS
16. Concurrency Control in DBMSkoolkampus
 
Database ,11 Concurrency Control
Database ,11 Concurrency ControlDatabase ,11 Concurrency Control
Database ,11 Concurrency ControlAli Usman
 
Concurrency control PPT
Concurrency control PPTConcurrency control PPT
Concurrency control PPTShushrutGupta
 
Database concurrency control & recovery (1)
Database concurrency control & recovery (1)Database concurrency control & recovery (1)
Database concurrency control & recovery (1)Rashid Khan
 
Concurrency Conrol
Concurrency ConrolConcurrency Conrol
Concurrency Conrollubna19
 
Concurrency control ms neeti
Concurrency control ms neetiConcurrency control ms neeti
Concurrency control ms neetineeti arora
 
Concurrency control
Concurrency controlConcurrency control
Concurrency controlvarsha singh
 
Concurrency Control in Database Management System
Concurrency Control in Database Management SystemConcurrency Control in Database Management System
Concurrency Control in Database Management SystemJanki Shah
 
Concurrency control!
Concurrency control!Concurrency control!
Concurrency control!Ashish K
 
Deadlock management
Deadlock managementDeadlock management
Deadlock managementAhmed kasim
 
Concurrency (Distributed computing)
Concurrency (Distributed computing)Concurrency (Distributed computing)
Concurrency (Distributed computing)Sri Prasanna
 
Concurrency control
Concurrency controlConcurrency control
Concurrency controlJaya Jeswani
 
Locking base concurrency control
  Locking base concurrency control  Locking base concurrency control
Locking base concurrency controlPrakash Poudel
 
Optimistic concurrency control in Distributed Systems
Optimistic concurrency control in Distributed SystemsOptimistic concurrency control in Distributed Systems
Optimistic concurrency control in Distributed Systemsmridul mishra
 
Databases: Concurrency Control
Databases: Concurrency ControlDatabases: Concurrency Control
Databases: Concurrency ControlDamian T. Gordon
 

What's hot (20)

concurrency-control
concurrency-controlconcurrency-control
concurrency-control
 
16. Concurrency Control in DBMS
16. Concurrency Control in DBMS16. Concurrency Control in DBMS
16. Concurrency Control in DBMS
 
Database ,11 Concurrency Control
Database ,11 Concurrency ControlDatabase ,11 Concurrency Control
Database ,11 Concurrency Control
 
Ch16
Ch16Ch16
Ch16
 
Concurrency control
Concurrency controlConcurrency control
Concurrency control
 
Concurrency control PPT
Concurrency control PPTConcurrency control PPT
Concurrency control PPT
 
Database concurrency control & recovery (1)
Database concurrency control & recovery (1)Database concurrency control & recovery (1)
Database concurrency control & recovery (1)
 
Concurrency Conrol
Concurrency ConrolConcurrency Conrol
Concurrency Conrol
 
Concurrency control ms neeti
Concurrency control ms neetiConcurrency control ms neeti
Concurrency control ms neeti
 
Concurrency control
Concurrency controlConcurrency control
Concurrency control
 
Concurrency Control in Database Management System
Concurrency Control in Database Management SystemConcurrency Control in Database Management System
Concurrency Control in Database Management System
 
Concurrency control!
Concurrency control!Concurrency control!
Concurrency control!
 
Deadlock management
Deadlock managementDeadlock management
Deadlock management
 
Concurrency (Distributed computing)
Concurrency (Distributed computing)Concurrency (Distributed computing)
Concurrency (Distributed computing)
 
Concurrency control
Concurrency controlConcurrency control
Concurrency control
 
Locking base concurrency control
  Locking base concurrency control  Locking base concurrency control
Locking base concurrency control
 
Optimistic concurrency control in Distributed Systems
Optimistic concurrency control in Distributed SystemsOptimistic concurrency control in Distributed Systems
Optimistic concurrency control in Distributed Systems
 
Concurrency control
Concurrency controlConcurrency control
Concurrency control
 
2 phase locking protocol DBMS
2 phase locking protocol DBMS2 phase locking protocol DBMS
2 phase locking protocol DBMS
 
Databases: Concurrency Control
Databases: Concurrency ControlDatabases: Concurrency Control
Databases: Concurrency Control
 

Similar to L11 l12 l13 transaction management

Similar to L11 l12 l13 transaction management (20)

Rdbms
RdbmsRdbms
Rdbms
 
F017213747
F017213747F017213747
F017213747
 
F017213747
F017213747F017213747
F017213747
 
Design & Development of an Advanced Database Management System Using Multiver...
Design & Development of an Advanced Database Management System Using Multiver...Design & Development of an Advanced Database Management System Using Multiver...
Design & Development of an Advanced Database Management System Using Multiver...
 
Transaction management transparencies
Transaction management transparenciesTransaction management transparencies
Transaction management transparencies
 
Concurrency note.pdf
Concurrency note.pdfConcurrency note.pdf
Concurrency note.pdf
 
deadlock
deadlockdeadlock
deadlock
 
ch15.ppt
ch15.pptch15.ppt
ch15.ppt
 
ch15.ppt
ch15.pptch15.ppt
ch15.ppt
 
ch15fgdhcvkjdhjkvhdfjkfhvdzkjfhvkjdfhjkvzhdfktxh (2).ppt
ch15fgdhcvkjdhjkvhdfjkfhvdzkjfhvkjdfhjkvzhdfktxh (2).pptch15fgdhcvkjdhjkvhdfjkfhvdzkjfhvkjdfhjkvzhdfktxh (2).ppt
ch15fgdhcvkjdhjkvhdfjkfhvdzkjfhvkjdfhjkvzhdfktxh (2).ppt
 
Ch15
Ch15Ch15
Ch15
 
ch15.ppt
ch15.pptch15.ppt
ch15.ppt
 
Transaction management
Transaction managementTransaction management
Transaction management
 
DBMS Presentation.pptx
DBMS Presentation.pptxDBMS Presentation.pptx
DBMS Presentation.pptx
 
dokumen.tips_silberschatz-korth-and-sudarshan1-transactions-transaction-conce...
dokumen.tips_silberschatz-korth-and-sudarshan1-transactions-transaction-conce...dokumen.tips_silberschatz-korth-and-sudarshan1-transactions-transaction-conce...
dokumen.tips_silberschatz-korth-and-sudarshan1-transactions-transaction-conce...
 
Ch16
Ch16Ch16
Ch16
 
DBMS Transaction course
DBMS Transaction courseDBMS Transaction course
DBMS Transaction course
 
concurrency control
concurrency controlconcurrency control
concurrency control
 
Concurrency Control & Deadlock Handling
Concurrency Control & Deadlock HandlingConcurrency Control & Deadlock Handling
Concurrency Control & Deadlock Handling
 
Concurrency control
Concurrency  controlConcurrency  control
Concurrency control
 

More from Rushdi Shams

Research Methodology and Tips on Better Research
Research Methodology and Tips on Better ResearchResearch Methodology and Tips on Better Research
Research Methodology and Tips on Better ResearchRushdi Shams
 
Common evaluation measures in NLP and IR
Common evaluation measures in NLP and IRCommon evaluation measures in NLP and IR
Common evaluation measures in NLP and IRRushdi Shams
 
Machine learning with nlp 101
Machine learning with nlp 101Machine learning with nlp 101
Machine learning with nlp 101Rushdi Shams
 
Semi-supervised classification for natural language processing
Semi-supervised classification for natural language processingSemi-supervised classification for natural language processing
Semi-supervised classification for natural language processingRushdi Shams
 
Natural Language Processing: Parsing
Natural Language Processing: ParsingNatural Language Processing: Parsing
Natural Language Processing: ParsingRushdi Shams
 
Types of machine translation
Types of machine translationTypes of machine translation
Types of machine translationRushdi Shams
 
L1 l2 l3 introduction to machine translation
L1 l2 l3  introduction to machine translationL1 l2 l3  introduction to machine translation
L1 l2 l3 introduction to machine translationRushdi Shams
 
Syntax and semantics
Syntax and semanticsSyntax and semantics
Syntax and semanticsRushdi Shams
 
Propositional logic
Propositional logicPropositional logic
Propositional logicRushdi Shams
 
Probabilistic logic
Probabilistic logicProbabilistic logic
Probabilistic logicRushdi Shams
 
Knowledge structure
Knowledge structureKnowledge structure
Knowledge structureRushdi Shams
 
Knowledge representation
Knowledge representationKnowledge representation
Knowledge representationRushdi Shams
 
L5 understanding hacking
L5  understanding hackingL5  understanding hacking
L5 understanding hackingRushdi Shams
 
L2 Intrusion Detection System (IDS)
L2  Intrusion Detection System (IDS)L2  Intrusion Detection System (IDS)
L2 Intrusion Detection System (IDS)Rushdi Shams
 

More from Rushdi Shams (20)

Research Methodology and Tips on Better Research
Research Methodology and Tips on Better ResearchResearch Methodology and Tips on Better Research
Research Methodology and Tips on Better Research
 
Common evaluation measures in NLP and IR
Common evaluation measures in NLP and IRCommon evaluation measures in NLP and IR
Common evaluation measures in NLP and IR
 
Machine learning with nlp 101
Machine learning with nlp 101Machine learning with nlp 101
Machine learning with nlp 101
 
Semi-supervised classification for natural language processing
Semi-supervised classification for natural language processingSemi-supervised classification for natural language processing
Semi-supervised classification for natural language processing
 
Natural Language Processing: Parsing
Natural Language Processing: ParsingNatural Language Processing: Parsing
Natural Language Processing: Parsing
 
Types of machine translation
Types of machine translationTypes of machine translation
Types of machine translation
 
L1 l2 l3 introduction to machine translation
L1 l2 l3  introduction to machine translationL1 l2 l3  introduction to machine translation
L1 l2 l3 introduction to machine translation
 
Syntax and semantics
Syntax and semanticsSyntax and semantics
Syntax and semantics
 
Propositional logic
Propositional logicPropositional logic
Propositional logic
 
Probabilistic logic
Probabilistic logicProbabilistic logic
Probabilistic logic
 
L15 fuzzy logic
L15  fuzzy logicL15  fuzzy logic
L15 fuzzy logic
 
Knowledge structure
Knowledge structureKnowledge structure
Knowledge structure
 
Knowledge representation
Knowledge representationKnowledge representation
Knowledge representation
 
First order logic
First order logicFirst order logic
First order logic
 
Belief function
Belief functionBelief function
Belief function
 
L5 understanding hacking
L5  understanding hackingL5  understanding hacking
L5 understanding hacking
 
L4 vpn
L4  vpnL4  vpn
L4 vpn
 
L3 defense
L3  defenseL3  defense
L3 defense
 
L2 Intrusion Detection System (IDS)
L2  Intrusion Detection System (IDS)L2  Intrusion Detection System (IDS)
L2 Intrusion Detection System (IDS)
 
L1 phishing
L1  phishingL1  phishing
L1 phishing
 

Recently uploaded

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGSujit Pal
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 

Recently uploaded (20)

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAG
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 

L11 l12 l13 transaction management

  • 1. Rushdi Shams, Dept of CSE, KUET 1
  • 2. › Action, or series of actions, carried out by user or application, which reads or updates contents of database. › Transforms database from one consistent state to another, although consistency may be violated during transaction. Rushdi Shams, Dept of CSE, KUET 2
  • 3.  Can have one of two outcomes: › Success - transaction commits and database reaches a new consistent state. › Failure - transaction aborts, and database must be restored to consistent state before it started. Such a transaction is rolled back or undone.  Committed transaction cannot be aborted.  Aborted transaction that is rolled back can be restarted later. Rushdi Shams, Dept of CSE, KUET 3
  • 4. Rushdi Shams, Dept of CSE, KUET 4
  • 5.  Process of managing simultaneous operations on the database without having them interfere with one another.  Prevents interference when two or more users are accessing database simultaneously and at least one is updating data.  Although two transactions may be correct in themselves, interleaving of operations may produce an incorrect result. Rushdi Shams, Dept of CSE, KUET 5
  • 6.  Three examples of potential problems caused by concurrency: 1. Lost update problem. 2. Uncommitted dependency problem. 3. Inconsistent analysis problem. Rushdi Shams, Dept of CSE, KUET 6
  • 7.  Successfully completed update is overridden by another user.  T1 withdrawing £10 from an account with balx, initially £100.  T2 depositing £100 into same account.  Serially, final balance would be £190. Rushdi Shams, Dept of CSE, KUET 7
  • 8. Rushdi Shams, Dept of CSE, KUET 8
  • 9.  Occurs when one transaction can see intermediate results of another transaction before it has committed.  T4 updates balx to £200 but it aborts, so balx should be back at original value of £100.  T3 has read new value of balx (£200) and uses value as basis of £10 reduction, giving a new balance of £190, instead of £90. Rushdi Shams, Dept of CSE, KUET 9
  • 10. Rushdi Shams, Dept of CSE, KUET 10
  • 11.  Occurs when transaction reads several values but second transaction updates some of them during execution of first.  Sometimes referred to as dirty read or unrepeatable read.  T6 is totaling balances of account x (£100), account y (£50), and account z (£25).  Meantime, T5 has transferred £10 from balx to balz, so T6 now has wrong result (£10 too high). Rushdi Shams, Dept of CSE, KUET 11
  • 12. Rushdi Shams, Dept of CSE, KUET 12
  • 13.  Objective of a concurrency control protocol is to schedule transactions in such a way as to avoid any interference.  Could run transactions serially, but this limits degree of concurrency or parallelism in system.  Serializability identifies those executions of transactions guaranteed to ensure consistency. Rushdi Shams, Dept of CSE, KUET 13
  • 14.  Sequence of reads/writes by set of concurrent transactions.  There are 2 types of scheduling- 1. Serial scheduling 2. Non serial scheduling Rushdi Shams, Dept of CSE, KUET 14
  • 15. › Schedule where operations of each transaction are executed consecutively without any interleaved operations from other transactions. Rushdi Shams, Dept of CSE, KUET 15
  • 16.  Schedule where operations from set of concurrent transactions are interleaved. Rushdi Shams, Dept of CSE, KUET 16
  • 17.  Objective of serializability is to find nonserial schedules that allow transactions to execute concurrently without interfering with one another.  In other words, want to find nonserial schedules that are equivalent to some serial schedule. Such a schedule is called serializable. Rushdi Shams, Dept of CSE, KUET 17
  • 18.  In serializability, ordering of read/writes is important: 1. If two transactions only read a data item, they do not conflict and order is not important. 2. If two transactions either read or write completely separate data items, they do not conflict and order is not important. 3. If one transaction writes a data item and another reads or writes same data item, order of execution is important. Rushdi Shams, Dept of CSE, KUET 18
  • 19. Rushdi Shams, Dept of CSE, KUET 19
  • 20.  Used to test for serializability  Create › node for each transaction; › a directed edge Ti → Tj, if Tj reads the value of an item written by Ti; › a directed edge Ti → Tj, if Tj writes a value into an item after it has been read by Ti.  If precedence graph contains cycle you are in trouble!! Rushdi Shams, Dept of CSE, KUET 20
  • 21.  T9 is transferring £100 from one account with balance balx to another account with balance baly.  T10 is increasing balance of these two accounts by 10%.  Precedence graph has a cycle and so is not serializable. Rushdi Shams, Dept of CSE, KUET 21
  • 22. Rushdi Shams, Dept of CSE, KUET 22
  • 23.  Serializability identifies schedules that maintain database consistency, assuming no transaction fails.  Could also examine recoverability of transactions within schedule. Rushdi Shams, Dept of CSE, KUET 23
  • 24.  A schedule is recoverable if, for each pair of transactions Ti and Tj, if Tj reads a data item previously written by Ti, then the commit operation of Ti precedes the commit operation of Tj. Rushdi Shams, Dept of CSE, KUET 24
  • 25. 1. Optimistic method: › Based on assumption that conflict does not happen very often. › So we better let the transaction run to its completion and then check at commit time to see if there is a conflict. › If there is, the offending transaction simply starts again from the beginning. Rushdi Shams, Dept of CSE, KUET 25
  • 26. 2. Timestamping: › For any given database request, the system compares the timestamp of the requesting transaction with the timestamp of the transaction that last retrieved or updated the requested record. › If there is a conflict, the requesting transaction can simply be restarted (with new timestamp). Rushdi Shams, Dept of CSE, KUET 26
  • 27. 3. Locking: › When a transaction needs an assurance that transaction will not be affected by others, it requires a lock on that object. › Then the first transaction is able to carry out its processing without fear of others’ interference. Rushdi Shams, Dept of CSE, KUET 27
  • 28.  Exclusive Lock (XLock): If anybody is having exclusive lock, the other users will go into wait list until the exclusive lock holder releases it.  Shared Lock (SLock): If anybody has shared lock, the other users with request shared lock can also have access to it. Rushdi Shams, Dept of CSE, KUET 28
  • 29. If A has XLock, then if B wants XLock, B has to wait then if B wants SLock, B has to wait then if B wants NoLock, B can see it If A has SLock, then if B wants XLock, B has to wait then if B wants SLock, B gets permission then if B wants NoLock, B can see it If A has NoLock, then if B wants XLock, B will be granted then if B wants SLock, B will be granted then if B wants NoLock, B will be granted  Xlock= Exclusive Lock  SLock= Shared Lock Rushdi Shams, Dept of CSE, KUET 29
  • 30.  If transaction has shared lock on item, can read but not update item.  If transaction has exclusive lock on item, can both read and update item.  Reads cannot conflict, so more than one transaction can hold shared locks simultaneously on same item. Rushdi Shams, Dept of CSE, KUET 30
  • 31.  Problem is that transactions release locks too soon, resulting in loss of total isolation and atomicity.  To guarantee serializability, need an additional protocol concerning the positioning of lock and unlock operations in every transaction. Rushdi Shams, Dept of CSE, KUET 31
  • 32.  Transaction follows 2PL protocol if all locking operations precede first unlock operation in the transaction.  Two phases for transaction: › Growing phase - acquires all locks but cannot release any locks. › Shrinking phase - releases locks but cannot acquire any new locks. Rushdi Shams, Dept of CSE, KUET 32
  • 33. Rushdi Shams, Dept of CSE, KUET 33
  • 34. Rushdi Shams, Dept of CSE, KUET 34
  • 35. Rushdi Shams, Dept of CSE, KUET 35
  • 36. Rushdi Shams, Dept of CSE, KUET 36
  • 37.  Transactions conform to 2PL.  T14 aborts.  Since T15 is dependent on T14, T15 must also be rolled back. Since T16 is dependent on T15, it too must be rolled back.  This is called cascading rollback.  To prevent this with 2PL, leave release of all locks until end of transaction. Rushdi Shams, Dept of CSE, KUET 37
  • 38.  An impasse that may result when two (or more) transactions are each waiting for locks held by the other to be released.  Deadlock is a situation in which two or more transactions are in a simultaneous wait state; each one waiting for one of the other to release a lock before it can proceed. Rushdi Shams, Dept of CSE, KUET 38
  • 39. Rushdi Shams, Dept of CSE, KUET 39
  • 40.  Deadlock should be transparent to user, so DBMS should restart transaction(s).  Three general techniques for handling deadlock: 1. Timeouts. 2. Deadlock prevention. 3. Deadlock detection and recovery. Rushdi Shams, Dept of CSE, KUET 40
  • 41.  Transaction that requests lock will only wait for a system-defined period of time.  If lock has not been granted within this period, lock request times out.  In this case, DBMS assumes transaction may be deadlocked, even though it may not be, and it aborts and automatically restarts the transaction. Rushdi Shams, Dept of CSE, KUET 41
  • 42.  DBMS looks ahead to see if transaction would cause deadlock and never allows deadlock to occur.  Wait-Die - only an older transaction can wait for younger one, otherwise If younger transaction requests lock held by older one, younger one is aborted (dies) and restarted with same timestamp. Rushdi Shams, Dept of CSE, KUET 42
  • 43. › Wound-Wait - only a younger transaction can wait for an older one. If older transaction requests lock held by younger one, younger one is aborted (wounded). Rushdi Shams, Dept of CSE, KUET 43
  • 44.  DBMS allows deadlock to occur but recognizes it and breaks it.  Usually handled by construction of wait-for graph (WFG) showing transaction dependencies: › Create a node for each transaction. › Create edge Ti -> Tj, if Ti waiting to lock item locked by Tj.  Deadlock exists if and only if WFG contains cycle. Rushdi Shams, Dept of CSE, KUET 44
  • 45. Rushdi Shams, Dept of CSE, KUET 45
  • 46.  Selecting a victim – minimize cost.  Rollback – return to some safe state, restart transaction for that state.  Starvation – same transaction may always be picked as victim, include number of rollback in cost factor. Rushdi Shams, Dept of CSE, KUET 46
  • 47.  Database Management Systems by R. Ramakrishnan  John Hall, Senior Lecturer, University of Bolton, UK  Operating Systems Concept (6th Edition) by Silberschatz, Galvin and Gagne Rushdi Shams, Dept of CSE, KUET 47