Docsity

Operations - E-Commerce - Lecture Slides, Slides of Fundamentals of E-Commerce

Toggle sidebar
bg1
Which Operations Get Synchronized?
Record-oriented operations
Page-oriented operations
SQL operations
Query Optimizer
Query Executor
Access Method
(record-oriented files)
Page-oriented Files
• It’s a tradeoff between
– amount of concurrency and
– runtime expense and programming complexity
of synchronization
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Operations - E-Commerce - Lecture Slides and more Slides Fundamentals of E-Commerce in PDF only on Docsity!

Which Operations Get Synchronized?

SQL operations Record-oriented operationsPage-oriented operations

Query OptimizerQuery ExecutorAccess Method(record-oriented files)Page-oriented Files • It’s a tradeoff between – amount of concurrency and– runtime expense and programming complexityof synchronization

Lock Manager

-^ 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

Lock Manager (cont’d)

-^ 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)

Locking Granularity

-^ 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

3.7 Deadlocks

-^ 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

deadlocked • Deadlock is 2PL’s way to avoid non-SR executions – rl[x] r^11

[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

Deadlock Prevention

-^ 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.

Detection Using Waits-For Graph • Explicit deadlock detection - Use a Waits-For Graph – Nodes = {transactions} – Edges = {T

→^ Ti k^ | Tis waiting for Ti^

to release a lock}k

-^ Example (previous deadlock)

T^1

T^2

-^ Theorem: If there’s a deadlock, then the waits-forgraph has a cycle.

Detection Using Waits-For Graph

(cont’d)

-^ 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).