11. distributed con currency control - 2 of 3
TRANSCRIPT
8/3/2019 11. Distributed Con Currency Control - 2 of 3
http://slidepdf.com/reader/full/11-distributed-con-currency-control-2-of-3 1/46
Distributed Database SystemsAutumn, 2007
Chapter 11 – Part 2 of 3
Distributed
Concurrency Control
1Distributed Database Systems
8/3/2019 11. Distributed Con Currency Control - 2 of 3
http://slidepdf.com/reader/full/11-distributed-con-currency-control-2-of-3 2/46
Taxonomy Of Concurrency
Control Algorithms
Section 11.2
Distributed Database Systems 2
8/3/2019 11. Distributed Con Currency Control - 2 of 3
http://slidepdf.com/reader/full/11-distributed-con-currency-control-2-of-3 3/46
Distributed Database Systems 3
For locking-based methods,
locking granularity, i.e. the size of
the portion of database that a
lock is applied, is an importantissue. This portion is called
locking unit (lu).
8/3/2019 11. Distributed Con Currency Control - 2 of 3
http://slidepdf.com/reader/full/11-distributed-con-currency-control-2-of-3 4/46
Locking-based Concurrency
Control Algorithms
Section 11.3
Distributed Database Systems 4
8/3/2019 11. Distributed Con Currency Control - 2 of 3
http://slidepdf.com/reader/full/11-distributed-con-currency-control-2-of-3 5/46
11.3 Locking-based Concurrency Control Algorithms
Lock modes
read lock (rl), and write lock (wl). Compatibility of lock modes
In a locking-based system, the SC is a
lock manager (LM).
Distributed Database Systems 5
8/3/2019 11. Distributed Con Currency Control - 2 of 3
http://slidepdf.com/reader/full/11-distributed-con-currency-control-2-of-3 6/46
8/3/2019 11. Distributed Con Currency Control - 2 of 3
http://slidepdf.com/reader/full/11-distributed-con-currency-control-2-of-3 7/46
Basic LM Algorithm
2. For a message from the TM, LM checks if the
lu which contains the required data item is
locked:
• If so, and the locking mode is incompatible, then
put the current operation on queue;
• Otherwise
I. the lock is set in an appropriate mode, and
II. database operation is passed onto the dataprocessor, and then
III. wait for messages from the data processor.
Distributed Database Systems 7
8/3/2019 11. Distributed Con Currency Control - 2 of 3
http://slidepdf.com/reader/full/11-distributed-con-currency-control-2-of-3 8/46
Basic LM Algorithm
3. Upon the receive of a message from the
data processor:I. Release the lock on lu;
II. check if there are more locks on lu and
operations in the waiting queue and takeproper actions.
For detailed algorithm,
read algorithm 11.1 on p310-p311.
Distributed Database Systems 8
8/3/2019 11. Distributed Con Currency Control - 2 of 3
http://slidepdf.com/reader/full/11-distributed-con-currency-control-2-of-3 9/46
Basic LM Algorithm
Problem
Early release of data
Example (next page):
Distributed Database Systems 9
8/3/2019 11. Distributed Con Currency Control - 2 of 3
http://slidepdf.com/reader/full/11-distributed-con-currency-control-2-of-3 10/46
Example – Early release of data
Distributed Database Systems 10
Initial: x = 50 y = 20
Result of above scheduling:
x = 102 y = 39
Result of schedule {T1,T2}:
x = 102 y = 38
Result of schedule {T2,T1}:
x = 101 y = 39
Basic LM algorithm may generate non-serializable schedule!
8/3/2019 11. Distributed Con Currency Control - 2 of 3
http://slidepdf.com/reader/full/11-distributed-con-currency-control-2-of-3 11/46
Two-Phase Locking (2PL)
Distributed Database Systems 11
Note: (1). 2PL is serializable; (2) 2PL can cause cascading aborts!
8/3/2019 11. Distributed Con Currency Control - 2 of 3
http://slidepdf.com/reader/full/11-distributed-con-currency-control-2-of-3 12/46
Strict 2PL (S2PL)
S2PL provides degree 3 consistency!
S2PL requires minimal modification to 2PL algorithm.
Distributed Database Systems 12
8/3/2019 11. Distributed Con Currency Control - 2 of 3
http://slidepdf.com/reader/full/11-distributed-con-currency-control-2-of-3 13/46
Details
The TM algorithm and cooperative S2PLalgorithm, algorithm 11.2 and 11.3, are
presented on p314-316.
Read them for details.
Distributed Database Systems 13
8/3/2019 11. Distributed Con Currency Control - 2 of 3
http://slidepdf.com/reader/full/11-distributed-con-currency-control-2-of-3 14/46
Locking-based Concurrency
Control Algorithms
Section 11.3
Distributed Database Systems 14
Subsection 11.3.1
Centralized 2PL for Distributed Databases
8/3/2019 11. Distributed Con Currency Control - 2 of 3
http://slidepdf.com/reader/full/11-distributed-con-currency-control-2-of-3 15/46
11.3.1 Centralized 2PL for Distributed Databases
A method to delegate lock management
responsibility to a single site only, knownas primary 2PL algorithm.
◦ Coordinating TM
The TM at the site where the transaction is
initiated.
◦
Participating siteThose at which database operations to be
carried out.
Distributed Database Systems 15
8/3/2019 11. Distributed Con Currency Control - 2 of 3
http://slidepdf.com/reader/full/11-distributed-con-currency-control-2-of-3 16/46
Communication structure of centralized 2PL
Distributed Database Systems 16
Messages:
① Lock request
② Lock granted
③ Database operation
④ End of database
operation
⑤ Release locks
8/3/2019 11. Distributed Con Currency Control - 2 of 3
http://slidepdf.com/reader/full/11-distributed-con-currency-control-2-of-3 17/46
Communication structure of centralized 2PL
Algorithms for Centralized 2PL TM andLM – see algorithm 11.4 and 11.5 on
p319, 321.
Problems:
poor performance and reliability.
Distributed Database Systems 17
8/3/2019 11. Distributed Con Currency Control - 2 of 3
http://slidepdf.com/reader/full/11-distributed-con-currency-control-2-of-3 18/46
Locking-based Concurrency
Control Algorithms
Section 11.3
Distributed Database Systems 18
Subsection 11.3.2
Primary Copy 2PL
8/3/2019 11. Distributed Con Currency Control - 2 of 3
http://slidepdf.com/reader/full/11-distributed-con-currency-control-2-of-3 19/46
11.3.2 Primary Copy 2PL
Implement lock management at a number
of sites and make each lock managerresponsible for a set of lock units.
A dictionary is needed to keep the
allocation of lock managers information.
Changes from centralized 2PL to primary
copy 2PL are minimal.
Distributed Database Systems 19
8/3/2019 11. Distributed Con Currency Control - 2 of 3
http://slidepdf.com/reader/full/11-distributed-con-currency-control-2-of-3 20/46
Locking-based Concurrency
Control Algorithms
Section 11.3
Distributed Database Systems 20
Subsection 11.3.3
Distributed 2PL
8/3/2019 11. Distributed Con Currency Control - 2 of 3
http://slidepdf.com/reader/full/11-distributed-con-currency-control-2-of-3 21/46
11.3.3 Distributed 2PL
There is a lock manager at every site.
Concurrency control is accomplished bythe cooperation of lock manager at the
sites where data are involved in the set of
transactions.
If database is not replicated, distributed
2PL becomes primary copy 2PL. For replicated database, a Read One
Write All protocol is needed.Distributed Database Systems 21
8/3/2019 11. Distributed Con Currency Control - 2 of 3
http://slidepdf.com/reader/full/11-distributed-con-currency-control-2-of-3 22/46
Communication structure
Differences between centralized 2PL and
distributed 2PL can be observed by looking at
the communication structures.
Distributed Database Systems 22
Messages:
① Lock request
② Lock granted
③ End of database operation
④ Release Lock
8/3/2019 11. Distributed Con Currency Control - 2 of 3
http://slidepdf.com/reader/full/11-distributed-con-currency-control-2-of-3 23/46
Differences between centralized 2PL and distributed 2PL
Distributed Database Systems 23
① Lock request② Lock granted
③ Database operation
④ End of database operation
⑤ Release locks
① Lock request② Lock granted
③ End of database operation
④ Release Lock
Centralized 2PL Distributed 2PL
8/3/2019 11. Distributed Con Currency Control - 2 of 3
http://slidepdf.com/reader/full/11-distributed-con-currency-control-2-of-3 24/46
Timestamp-based Concurrency
Control Algorithms
Section 11.4
Distributed Database Systems 24
8/3/2019 11. Distributed Con Currency Control - 2 of 3
http://slidepdf.com/reader/full/11-distributed-con-currency-control-2-of-3 25/46
11.4 Timestamp-based Concurrency Control Algorithms
Lock method maintains serializability by
mutual exclusion. Timestamp method maintains
serializability by assigning a unique
timestamp to every transaction and
executing transactions accordingly.
Distributed Database Systems 25
8/3/2019 11. Distributed Con Currency Control - 2 of 3
http://slidepdf.com/reader/full/11-distributed-con-currency-control-2-of-3 26/46
What is a timestamp?
An identifier for transaction
Used to permit ordering Monotonicity
– timestamps generated by the same TM
are monotonically increased in values.
Distributed Database Systems 26
8/3/2019 11. Distributed Con Currency Control - 2 of 3
http://slidepdf.com/reader/full/11-distributed-con-currency-control-2-of-3 27/46
Use a monotonically increasing counter,
but this is difficult in distributedenvironment.
Use a two-tuple form:<local-counter-value, site-identifier>
Use another two-tuple form:<local-system-clock, site-identifier>
How to assign a timestamp value
Distributed Database Systems 27
site ID is put in the least significant positionto avoid the situation that timestamps from a site will always be
larger/smaller than timestamps from another site.
8/3/2019 11. Distributed Con Currency Control - 2 of 3
http://slidepdf.com/reader/full/11-distributed-con-currency-control-2-of-3 28/46
TO (Timestamps Ordering) Rule
Given two conflicting operations Oij( x)
and Okl( x
)belonging to transaction T i andT k respectively,
Oij( x) is executed before O
kl( x)
iff ts(T i) < ts(T k ),
i.e. the older transaction gets executed first.
Distributed Database Systems 28
ts(T i) - the timestamp value of transaction T i.
8/3/2019 11. Distributed Con Currency Control - 2 of 3
http://slidepdf.com/reader/full/11-distributed-con-currency-control-2-of-3 29/46
Schedule by the TO Rule
Basic procedure:
1. Check each new operation against conflicting
operations that have been scheduled;
2. IF the new operation belongs to a younger (later) transaction
than all conflicting ones THEN
accept it;
ELSE
reject it;
restart the entire transaction with a new timestamp.
Distributed Database Systems 29
This means the system maintains the execution
order according to the timestamps order.
8/3/2019 11. Distributed Con Currency Control - 2 of 3
http://slidepdf.com/reader/full/11-distributed-con-currency-control-2-of-3 30/46
Tiemstamp-based Concurrency
Control Algorithms
Section 11.4
Distributed Database Systems 30
Subsection 11.4.1
Basic TO Algorithm
8/3/2019 11. Distributed Con Currency Control - 2 of 3
http://slidepdf.com/reader/full/11-distributed-con-currency-control-2-of-3 31/46
11.4.1 Basic TO Algorithm
TM is responsible for assigning a
timestamp to each transaction andattaching it to each database operation.
Two timestamps maintained by DBMS for
each data item x for scheduling:
◦ rts( x): the largest (youngest) of timestamps of
transactions that have read x.◦ wts( x): the largest (youngest) of timestamps of
transactions that have written x.
Distributed Database Systems 31
8/3/2019 11. Distributed Con Currency Control - 2 of 3
http://slidepdf.com/reader/full/11-distributed-con-currency-control-2-of-3 32/46
8/3/2019 11. Distributed Con Currency Control - 2 of 3
http://slidepdf.com/reader/full/11-distributed-con-currency-control-2-of-3 33/46
11.4.1 Basic TO Algorithm
For write
IF ts(T ) > rts( x) AND ts(T ) > wts( x) THEN
send write( x) to DP;
rts( x) ts(T );
wts( x) ts(T ).
END IF
Distributed Database Systems 33
For basic timestamp algorithms for the TM and
scheduler, read p319 to p322.
8/3/2019 11. Distributed Con Currency Control - 2 of 3
http://slidepdf.com/reader/full/11-distributed-con-currency-control-2-of-3 34/46
Maintain timestamps among sites
When ts(T ) < rts( x), the read is rejected.
Site 2 adjusts its timestamp by making it larger than
rts( x) and restart.
Why? Avoid ts(site 1) >> ts(site 2) which may make
operations from site 2 never get executed.
Distributed Database Systems 34
8/3/2019 11. Distributed Con Currency Control - 2 of 3
http://slidepdf.com/reader/full/11-distributed-con-currency-control-2-of-3 35/46
Tiemstamp-based Concurrency
Control Algorithms
Section 11.4
Distributed Database Systems 35
Subsection 11.4.2
Conservative TO Algorithm
8/3/2019 11. Distributed Con Currency Control - 2 of 3
http://slidepdf.com/reader/full/11-distributed-con-currency-control-2-of-3 36/46
8/3/2019 11. Distributed Con Currency Control - 2 of 3
http://slidepdf.com/reader/full/11-distributed-con-currency-control-2-of-3 37/46
Basic technique
At site i, each scheduler i has one queue
Qij for each
TM at site
jin the system.
An operation from TM j is placed in Qij in
increasing timestamp order.
Scheduler i executes operation from all
queues in this order also.
Distributed Database Systems 37
This reduces the number of restarts.
But restart may occur when a queue is empty.
8/3/2019 11. Distributed Con Currency Control - 2 of 3
http://slidepdf.com/reader/full/11-distributed-con-currency-control-2-of-3 38/46
Basic technique
Suppose Q23 is empty
and scheduler 2 chooses
an operation op from
Q21 and Q22.
But later a conflictingoperation with smaller
timestamp than ts(op)
from site 3 arrives, thenthis operation must be
rejected and restarted!
Distributed Database Systems 38
8/3/2019 11. Distributed Con Currency Control - 2 of 3
http://slidepdf.com/reader/full/11-distributed-con-currency-control-2-of-3 39/46
Improvement 1
Use extremely conservative algorithm
complemented by
◦ In each queue there is at least one operation, or
◦ if a TM does not have a transaction to process, it has
to send a message periodically to inform that in the
future it will send timestamp larger than that of the
message.
Distributed Database Systems 39
Extremely conservative algorithm actually executestransaction serially at each site – too conservative!
An operation may have to wait for the coming of a
younger operation of an empty queue – a delay problem!
8/3/2019 11. Distributed Con Currency Control - 2 of 3
http://slidepdf.com/reader/full/11-distributed-con-currency-control-2-of-3 40/46
Improvement 2
Define transaction classes and set a queue
for each class instead of each TM.◦ Transaction classes are defined by their read
set and write set:
If a transaction’s read set and write set aresubset of a class, then the transaction belongs
to that class.
Distributed Database Systems 40
It is difficult to define transaction classes!
8/3/2019 11. Distributed Con Currency Control - 2 of 3
http://slidepdf.com/reader/full/11-distributed-con-currency-control-2-of-3 41/46
Tiemstamp-based Concurrency
Control Algorithms
Section 11.4
Distributed Database Systems 41
Subsection 11.4.3
MultiversionTO Algorithm
8/3/2019 11. Distributed Con Currency Control - 2 of 3
http://slidepdf.com/reader/full/11-distributed-con-currency-control-2-of-3 42/46
11.4.3 Multiversion TO Algorithm
Each write creates a new version of the
data item to be updated. Versions are
transparent to users.
Transactions are processed on a state of
database that it would have seen if theywere executed serially.
Distributed Database Systems 42
8/3/2019 11. Distributed Con Currency Control - 2 of 3
http://slidepdf.com/reader/full/11-distributed-con-currency-control-2-of-3 43/46
Work of the scheduler
For a read from transaction T i , i.e. Ri( x) :
1. Find a version of x, say xv ,s.t. ts( xv) is the largest timestamp less
than ts(T i);
2. Send Ri( xv) to the data processor.
Distributed Database Systems 43
8/3/2019 11. Distributed Con Currency Control - 2 of 3
http://slidepdf.com/reader/full/11-distributed-con-currency-control-2-of-3 44/46
Work of the scheduler
For W i( x) from transaction T i :
IF the scheduler has already processed a R j( xr )such that ts(T i)<ts( xr )<ts(T j) THEN
reject W i( x);
ELSE
translate W i( x) into W i( xw);
ts( xw) ts(T i).
Distributed Database Systems 44
8/3/2019 11. Distributed Con Currency Control - 2 of 3
http://slidepdf.com/reader/full/11-distributed-con-currency-control-2-of-3 45/46
Work of the scheduler
This scheduler generates serializable
schedule.
Versions may be purged when they are
not accessed by any transactions.
Distributed Database Systems 45
8/3/2019 11. Distributed Con Currency Control - 2 of 3
http://slidepdf.com/reader/full/11-distributed-con-currency-control-2-of-3 46/46
To be continued…