rdbtf05 Locking
rdbtf05 Locking
Locking Concepts
• Synchronization techniques
• VMS Distributed Lock Manager
• Rdb’s uses of locking
• Tools and tricks
2
Synchronization
Techniques
• Atomic Updates
– Compiler builtins
– LDx_L/STx_C (Alpha)
– fetchadd, xchg, cmpxchg (IA64)
• Spinlocks
– Static (SCHED, IOLOCK8, MMG)
– Dynamic (PCB, Mailbox, TCPIP)
• Mutexes & Semaphores
– Posix Threads
• Locks & Resources
– Distributed Lock Manager
– Used by VMS, XQP, RMS, Rdb, etc.
3
Distributed Lock Manager
4
Distributed Lock Manager
(cont’d)
• Lock modes: NL, CR, CW, PR, PW, EX
5
Compatibility of Lock Modes
Mode of Currently Granted Lock
Requested NL CR CW PR PW EX
Mode
NL Yes Yes Yes Yes Yes Yes
CR Yes Yes Yes Yes Yes No
CW Yes Yes Yes No No No
PR Yes Yes No Yes No No
PW Yes Yes No No No No
EX Yes No No No No No
6
Distributed Lock Manager
(cont’d)
• Lock conversion
– ”UP” to more restrictive mode
– ”DONE” to less restrictive mode
– Convert to NL mode & keep lock is faster than
enqueue/dequeue new locks
• Lock queues
– Granted, Waiting & Conversion
7
Deadlocks
• Occur when any group of locks are waiting for each other in a
circular fashion
– There can be 2 or more locks involved in deadlock
A B
Waiting for Waiting for
resource resource
that B has that C has
C
Waiting for
resource
that A has
9
Lock Blocking AST
• When lock is requested, blocking AST routine may be
specified
• When incompatible lock is requested by another
process, blocking AST routine is called
– Notifies program that it is blocking some other lock request
– Also called ‘BLAST’ (BLockingAST)
• Cheaper to hold on to lock with BLKAST than to
convert up & down at high rate
– RMS bucket and record lock
– Rdb Page lock
• Used also for event notification
10
Lock Value Block
1000
882
Microseconds (Measured)
800
600
Local
400 350 Remote
200
78 79 57
6 2 4
0
GS140/525 Galaxy GS320/1000 GS140/700 CI VAX 6650 CI
Galaxy
13
Distributed Locking Costs
GS140 - CI Interconnect (estimated)
350
Elapsed Time (microseconds)
300
250
200 Network
150 Remote CPU
Local CPU
100
50
0
Local Local Remote Remote
ENQ/DEQ Convert ENQ/DEQ Convert
14
Dedicated CPU Lock Manager
15
Locking Parameters
• ENQLM process quota
– 32K in SYSUAF means unlimited
• LOCKIDTBL initial size of lock id table
– Can grow on the fly
• DEADLOCK_WAIT
– Control deadlock searches, overhead if too small
• LOCKDIRWT
– Controls portion of lock directory for this node
• PE1 controls dynamic remastering
• LCKMGR_MODE enables dedicated lckmgr
• LCKMGR_CPU controls CPU affinity of dedicated lckmgr
16
Rdb Lock Tree
Database
Device ID + File ID
Page 9987 Page 855 Logical Area 14 Page 733 Page 476
17
Rdb Lock Tools
• $ RMU /SHOW STATISTICS
• $ RMU /SHOW LOCKS
– [/MODE=BLOCKING]
– [/MODE=WAITING]
– [/MODE=CULPRIT]
18
Top 8 Interesting
Rdb Resource Types
Type Name
B Logical Area
C Snap Area Cursor
G TSNBLK
K Database key scope
L DBKEY (page/line)
P Page
R SEQBLK
U Client (subtypes: DDL, PSN, DDLctr)
19
Example Rdb Client
Resource Name
• Resource: client '....7...C1 '
20203143000000370000000400000055
– Client Lock
– Lock Type
Relation/View = 00000004
Modules = 00000015
Routines = 00000016
– Object number
– Additional information (usually 4 byte start of ASCII name)
• Enhanced formatting in Rdb 7.2
20
Example Uses of
Lock Value Block
Resource Name: TSN block 2
Lock Value Block: 00002171 00000000 00000FE2 03000001
– 00002171 00000000 - oldest TSN in block (8561)
– 00000FE2 - TSNBLK sequence (4066)
– 0001 - There is a WIP TSN in this block
– 00 - Filler byte – not used
– 03 - VALBLK_VALID + SYNCH
21
Tools & Utilities
• $ MONITOR LOCK
• $ MONITOR DLOCK
22
More Tools & Utilities
• SDA> LCK STATISTIC
• SDA> LCK SHOW ACTIVE
• SDA> LCK SHOW CONTENTION /INTER=0.1
• SDA> LCK SHOW LCKMGR /INT=10 /REP=5
• Examples
– lck_active.txt
– lck_statistic.txt
– lck_lckmgr.txt
– lck_process.txt
23
Anything Else...
Questions?
Comments?
24