bacs 485—database management concurrency control overview of database concurrency control
Post on 22-Dec-2015
221 views
TRANSCRIPT
BACS 485—Database ManagementConcurrency Control
Concurrency Control
Overview of Database Concurrency Control
BACS 485—Database ManagementConcurrency Control
Lecture Objectives Learn the basic concepts associated
with concurrency control in a relational database environment.
Learn about serial and serializable schedules.
Learn the basic concurrency control protocols
Learn the basics of locks and timestamps as there are used in concurrency control.
BACS 485—Database ManagementConcurrency Control
Concurrency Background Modern databases gain their
usefulness by sharing data among many users.
The cost of sharing data is concurrency problems.
Modern DBMSs deal with concurrency problems by controlling the interaction among users to maintain database consistency (integrity).
BACS 485—Database ManagementConcurrency Control
Concurrency Background There are 5 basic background
concepts related to concurrency control: Multiprogramming Data Sharing Concurrent access vs. integrity
conflict Transactions Levels of concurrency control
BACS 485—Database ManagementConcurrency Control
Multiprogramming Multiprogramming is the process of
interleaving (shuffling) the operations of several programs in order to better utilize the system resources.
By quickly switching “contexts”, the illusion of simultaneous execution is possible on a single CPU computer.
BACS 485—Database ManagementConcurrency Control
Data Sharing Database systems share data to reduce
redundancy and gain better control through centralization.
Shared data that is dynamic (i.e., update, insert, delete) causes concurrency problems in database environments.
Strictly “read only” shared data does not cause concurrency problems.
BACS 485—Database ManagementConcurrency Control
Concurrency vs. Integrity There is a conflict between total
concurrent data access and database integrity.
The more concurrency that takes place, the potentially worse the integrity.
Conversely, the better the integrity, the less concurrency is possible.
The goal is to achieve a reasonable balance.
BACS 485—Database ManagementConcurrency Control
Transactions Transactions are a logical unit of
work in the database. By executing transactions, the
database moves from one consistent state to another.
Transactions are important is several areas of database theory (including concurrency).
BACS 485—Database ManagementConcurrency Control
Transactions Good transactions have the following
characteristics: Atomic – performed totally or not at all Consistency preservation – consistent state is
maintained before and after the transaction is executed.
Permanence – Changes that are “committed” are permanent. They cannot be lost.
Isolation – Transaction updates should not be visible outside of the transaction.
Serializability – Running interleaved transactions should produce the same result as running them in some serial order.
BACS 485—Database ManagementConcurrency Control
Levels of Control The concurrency mechanisms that will
be discussed in this slide set apply to multiple levels of the database.
Specifically, they can apply to: Data-item level Tuple level Table level Extent level Full database
BACS 485—Database ManagementConcurrency Control
Uncontrolled Concurrency Uncontrolled concurrency implies
that the transactions are interleaved randomly.
This causes 3 classic problems: Lost update problem Temporary update problem Incorrect summary problem
BACS 485—Database ManagementConcurrency Control
Lost Update Problem
T1 | T2 _____________________________________|____________________________
READ checking-balance |Balance = Balance - 50 |
| READ checking-balance | Balance = Balance + 100
WRITE checking-balance |READ savings-balance |
| WRITE checking-balance <-T1 updateBalance = Balance + 50 | lostWRITE savings-balance |
BACS 485—Database ManagementConcurrency Control
Temporary Update Problem
T1 | T2 _________________________________|____________________________
READ checking-balance |Balance = Balance - 50 | WRITE checking-balance |
| READ checking-balance | Balance = Balance + 100 | WRITE checking-balance
READ savings-balance |
T1 fails and must be restored -->
BACS 485—Database ManagementConcurrency Control
Incorrect Summary Problem
T1 | T2 ________________________________|____________________________
| Sum = 0| READ check-balance-1| Sum = Sum + Balance| ...
READ checking-balance-5 |Balance = Balance - 50 |WRITE check-balance-5 |
| READ check-balance-5| Sum = Sum + Balance| READ check-balance-6| Sum = Sum + Balance
READ checking-balance-6 |Balance = Balance + 50 |WRITE check-balance-6 |
How do you avoid these problems?
You can avoid the problems of uncontrolled concurrency by generating “serializable schedules.”
A “schedule” is a plan for transaction execution.
A “serial schedule” is one where there is no concurrency (one transaction after another).
A serializable schedule is one that allows instruction interleaving while still giving serial schedule results.
BACS 486—Advanced Database Management
Concurrency Control
Schedules assume… Transactions are individually correct If database consistent (i.e., correct)
before a transaction, it will be consistent after
Schedules preserve instruction order A serial execution of several
transactions is “correct” by definition Interleaved execution is “correct” it is
equivalent to any serial execution (called a “serializable schedule”)BACS 486—Advanced Database
ManagementConcurrency Control
Schedule ExampleExample: T1 transfers $50 from checking to savings while T2 takes 10% of checking and puts it into savings. Initial value checking $1000, savings $2000.
T1 T2READ checking-balance READ checking-balanceBalance = Balance - 50 Temp = Balance * 10%WRITE checking-balance Balance = Balance - TempREAD savings-balance WRITE checking-balanceBalance = Balance + 50 READ savings-balanceWRITE savings-balance Balance = Balance + Temp
WRITE savings-balance
BACS 486—Advanced Database Management
Concurrency Control
Schedule ExampleSCHEDULE 1:
T1 | T2
________________________|____________________________READ checking-balance |Balance = Balance - 50 |WRITE checking-balance |READ savings-balance |Balance = Balance + 50 |WRITE savings-balance |
| READ checking-balance| Temp = Balance * 10% | Balance = Balance - Temp| WRITE checking-balance| READ savings-balance| Balance = Balance + Temp| WRITE savings-balance
Checking Value = $855 Savings Value = $2145
BACS 486—Advanced Database Management
Concurrency Control
Schedule ExampleSCHEDULE 2:
T1 | T2________________________|____________________________
| READ checking-balance| Temp = Balance * 10%| Balance = Balance - Temp| WRITE checking-balance| READ savings-balance| Balance = Balance + Temp| WRITE savings-balance
READ checking-balance | Balance = Balance - 50 |WRITE checking-balance |READ savings-balance |Balance = Balance + 50 |WRITE savings-balance |
Checking Value = $850 Savings Value = $2150
BACS 486—Advanced Database Management
Concurrency Control
Locks and Protocols Types of simple Locks
Exclusive Locks Shared Locks (read locks) Update Locks
Lock Problems Deadlock Livelock
BACS 486—Advanced Database Management
Concurrency Control