Distributed Con Currency Control - 2 of 3
Distributed Con Currency Control - 2 of 3
Section 11.2
For locking-based methods, locking granularity, i.e. the size of the portion of database that a lock is applied, is an important issue. This portion is called locking unit (lu).
Distributed Database Systems 3
Section 11.3
Lock modes read lock (rl), and write lock (wl). Compatibility of lock modes
Basic LM Algorithm
1.
LM receives DB operations and associated information (transaction ID etc.) from the TM, or a message from the data processor.
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 data processor, and then III. wait for messages from the data processor.
Basic LM Algorithm
3.
Basic LM Algorithm
Problem
Note: (1). 2PL is serializable; (2) 2PL can cause cascading aborts!
Distributed Database Systems 11
S2PL provides degree 3 consistency! S2PL requires minimal modification to 2PL algorithm.
Distributed Database Systems 12
Details
The TM algorithm and cooperative S2PL algorithm, algorithm 11.2 and 11.3, are presented on p314-316. Read them for details.
13
Section 11.3
14
A method to delegate lock management responsibility to a single site only, known as primary 2PL algorithm.
Coordinating TM The TM at the site where the transaction is initiated. Participating site Those at which database operations to be carried out.
Distributed Database Systems 15
16
Algorithms for Centralized 2PL TM and LM see algorithm 11.4 and 11.5 on p319, 321. Problems: poor performance and reliability.
17
Section 11.3
18
19
Section 11.3
Distributed 2PL
20
Communication structure
Messages: Lock request Lock granted End of database operation Release Lock
Differences between centralized 2PL and distributed 2PL can be observed by looking at the communication structures.
Distributed Database Systems 22
Lock request Lock granted Database operation End of database operation Release locks
23
Section 11.4
24
Lock method maintains serializability by mutual exclusion. Timestamp method maintains serializability by assigning a unique timestamp to every transaction and executing transactions accordingly.
25
What is a timestamp?
An identifier for transaction Used to permit ordering Monotonicity timestamps generated by the same TM are monotonically increased in values.
26
ELSE
reject it; restart the entire transaction with a new timestamp.
This means the system maintains the execution order according to the timestamps order.
Distributed Database Systems 29
Section 11.4
Basic TO Algorithm
30
For read
IF ts(T) > rts(x) THEN send read(x) to DP; rts(x) ts(T). END IF
32
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
Section 11.4
Conservative TO Algorithm
35
36
Basic technique
At site i, each scheduler i has one queue Qij for each TM at site j in the system. An operation from TMj is placed in Qij in increasing timestamp order. Scheduler i executes operation from all queues in this order also.
This reduces the number of restarts. But restart may occur when a queue is empty.
37
Basic technique
Suppose Q23 is empty and scheduler 2 chooses an operation op from Q21 and Q22. But later a conflicting operation with smaller timestamp than ts(op) from site 3 arrives, then this operation must be rejected and restarted!
Distributed Database Systems 38
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. Extremely conservative algorithm actually executes transaction 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!
Distributed Database Systems 39
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 transactions read set and write set are subset of a class, then the transaction belongs to that class.
Section 11.4
Multiversion TO Algorithm
41
42
43
ELSE
translate Wi(x) into Wi(xw); ts(xw) ts(Ti).
44
45
To be continued
46