






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!







SQL operations Record-oriented operationsPage-oriented operations
-^ A lock manager services the operations^ –^ Lock(trans-id, data-item-id, mode)^ –^ Unlock(trans-id, data-item-id)^ –^ Unlock(trans-id) •^ It stores locks in a lock table. Lock op inserts [trans-id, mode] in the table. Unlock deletes it.^ Data Item
List of Locks
Wait List
x^
[T,r] [T^1
,r]^2
[T,w]^3
y^
[T,w]^4
[T,w] [T^5
, r] 6
-^ In MS SQL Server^ –^ Locks are approx 32 bytes each.^ –^ Each lock contains a Database-ID, Object-Id, and otherresource-specific lock information such as record id (RID)or key.^ –^ Each lock is attached to lock resource block (64 bytes)and lock owner block (32 bytes)
-^ Granularity - size of data items to lock^ –^ e.g., files, pages, records, fields •^ Coarse granularity implies^ –^ very few locks, so little locking overhead^ –^ must lock large chunks of data, so high chance ofconflict, so concurrency may be low •^ Fine granularity implies^ –^ many locks, so high locking overhead^ –^ locking conflict occurs only when two transactions tryto access the exact same data concurrently •^ High performance TP requires record locking
-^ A set of transactions is deadlocked if every^ transaction in the set is blocked and will remainblocked unless the system intervenes.^ –^ Example
rl[x]^1
granted rl[y]^2
granted wl[x]^2
blocked wl[y]^1
blocked and
[x] rl[y] r^2
[y] … can’t run w 2
[x] w 21 [y] and be SR
-^ To repair a deadlock, you must abort a transaction^ –^ if you released a transaction’s lock without aborting it,^ you’d break 2PL
-^ Never grant a lock that can lead to deadlock •^ Often advocated in operating systems •^ Useless for TP, because it would require runningtransactions serially.^ –^ Example to prevent the previous deadlock,^ rl
[x] rl[y] wl 12
[x] wl 2 [y], the system can’t grant rl 1
[y] 2
-^ Avoiding deadlock by resource ordering is unusablein general, since it overly constrains applications.^ –^ But may help for certain high frequency deadlocks •^ Setting all locks when txn begins requires too muchadvance knowledge and reduces concurrency.
→^ Ti k^ | Tis waiting for Ti^
to release a lock}k
-^ Example (previous deadlock)
-^ Theorem: If there’s a deadlock, then the waits-forgraph has a cycle.
-^ So, to find deadlocks^ –^ when a transaction blocks, add an edge to the graph^ –^ periodically check for cycles in the waits-for graph •^ Need not test for deadlocks too often. (A cyclewon’t disappear until you detect it and break it.) •^ When a deadlock is detected, select a victim fromthe cycle and abort it. •^ Select a victim that hasn’t done much work(e.g., has set the fewest locks).