SlideShare a Scribd company logo
Transactions & Concurrency
Control
CS4262 Distributed Systems
Dilum Bandara
Dilum.Bandara@uom.lk
Some slides adapted from U Uthaiyashankar (WSO2) and Rajkumar
Buyya’s
Outline
 Transactions
 Properties
 Classification
 Transaction implementation
 Concurrency control
2
Transactions
 Transactions protect a shared resource (e.g.,
shared data) against simultaneous access by
several concurrent processes
 Transactions can do much more…
 They allow a process to access & modify multiple data
items as a single atomic operation
 All-or-nothing property
3
Transactions in DBMS
 A unit of work performed within a DBMS against
a database
 Treated in a coherent & reliable way independent of
other transactions
 2 main purposes
 To provide reliable units of work that allow correct
recovery from failures & keep a database consistent
even in cases of (complete or partial) system failure
 To provide isolation between programs accessing a
database concurrently
4
Goal of Transactions
 To ensure objects managed by a server remain
in a consistent state when accessed by multiple
transactions in the presence of server failure
 Transactions deal with process crash failures &
communication omission failures
 Transactions don’t deal with Byzantine failure
5
Transaction Model
 Recoverable objects
 Objects that can be recovered after their server
crashes
 Failure atomicity
 Effects of the transaction are atomic even when
server crashes
 Transactions require coordination among
 A client program
 Some recoverable objects
 A coordinator
6
Transaction Model (Cont.)
 Each transaction is created & managed by a
coordinator which implements the coordinator
interface
 Coordinator gives each transaction an identifier (TID)
 Clients invoke transaction coordinator interface
methods to perform a transaction
 A transaction may be aborted by client or server
7
Transaction Coordinator Interface
 openTransaction() → trans
 Starts a new transaction & delivers a unique TID trans
 trans will be used in other operations in the transaction
 closeTransaction(trans) → (commit, abort)
 Ends a transaction
 commit – indicates that transaction has committed
 abort – Indicates that it has aborted
 abortTransaction(trans)
 Aborts the transaction
8
Properties of a Transaction
 Proposed by Harder & Reuter in 1983
 ACID Property
 Atomic
 Consistent
 Isolated
 Durable
9
Atomic Property
 Process all of a transaction or none of it
 To outside world, transaction happens indivisibly
 While a transaction happens, other processes
can’t see any intermediate states
 Example
 A file is 100 bytes long when a transaction starts to
append to it
 If other processes read the file during transaction,
they should see & access only the 100 bytes
 If transaction commits successfully, file grows
instantaneously to its new size
10
Consistent Property
 Data on all systems reflects the same state
 Transaction doesn’t violate system invariants
 Example
 In a banking system, a key invariant is the law of
conservation of money
 After any internal transfer, amount of money in bank
must be same as it was before transfer
 During internal transfer operations, this invariant may
be violated
 But this violation isn’t visible outside the transaction
11
Isolated Property
 Transactions don’t interact/interfere with one
another
 Concurrent transactions don’t interfere with each
other
 i.e., transactions are serializable
 Example
 If 2+ transactions are running at the same time, to
each of them & to other processes, final result
appears as though all transactions ran sequentially (in
some system-dependent order)
12
Durable Property
 Effects of a completed transaction are persistent
 Once a transaction commits, changes are
permanent
 No failure after the commit can undo results or
cause them to be lost
13
Ensuring Transaction Properties
 To support “failure atomicity” & “durability”,
objects must be recoverable
 To support “isolation” & “consistency” server
needs to synchronize operations
 Perform transactions serially (sequentially)
 Generally, an unacceptable solution
 Allow transactions to execute concurrently, if they
would have the same effect as a serial execution
 Known as serializable or serially equivalent transactions
14
Classification of Transactions
 Flat transactions
 Nested transactions
 Distributed transactions
15
Flat Transactions
 A series of operations
 Don’t allow partial results to be committed or
aborted
 e.g., booking multiple air lines from start to
destination
16
Nested Transactions
 Constructed from a number of sub-transactions
 Top-level transaction may fork off children that
run in parallel to one another
 Incase of failure results of some sub-transaction
that committed must be undone
 e.g., booking multiple air lines from start to
destination
17
Distributed Transactions
 Logically, a flat, indivisible transaction that
operates on distributed data
 In contrast, a nested transaction is logically
decomposed into a hierarchy of sub-transactions
18
Source: Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007
Achieving Transaction Properties in
Distributed Transactions
 To achieve atomicity & durability
 Distributed commit protocols
 To achieve consistency & isolation
 Concurrency control algorithms (distributed locking
protocols)
 We need separate distributed algorithms to
handle “locking of data” & “committing entire
transaction”
19
Transaction Implementation
 Consider transactions on a file system
 If each process executing a transaction just updates
the file it uses in place, then transactions will not be
atomic
 2 common implementation techniques
 Private workspace
 Write-ahead log
20
Private Workspace
 Provide private (local) copies
 All updates on private copies
 Update the original (global) copy while
committing
 Issues
 Cost of copying everything
 Possible solution
 Keep a pointer to relevant file block
 When writing copy file block, instead of entire file
 Update original when closing file
 Examples – Andrew file systems
21
Example – Private Workspace
Implementation
22
Source: Andrew S. Tanenbaum , Distributed Operating Systems
Write-Ahead Log
 Files are modified in-place
 Before any changes, a record is written in a log
indicating
 Which transaction is making the change
 Which file & block is being changed
 What old & new values are
 Change is made to file only after log is written
successfully
 Example – log structured file system
 If transaction succeeds & is committed, a commit
record is written in log
 If transaction is aborted, log is used to revert file
back to its original state – rollback 23
Writeahead Log Implementation
24
Concurrency Control
 Goal
 Allow simultaneous execution of transactions
 While enabling each transaction to be isolated & data
items being manipulated are left in a consistent state
 Consistency
 Achieved by giving transactions access to data items in
a specific order
 Final result would be the same as if all transactions
were run sequentially
25
Achieving Concurrency Control
 3 different managers
1. Data manager
2. Scheduler
3. Transaction manager
26
Achieving Concurrency Control
(Cont.)
 Data manager
 Performs actual read/write on data
 Not concerned about transaction
 Scheduler
 Responsible for properly controlling concurrency
 Determines which transaction is allowed to pass a read/write
operation to data manager & at which time
 Schedules individual read/write s.t. transaction isolation &
consistency properties are met
 Transaction manager
 Guarantees transaction atomicity
 Processes transaction primitives by transforming them into
scheduling requests
27
 Each site has a scheduler & data manager
 Each transaction is handled by a transaction manager
 Transaction manager communicates with schedulers
at different sites
 Scheduler may also communicate with remote data
managers
Distributed Concurrency Control
28
Concurrency Control
 Schedules
 Concurrency control issues
 Serial equivalence
 Issues in aborting transactions
29
Schedules – Example
 Schedule – system dependent order of actions
 Final result looks as though all transactions ran sequentially
30
Concurrent Transaction Issues
 Lost update problem
 Transactions should not read a “stale” value & use it
in computing a new value
 Inconsistent retrievals problem
 Update transactions shouldn’t interfere with retrievals
 Illustrated in the context of banking examples…
31
“Lost Update” Problem
 3 bank accounts (A, B, C) with balances,
 A = $100, B = $200, C = $300
 Transaction T
 Transfers from account A to B, for 10% increase in the B’s
balance
 B = $200 + ($200*10%) = $220
 A = $100 – ($200*10%) = $80
 Transaction U
 Transfers from C to B, for 10% increase in B’s balance
 B = $220 + ($220*10%) = $242
 C = $300 – ($220*10%) = $278
 What might happen if transactions T & U are executed
concurrently?
32
“Lost Update” Problem (Cont.)
33
“Inconsistent Retrievals” Problem
 2 bank accounts (A, B) with balances
 A = $200
 B = $200
 Transaction V
 Transfers $100 of account A to B
 A = $200 - $100 = $100
 B = $200 + $100 = $300
 Transaction W
 Computes sum of all account balances (branch total)
 Total = $100 + $300 +…… = $400 + ……
 What might happen if transactions V & W are executed
concurrently? 34
“Inconsistent Retrievals” Problem
(Cont.)
35
Serial Equivalence
 Serial equivalence prevents occurrence of lost
updates & inconsistent retrievals
 Thus, serial equivalence is used as a criterion in
concurrency control algorithms
 2 transactions are serially equivalent if
 All pairs of conflicting operations of 2 transactions are
executed in same order at all of the objects that both
transactions access
36
Serial Equivalence (Cont.)
 Consider 2 objects i & j, & 2 transactions T & U
 Serially equivalent orderings require one of the
following 2 conditions
 T accesses i before U, and T accesses j before U
 U accesses i before T, and U accesses j before T
37
“Lost Update” Problem
38
Serially Equivalent Interleaving
39
“Inconsistent Retrievals” Problem
40
Serially Equivalent Interleaving
41
Issues in Aborting Transactions
 Servers must record effects of all committed
transactions & none of aborted transactions
 2 well-known problems
 Dirty reads
 Premature writes
 Both of these can occur in the presence of
serially equivalent executions of transactions
42
Example – Dirty Read
43
Example – Premature Writes
 Due to interaction between write operations on
the same object belonging to different
transactions
 If U aborts & T commits, balance should be $105
44
Concurrency Control Algorithms
 2-Phase Locking (2PL)
 Get all locks, then release them
 No more lock acquisition when a lock is release
 Timestamp ordering
 Lamport’s time stamp
 Optimistic concurrency
 Go & do the changes, if there is a problem let’s
handle them later
 How to do these concurrently on a distributed
system? 45

More Related Content

What's hot

Resource management
Resource managementResource management
Resource management
Dr Sandeep Kumar Poonia
 
Database System Architectures
Database System ArchitecturesDatabase System Architectures
Database System Architectures
Information Technology
 
Threads (operating System)
Threads (operating System)Threads (operating System)
Threads (operating System)
Prakhar Maurya
 
Replication in Distributed Systems
Replication in Distributed SystemsReplication in Distributed Systems
Replication in Distributed Systems
Kavya Barnadhya Hazarika
 
Cpu scheduling in operating System.
Cpu scheduling in operating System.Cpu scheduling in operating System.
Cpu scheduling in operating System.
Ravi Kumar Patel
 
Concurrency Control in Distributed Database.
Concurrency Control in Distributed Database.Concurrency Control in Distributed Database.
Concurrency Control in Distributed Database.
Meghaj Mallick
 
distributed shared memory
 distributed shared memory distributed shared memory
distributed shared memory
Ashish Kumar
 
15. Transactions in DBMS
15. Transactions in DBMS15. Transactions in DBMS
15. Transactions in DBMS
koolkampus
 
Concurrency control
Concurrency controlConcurrency control
Concurrency control
Subhasish Pati
 
16. Concurrency Control in DBMS
16. Concurrency Control in DBMS16. Concurrency Control in DBMS
16. Concurrency Control in DBMS
koolkampus
 
13. Query Processing in DBMS
13. Query Processing in DBMS13. Query Processing in DBMS
13. Query Processing in DBMS
koolkampus
 
RPC: Remote procedure call
RPC: Remote procedure callRPC: Remote procedure call
RPC: Remote procedure call
Sunita Sahu
 
Distributed file system
Distributed file systemDistributed file system
Distributed file system
Anamika Singh
 
Overview of Concurrency Control & Recovery in Distributed Databases
Overview of Concurrency Control & Recovery in Distributed DatabasesOverview of Concurrency Control & Recovery in Distributed Databases
Overview of Concurrency Control & Recovery in Distributed Databases
Meghaj Mallick
 
Memory management
Memory managementMemory management
Memory management
Rajni Sirohi
 
Processes and threads
Processes and threadsProcesses and threads
Clock synchronization in distributed system
Clock synchronization in distributed systemClock synchronization in distributed system
Clock synchronization in distributed system
Sunita Sahu
 
Deadlock Detection in Distributed Systems
Deadlock Detection in Distributed SystemsDeadlock Detection in Distributed Systems
Deadlock Detection in Distributed Systems
DHIVYADEVAKI
 
Transaction management and concurrency control
Transaction management and concurrency controlTransaction management and concurrency control
Transaction management and concurrency control
Dhani Ahmad
 
Paging and segmentation
Paging and segmentationPaging and segmentation
Paging and segmentation
Piyush Rochwani
 

What's hot (20)

Resource management
Resource managementResource management
Resource management
 
Database System Architectures
Database System ArchitecturesDatabase System Architectures
Database System Architectures
 
Threads (operating System)
Threads (operating System)Threads (operating System)
Threads (operating System)
 
Replication in Distributed Systems
Replication in Distributed SystemsReplication in Distributed Systems
Replication in Distributed Systems
 
Cpu scheduling in operating System.
Cpu scheduling in operating System.Cpu scheduling in operating System.
Cpu scheduling in operating System.
 
Concurrency Control in Distributed Database.
Concurrency Control in Distributed Database.Concurrency Control in Distributed Database.
Concurrency Control in Distributed Database.
 
distributed shared memory
 distributed shared memory distributed shared memory
distributed shared memory
 
15. Transactions in DBMS
15. Transactions in DBMS15. Transactions in DBMS
15. Transactions in DBMS
 
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
 
13. Query Processing in DBMS
13. Query Processing in DBMS13. Query Processing in DBMS
13. Query Processing in DBMS
 
RPC: Remote procedure call
RPC: Remote procedure callRPC: Remote procedure call
RPC: Remote procedure call
 
Distributed file system
Distributed file systemDistributed file system
Distributed file system
 
Overview of Concurrency Control & Recovery in Distributed Databases
Overview of Concurrency Control & Recovery in Distributed DatabasesOverview of Concurrency Control & Recovery in Distributed Databases
Overview of Concurrency Control & Recovery in Distributed Databases
 
Memory management
Memory managementMemory management
Memory management
 
Processes and threads
Processes and threadsProcesses and threads
Processes and threads
 
Clock synchronization in distributed system
Clock synchronization in distributed systemClock synchronization in distributed system
Clock synchronization in distributed system
 
Deadlock Detection in Distributed Systems
Deadlock Detection in Distributed SystemsDeadlock Detection in Distributed Systems
Deadlock Detection in Distributed Systems
 
Transaction management and concurrency control
Transaction management and concurrency controlTransaction management and concurrency control
Transaction management and concurrency control
 
Paging and segmentation
Paging and segmentationPaging and segmentation
Paging and segmentation
 

Similar to Transactions and Concurrency Control

Dbms sixth chapter_part-1_2011
Dbms sixth chapter_part-1_2011Dbms sixth chapter_part-1_2011
Dbms sixth chapter_part-1_2011
sumit_study
 
Svetlin Nakov - Database Transactions
Svetlin Nakov - Database TransactionsSvetlin Nakov - Database Transactions
Svetlin Nakov - Database Transactions
Svetlin Nakov
 
24904 lecture11
24904 lecture1124904 lecture11
Transactionsmanagement
TransactionsmanagementTransactionsmanagement
Transactionsmanagement
Sanjeev Gupta
 
DBF-Lecture11-Chapter12.pptDatabase Principles Fundam.docx
DBF-Lecture11-Chapter12.pptDatabase Principles Fundam.docxDBF-Lecture11-Chapter12.pptDatabase Principles Fundam.docx
DBF-Lecture11-Chapter12.pptDatabase Principles Fundam.docx
randyburney60861
 
Introduction to transaction processing concepts and theory
Introduction to transaction processing concepts and theoryIntroduction to transaction processing concepts and theory
Introduction to transaction processing concepts and theory
Zainab Almugbel
 
Unit06 dbms
Unit06 dbmsUnit06 dbms
Unit06 dbms
arnold 7490
 
Chapter 4 u
Chapter 4 uChapter 4 u
Chapter 4 u
Sandeep Singh
 
DBMS-chap 2-Concurrency Control
DBMS-chap 2-Concurrency ControlDBMS-chap 2-Concurrency Control
DBMS-chap 2-Concurrency Control
Mukesh Tekwani
 
Distributed datababase Transaction and concurrency control
Distributed datababase Transaction and concurrency controlDistributed datababase Transaction and concurrency control
Distributed datababase Transaction and concurrency control
balamurugan.k Kalibalamurugan
 
Dartabase Transaction.pptx
Dartabase Transaction.pptxDartabase Transaction.pptx
Dartabase Transaction.pptx
Bibus Poudel
 
Cs501 transaction
Cs501 transactionCs501 transaction
Cs501 transaction
Kamal Singh Lodhi
 
Transactions in dbms
Transactions in dbmsTransactions in dbms
Transactions in dbms
Nancy Gulati
 
Tranasaction management
Tranasaction managementTranasaction management
Tranasaction management
Dr. C.V. Suresh Babu
 
Introduction to transaction processing
Introduction to transaction processingIntroduction to transaction processing
Introduction to transaction processing
Jafar Nesargi
 
Chapter 9 introduction to transaction processing
Chapter 9 introduction to transaction processingChapter 9 introduction to transaction processing
Chapter 9 introduction to transaction processing
Jafar Nesargi
 
Chapter 9 introduction to transaction processing
Chapter 9 introduction to transaction processingChapter 9 introduction to transaction processing
Chapter 9 introduction to transaction processing
Jafar Nesargi
 
Presentation on Transaction
Presentation on TransactionPresentation on Transaction
Presentation on Transaction
Rahul Prajapati
 
DBMS UNIT 4
DBMS UNIT 4DBMS UNIT 4
DBMS UNIT 4
SURBHI SAROHA
 
Ch15
Ch15Ch15

Similar to Transactions and Concurrency Control (20)

Dbms sixth chapter_part-1_2011
Dbms sixth chapter_part-1_2011Dbms sixth chapter_part-1_2011
Dbms sixth chapter_part-1_2011
 
Svetlin Nakov - Database Transactions
Svetlin Nakov - Database TransactionsSvetlin Nakov - Database Transactions
Svetlin Nakov - Database Transactions
 
24904 lecture11
24904 lecture1124904 lecture11
24904 lecture11
 
Transactionsmanagement
TransactionsmanagementTransactionsmanagement
Transactionsmanagement
 
DBF-Lecture11-Chapter12.pptDatabase Principles Fundam.docx
DBF-Lecture11-Chapter12.pptDatabase Principles Fundam.docxDBF-Lecture11-Chapter12.pptDatabase Principles Fundam.docx
DBF-Lecture11-Chapter12.pptDatabase Principles Fundam.docx
 
Introduction to transaction processing concepts and theory
Introduction to transaction processing concepts and theoryIntroduction to transaction processing concepts and theory
Introduction to transaction processing concepts and theory
 
Unit06 dbms
Unit06 dbmsUnit06 dbms
Unit06 dbms
 
Chapter 4 u
Chapter 4 uChapter 4 u
Chapter 4 u
 
DBMS-chap 2-Concurrency Control
DBMS-chap 2-Concurrency ControlDBMS-chap 2-Concurrency Control
DBMS-chap 2-Concurrency Control
 
Distributed datababase Transaction and concurrency control
Distributed datababase Transaction and concurrency controlDistributed datababase Transaction and concurrency control
Distributed datababase Transaction and concurrency control
 
Dartabase Transaction.pptx
Dartabase Transaction.pptxDartabase Transaction.pptx
Dartabase Transaction.pptx
 
Cs501 transaction
Cs501 transactionCs501 transaction
Cs501 transaction
 
Transactions in dbms
Transactions in dbmsTransactions in dbms
Transactions in dbms
 
Tranasaction management
Tranasaction managementTranasaction management
Tranasaction management
 
Introduction to transaction processing
Introduction to transaction processingIntroduction to transaction processing
Introduction to transaction processing
 
Chapter 9 introduction to transaction processing
Chapter 9 introduction to transaction processingChapter 9 introduction to transaction processing
Chapter 9 introduction to transaction processing
 
Chapter 9 introduction to transaction processing
Chapter 9 introduction to transaction processingChapter 9 introduction to transaction processing
Chapter 9 introduction to transaction processing
 
Presentation on Transaction
Presentation on TransactionPresentation on Transaction
Presentation on Transaction
 
DBMS UNIT 4
DBMS UNIT 4DBMS UNIT 4
DBMS UNIT 4
 
Ch15
Ch15Ch15
Ch15
 

More from Dilum Bandara

Introduction to Machine Learning
Introduction to Machine LearningIntroduction to Machine Learning
Introduction to Machine Learning
Dilum Bandara
 
Time Series Analysis and Forecasting in Practice
Time Series Analysis and Forecasting in PracticeTime Series Analysis and Forecasting in Practice
Time Series Analysis and Forecasting in Practice
Dilum Bandara
 
Introduction to Dimension Reduction with PCA
Introduction to Dimension Reduction with PCAIntroduction to Dimension Reduction with PCA
Introduction to Dimension Reduction with PCA
Dilum Bandara
 
Introduction to Descriptive & Predictive Analytics
Introduction to Descriptive & Predictive AnalyticsIntroduction to Descriptive & Predictive Analytics
Introduction to Descriptive & Predictive Analytics
Dilum Bandara
 
Introduction to Concurrent Data Structures
Introduction to Concurrent Data StructuresIntroduction to Concurrent Data Structures
Introduction to Concurrent Data Structures
Dilum Bandara
 
Hard to Paralelize Problems: Matrix-Vector and Matrix-Matrix
Hard to Paralelize Problems: Matrix-Vector and Matrix-MatrixHard to Paralelize Problems: Matrix-Vector and Matrix-Matrix
Hard to Paralelize Problems: Matrix-Vector and Matrix-Matrix
Dilum Bandara
 
Introduction to Map-Reduce Programming with Hadoop
Introduction to Map-Reduce Programming with HadoopIntroduction to Map-Reduce Programming with Hadoop
Introduction to Map-Reduce Programming with Hadoop
Dilum Bandara
 
Embarrassingly/Delightfully Parallel Problems
Embarrassingly/Delightfully Parallel ProblemsEmbarrassingly/Delightfully Parallel Problems
Embarrassingly/Delightfully Parallel Problems
Dilum Bandara
 
Introduction to Warehouse-Scale Computers
Introduction to Warehouse-Scale ComputersIntroduction to Warehouse-Scale Computers
Introduction to Warehouse-Scale Computers
Dilum Bandara
 
Introduction to Thread Level Parallelism
Introduction to Thread Level ParallelismIntroduction to Thread Level Parallelism
Introduction to Thread Level Parallelism
Dilum Bandara
 
CPU Memory Hierarchy and Caching Techniques
CPU Memory Hierarchy and Caching TechniquesCPU Memory Hierarchy and Caching Techniques
CPU Memory Hierarchy and Caching Techniques
Dilum Bandara
 
Data-Level Parallelism in Microprocessors
Data-Level Parallelism in MicroprocessorsData-Level Parallelism in Microprocessors
Data-Level Parallelism in Microprocessors
Dilum Bandara
 
Instruction Level Parallelism – Hardware Techniques
Instruction Level Parallelism – Hardware TechniquesInstruction Level Parallelism – Hardware Techniques
Instruction Level Parallelism – Hardware Techniques
Dilum Bandara
 
Instruction Level Parallelism – Compiler Techniques
Instruction Level Parallelism – Compiler TechniquesInstruction Level Parallelism – Compiler Techniques
Instruction Level Parallelism – Compiler Techniques
Dilum Bandara
 
CPU Pipelining and Hazards - An Introduction
CPU Pipelining and Hazards - An IntroductionCPU Pipelining and Hazards - An Introduction
CPU Pipelining and Hazards - An Introduction
Dilum Bandara
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
Dilum Bandara
 
High Performance Networking with Advanced TCP
High Performance Networking with Advanced TCPHigh Performance Networking with Advanced TCP
High Performance Networking with Advanced TCP
Dilum Bandara
 
Introduction to Content Delivery Networks
Introduction to Content Delivery NetworksIntroduction to Content Delivery Networks
Introduction to Content Delivery Networks
Dilum Bandara
 
Peer-to-Peer Networking Systems and Streaming
Peer-to-Peer Networking Systems and StreamingPeer-to-Peer Networking Systems and Streaming
Peer-to-Peer Networking Systems and Streaming
Dilum Bandara
 
Mobile Services
Mobile ServicesMobile Services
Mobile Services
Dilum Bandara
 

More from Dilum Bandara (20)

Introduction to Machine Learning
Introduction to Machine LearningIntroduction to Machine Learning
Introduction to Machine Learning
 
Time Series Analysis and Forecasting in Practice
Time Series Analysis and Forecasting in PracticeTime Series Analysis and Forecasting in Practice
Time Series Analysis and Forecasting in Practice
 
Introduction to Dimension Reduction with PCA
Introduction to Dimension Reduction with PCAIntroduction to Dimension Reduction with PCA
Introduction to Dimension Reduction with PCA
 
Introduction to Descriptive & Predictive Analytics
Introduction to Descriptive & Predictive AnalyticsIntroduction to Descriptive & Predictive Analytics
Introduction to Descriptive & Predictive Analytics
 
Introduction to Concurrent Data Structures
Introduction to Concurrent Data StructuresIntroduction to Concurrent Data Structures
Introduction to Concurrent Data Structures
 
Hard to Paralelize Problems: Matrix-Vector and Matrix-Matrix
Hard to Paralelize Problems: Matrix-Vector and Matrix-MatrixHard to Paralelize Problems: Matrix-Vector and Matrix-Matrix
Hard to Paralelize Problems: Matrix-Vector and Matrix-Matrix
 
Introduction to Map-Reduce Programming with Hadoop
Introduction to Map-Reduce Programming with HadoopIntroduction to Map-Reduce Programming with Hadoop
Introduction to Map-Reduce Programming with Hadoop
 
Embarrassingly/Delightfully Parallel Problems
Embarrassingly/Delightfully Parallel ProblemsEmbarrassingly/Delightfully Parallel Problems
Embarrassingly/Delightfully Parallel Problems
 
Introduction to Warehouse-Scale Computers
Introduction to Warehouse-Scale ComputersIntroduction to Warehouse-Scale Computers
Introduction to Warehouse-Scale Computers
 
Introduction to Thread Level Parallelism
Introduction to Thread Level ParallelismIntroduction to Thread Level Parallelism
Introduction to Thread Level Parallelism
 
CPU Memory Hierarchy and Caching Techniques
CPU Memory Hierarchy and Caching TechniquesCPU Memory Hierarchy and Caching Techniques
CPU Memory Hierarchy and Caching Techniques
 
Data-Level Parallelism in Microprocessors
Data-Level Parallelism in MicroprocessorsData-Level Parallelism in Microprocessors
Data-Level Parallelism in Microprocessors
 
Instruction Level Parallelism – Hardware Techniques
Instruction Level Parallelism – Hardware TechniquesInstruction Level Parallelism – Hardware Techniques
Instruction Level Parallelism – Hardware Techniques
 
Instruction Level Parallelism – Compiler Techniques
Instruction Level Parallelism – Compiler TechniquesInstruction Level Parallelism – Compiler Techniques
Instruction Level Parallelism – Compiler Techniques
 
CPU Pipelining and Hazards - An Introduction
CPU Pipelining and Hazards - An IntroductionCPU Pipelining and Hazards - An Introduction
CPU Pipelining and Hazards - An Introduction
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
High Performance Networking with Advanced TCP
High Performance Networking with Advanced TCPHigh Performance Networking with Advanced TCP
High Performance Networking with Advanced TCP
 
Introduction to Content Delivery Networks
Introduction to Content Delivery NetworksIntroduction to Content Delivery Networks
Introduction to Content Delivery Networks
 
Peer-to-Peer Networking Systems and Streaming
Peer-to-Peer Networking Systems and StreamingPeer-to-Peer Networking Systems and Streaming
Peer-to-Peer Networking Systems and Streaming
 
Mobile Services
Mobile ServicesMobile Services
Mobile Services
 

Recently uploaded

Generative AI Use cases applications solutions and implementation.pdf
Generative AI Use cases applications solutions and implementation.pdfGenerative AI Use cases applications solutions and implementation.pdf
Generative AI Use cases applications solutions and implementation.pdf
mahaffeycheryld
 
Open Channel Flow: fluid flow with a free surface
Open Channel Flow: fluid flow with a free surfaceOpen Channel Flow: fluid flow with a free surface
Open Channel Flow: fluid flow with a free surface
Indrajeet sahu
 
smart pill dispenser is designed to improve medication adherence and safety f...
smart pill dispenser is designed to improve medication adherence and safety f...smart pill dispenser is designed to improve medication adherence and safety f...
smart pill dispenser is designed to improve medication adherence and safety f...
um7474492
 
一比一原版(uofo毕业证书)美国俄勒冈大学毕业证如何办理
一比一原版(uofo毕业证书)美国俄勒冈大学毕业证如何办理一比一原版(uofo毕业证书)美国俄勒冈大学毕业证如何办理
一比一原版(uofo毕业证书)美国俄勒冈大学毕业证如何办理
upoux
 
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
ecqow
 
SCALING OF MOS CIRCUITS m .pptx
SCALING OF MOS CIRCUITS m                 .pptxSCALING OF MOS CIRCUITS m                 .pptx
SCALING OF MOS CIRCUITS m .pptx
harshapolam10
 
Height and depth gauge linear metrology.pdf
Height and depth gauge linear metrology.pdfHeight and depth gauge linear metrology.pdf
Height and depth gauge linear metrology.pdf
q30122000
 
SENTIMENT ANALYSIS ON PPT AND Project template_.pptx
SENTIMENT ANALYSIS ON PPT AND Project template_.pptxSENTIMENT ANALYSIS ON PPT AND Project template_.pptx
SENTIMENT ANALYSIS ON PPT AND Project template_.pptx
b0754201
 
原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样
原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样
原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样
ydzowc
 
一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理
uqyfuc
 
Blood finder application project report (1).pdf
Blood finder application project report (1).pdfBlood finder application project report (1).pdf
Blood finder application project report (1).pdf
Kamal Acharya
 
TIME TABLE MANAGEMENT SYSTEM testing.pptx
TIME TABLE MANAGEMENT SYSTEM testing.pptxTIME TABLE MANAGEMENT SYSTEM testing.pptx
TIME TABLE MANAGEMENT SYSTEM testing.pptx
CVCSOfficial
 
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Sinan KOZAK
 
Software Engineering and Project Management - Introduction, Modeling Concepts...
Software Engineering and Project Management - Introduction, Modeling Concepts...Software Engineering and Project Management - Introduction, Modeling Concepts...
Software Engineering and Project Management - Introduction, Modeling Concepts...
Prakhyath Rai
 
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODELDEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
ijaia
 
Tools & Techniques for Commissioning and Maintaining PV Systems W-Animations ...
Tools & Techniques for Commissioning and Maintaining PV Systems W-Animations ...Tools & Techniques for Commissioning and Maintaining PV Systems W-Animations ...
Tools & Techniques for Commissioning and Maintaining PV Systems W-Animations ...
Transcat
 
Supermarket Management System Project Report.pdf
Supermarket Management System Project Report.pdfSupermarket Management System Project Report.pdf
Supermarket Management System Project Report.pdf
Kamal Acharya
 
Applications of artificial Intelligence in Mechanical Engineering.pdf
Applications of artificial Intelligence in Mechanical Engineering.pdfApplications of artificial Intelligence in Mechanical Engineering.pdf
Applications of artificial Intelligence in Mechanical Engineering.pdf
Atif Razi
 
Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
shadow0702a
 
Software Engineering and Project Management - Software Testing + Agile Method...
Software Engineering and Project Management - Software Testing + Agile Method...Software Engineering and Project Management - Software Testing + Agile Method...
Software Engineering and Project Management - Software Testing + Agile Method...
Prakhyath Rai
 

Recently uploaded (20)

Generative AI Use cases applications solutions and implementation.pdf
Generative AI Use cases applications solutions and implementation.pdfGenerative AI Use cases applications solutions and implementation.pdf
Generative AI Use cases applications solutions and implementation.pdf
 
Open Channel Flow: fluid flow with a free surface
Open Channel Flow: fluid flow with a free surfaceOpen Channel Flow: fluid flow with a free surface
Open Channel Flow: fluid flow with a free surface
 
smart pill dispenser is designed to improve medication adherence and safety f...
smart pill dispenser is designed to improve medication adherence and safety f...smart pill dispenser is designed to improve medication adherence and safety f...
smart pill dispenser is designed to improve medication adherence and safety f...
 
一比一原版(uofo毕业证书)美国俄勒冈大学毕业证如何办理
一比一原版(uofo毕业证书)美国俄勒冈大学毕业证如何办理一比一原版(uofo毕业证书)美国俄勒冈大学毕业证如何办理
一比一原版(uofo毕业证书)美国俄勒冈大学毕业证如何办理
 
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
 
SCALING OF MOS CIRCUITS m .pptx
SCALING OF MOS CIRCUITS m                 .pptxSCALING OF MOS CIRCUITS m                 .pptx
SCALING OF MOS CIRCUITS m .pptx
 
Height and depth gauge linear metrology.pdf
Height and depth gauge linear metrology.pdfHeight and depth gauge linear metrology.pdf
Height and depth gauge linear metrology.pdf
 
SENTIMENT ANALYSIS ON PPT AND Project template_.pptx
SENTIMENT ANALYSIS ON PPT AND Project template_.pptxSENTIMENT ANALYSIS ON PPT AND Project template_.pptx
SENTIMENT ANALYSIS ON PPT AND Project template_.pptx
 
原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样
原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样
原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样
 
一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理
 
Blood finder application project report (1).pdf
Blood finder application project report (1).pdfBlood finder application project report (1).pdf
Blood finder application project report (1).pdf
 
TIME TABLE MANAGEMENT SYSTEM testing.pptx
TIME TABLE MANAGEMENT SYSTEM testing.pptxTIME TABLE MANAGEMENT SYSTEM testing.pptx
TIME TABLE MANAGEMENT SYSTEM testing.pptx
 
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
 
Software Engineering and Project Management - Introduction, Modeling Concepts...
Software Engineering and Project Management - Introduction, Modeling Concepts...Software Engineering and Project Management - Introduction, Modeling Concepts...
Software Engineering and Project Management - Introduction, Modeling Concepts...
 
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODELDEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
 
Tools & Techniques for Commissioning and Maintaining PV Systems W-Animations ...
Tools & Techniques for Commissioning and Maintaining PV Systems W-Animations ...Tools & Techniques for Commissioning and Maintaining PV Systems W-Animations ...
Tools & Techniques for Commissioning and Maintaining PV Systems W-Animations ...
 
Supermarket Management System Project Report.pdf
Supermarket Management System Project Report.pdfSupermarket Management System Project Report.pdf
Supermarket Management System Project Report.pdf
 
Applications of artificial Intelligence in Mechanical Engineering.pdf
Applications of artificial Intelligence in Mechanical Engineering.pdfApplications of artificial Intelligence in Mechanical Engineering.pdf
Applications of artificial Intelligence in Mechanical Engineering.pdf
 
Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
 
Software Engineering and Project Management - Software Testing + Agile Method...
Software Engineering and Project Management - Software Testing + Agile Method...Software Engineering and Project Management - Software Testing + Agile Method...
Software Engineering and Project Management - Software Testing + Agile Method...
 

Transactions and Concurrency Control

  • 1. Transactions & Concurrency Control CS4262 Distributed Systems Dilum Bandara Dilum.Bandara@uom.lk Some slides adapted from U Uthaiyashankar (WSO2) and Rajkumar Buyya’s
  • 2. Outline  Transactions  Properties  Classification  Transaction implementation  Concurrency control 2
  • 3. Transactions  Transactions protect a shared resource (e.g., shared data) against simultaneous access by several concurrent processes  Transactions can do much more…  They allow a process to access & modify multiple data items as a single atomic operation  All-or-nothing property 3
  • 4. Transactions in DBMS  A unit of work performed within a DBMS against a database  Treated in a coherent & reliable way independent of other transactions  2 main purposes  To provide reliable units of work that allow correct recovery from failures & keep a database consistent even in cases of (complete or partial) system failure  To provide isolation between programs accessing a database concurrently 4
  • 5. Goal of Transactions  To ensure objects managed by a server remain in a consistent state when accessed by multiple transactions in the presence of server failure  Transactions deal with process crash failures & communication omission failures  Transactions don’t deal with Byzantine failure 5
  • 6. Transaction Model  Recoverable objects  Objects that can be recovered after their server crashes  Failure atomicity  Effects of the transaction are atomic even when server crashes  Transactions require coordination among  A client program  Some recoverable objects  A coordinator 6
  • 7. Transaction Model (Cont.)  Each transaction is created & managed by a coordinator which implements the coordinator interface  Coordinator gives each transaction an identifier (TID)  Clients invoke transaction coordinator interface methods to perform a transaction  A transaction may be aborted by client or server 7
  • 8. Transaction Coordinator Interface  openTransaction() → trans  Starts a new transaction & delivers a unique TID trans  trans will be used in other operations in the transaction  closeTransaction(trans) → (commit, abort)  Ends a transaction  commit – indicates that transaction has committed  abort – Indicates that it has aborted  abortTransaction(trans)  Aborts the transaction 8
  • 9. Properties of a Transaction  Proposed by Harder & Reuter in 1983  ACID Property  Atomic  Consistent  Isolated  Durable 9
  • 10. Atomic Property  Process all of a transaction or none of it  To outside world, transaction happens indivisibly  While a transaction happens, other processes can’t see any intermediate states  Example  A file is 100 bytes long when a transaction starts to append to it  If other processes read the file during transaction, they should see & access only the 100 bytes  If transaction commits successfully, file grows instantaneously to its new size 10
  • 11. Consistent Property  Data on all systems reflects the same state  Transaction doesn’t violate system invariants  Example  In a banking system, a key invariant is the law of conservation of money  After any internal transfer, amount of money in bank must be same as it was before transfer  During internal transfer operations, this invariant may be violated  But this violation isn’t visible outside the transaction 11
  • 12. Isolated Property  Transactions don’t interact/interfere with one another  Concurrent transactions don’t interfere with each other  i.e., transactions are serializable  Example  If 2+ transactions are running at the same time, to each of them & to other processes, final result appears as though all transactions ran sequentially (in some system-dependent order) 12
  • 13. Durable Property  Effects of a completed transaction are persistent  Once a transaction commits, changes are permanent  No failure after the commit can undo results or cause them to be lost 13
  • 14. Ensuring Transaction Properties  To support “failure atomicity” & “durability”, objects must be recoverable  To support “isolation” & “consistency” server needs to synchronize operations  Perform transactions serially (sequentially)  Generally, an unacceptable solution  Allow transactions to execute concurrently, if they would have the same effect as a serial execution  Known as serializable or serially equivalent transactions 14
  • 15. Classification of Transactions  Flat transactions  Nested transactions  Distributed transactions 15
  • 16. Flat Transactions  A series of operations  Don’t allow partial results to be committed or aborted  e.g., booking multiple air lines from start to destination 16
  • 17. Nested Transactions  Constructed from a number of sub-transactions  Top-level transaction may fork off children that run in parallel to one another  Incase of failure results of some sub-transaction that committed must be undone  e.g., booking multiple air lines from start to destination 17
  • 18. Distributed Transactions  Logically, a flat, indivisible transaction that operates on distributed data  In contrast, a nested transaction is logically decomposed into a hierarchy of sub-transactions 18 Source: Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007
  • 19. Achieving Transaction Properties in Distributed Transactions  To achieve atomicity & durability  Distributed commit protocols  To achieve consistency & isolation  Concurrency control algorithms (distributed locking protocols)  We need separate distributed algorithms to handle “locking of data” & “committing entire transaction” 19
  • 20. Transaction Implementation  Consider transactions on a file system  If each process executing a transaction just updates the file it uses in place, then transactions will not be atomic  2 common implementation techniques  Private workspace  Write-ahead log 20
  • 21. Private Workspace  Provide private (local) copies  All updates on private copies  Update the original (global) copy while committing  Issues  Cost of copying everything  Possible solution  Keep a pointer to relevant file block  When writing copy file block, instead of entire file  Update original when closing file  Examples – Andrew file systems 21
  • 22. Example – Private Workspace Implementation 22 Source: Andrew S. Tanenbaum , Distributed Operating Systems
  • 23. Write-Ahead Log  Files are modified in-place  Before any changes, a record is written in a log indicating  Which transaction is making the change  Which file & block is being changed  What old & new values are  Change is made to file only after log is written successfully  Example – log structured file system  If transaction succeeds & is committed, a commit record is written in log  If transaction is aborted, log is used to revert file back to its original state – rollback 23
  • 25. Concurrency Control  Goal  Allow simultaneous execution of transactions  While enabling each transaction to be isolated & data items being manipulated are left in a consistent state  Consistency  Achieved by giving transactions access to data items in a specific order  Final result would be the same as if all transactions were run sequentially 25
  • 26. Achieving Concurrency Control  3 different managers 1. Data manager 2. Scheduler 3. Transaction manager 26
  • 27. Achieving Concurrency Control (Cont.)  Data manager  Performs actual read/write on data  Not concerned about transaction  Scheduler  Responsible for properly controlling concurrency  Determines which transaction is allowed to pass a read/write operation to data manager & at which time  Schedules individual read/write s.t. transaction isolation & consistency properties are met  Transaction manager  Guarantees transaction atomicity  Processes transaction primitives by transforming them into scheduling requests 27
  • 28.  Each site has a scheduler & data manager  Each transaction is handled by a transaction manager  Transaction manager communicates with schedulers at different sites  Scheduler may also communicate with remote data managers Distributed Concurrency Control 28
  • 29. Concurrency Control  Schedules  Concurrency control issues  Serial equivalence  Issues in aborting transactions 29
  • 30. Schedules – Example  Schedule – system dependent order of actions  Final result looks as though all transactions ran sequentially 30
  • 31. Concurrent Transaction Issues  Lost update problem  Transactions should not read a “stale” value & use it in computing a new value  Inconsistent retrievals problem  Update transactions shouldn’t interfere with retrievals  Illustrated in the context of banking examples… 31
  • 32. “Lost Update” Problem  3 bank accounts (A, B, C) with balances,  A = $100, B = $200, C = $300  Transaction T  Transfers from account A to B, for 10% increase in the B’s balance  B = $200 + ($200*10%) = $220  A = $100 – ($200*10%) = $80  Transaction U  Transfers from C to B, for 10% increase in B’s balance  B = $220 + ($220*10%) = $242  C = $300 – ($220*10%) = $278  What might happen if transactions T & U are executed concurrently? 32
  • 34. “Inconsistent Retrievals” Problem  2 bank accounts (A, B) with balances  A = $200  B = $200  Transaction V  Transfers $100 of account A to B  A = $200 - $100 = $100  B = $200 + $100 = $300  Transaction W  Computes sum of all account balances (branch total)  Total = $100 + $300 +…… = $400 + ……  What might happen if transactions V & W are executed concurrently? 34
  • 36. Serial Equivalence  Serial equivalence prevents occurrence of lost updates & inconsistent retrievals  Thus, serial equivalence is used as a criterion in concurrency control algorithms  2 transactions are serially equivalent if  All pairs of conflicting operations of 2 transactions are executed in same order at all of the objects that both transactions access 36
  • 37. Serial Equivalence (Cont.)  Consider 2 objects i & j, & 2 transactions T & U  Serially equivalent orderings require one of the following 2 conditions  T accesses i before U, and T accesses j before U  U accesses i before T, and U accesses j before T 37
  • 42. Issues in Aborting Transactions  Servers must record effects of all committed transactions & none of aborted transactions  2 well-known problems  Dirty reads  Premature writes  Both of these can occur in the presence of serially equivalent executions of transactions 42
  • 43. Example – Dirty Read 43
  • 44. Example – Premature Writes  Due to interaction between write operations on the same object belonging to different transactions  If U aborts & T commits, balance should be $105 44
  • 45. Concurrency Control Algorithms  2-Phase Locking (2PL)  Get all locks, then release them  No more lock acquisition when a lock is release  Timestamp ordering  Lamport’s time stamp  Optimistic concurrency  Go & do the changes, if there is a problem let’s handle them later  How to do these concurrently on a distributed system? 45

Editor's Notes

  1. Both T and U read the balance of B (200) T overwrites the update by U without seeing it
  2. W computes the sum before V updates account B
  3. Both T and U read the balance of B (200) T overwrites the update by U without seeing it
  4. W computes the sum before V updates account B