Docsity

Multigranularity Locking (MGL) and Hot Spot Techniques in Database Systems, Slides of Fundamentals of E-Commerce

Toggle sidebar
bg1
8.7 Multigranularity Locking (MGL)
•Allow different txns to lock at different granularity
–big queries should lock coarse-grained data (e.g. tables)
–short transactions lock fine-grained data (e.g. rows)
•Lock manager can’t detect these conflicts
–each data item (e.g., table or row) has a different id
•Multigranularity locking “trick”
–exploit the natural hierarchy of data containment
–before locking fine-grained data, set intention locks on
coarse grained data that contains it
–e.g., before setting a read-lock on a row, get an
intention-read-lock on the table that contains the row
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Multigranularity Locking (MGL) and Hot Spot Techniques in Database Systems and more Slides Fundamentals of E-Commerce in PDF only on Docsity!

8.7 Multigranularity Locking (MGL)

-^

Allow different txns to lock at different granularity^ –

big queries should lock coarse-grained data (e.g. tables)

short transactions lock fine-grained data (e.g. rows)

-^

Lock manager can’t detect these conflicts^ –

each data item (e.g., table or row) has a different id

-^

Multigranularity locking “trick”^ –

exploit the natural hierarchy of data containment

before locking fine-grained data, set

intention locks

on

coarse grained data that contains it

e.g., before setting a read-lock on a row, get anintention-read-lock on the table that contains the row

MGL Type and Instance Graphs

Database

Area^ File Record

DB

A

A

F

F

F

R1.

R1.

R2.

R2.

R2.

R2.

R2.

Lock Type

Graph

Lock Instance Graph

•^

Before setting a read lock on R2.3, first set an intention-readlock on DB1, then A2, and then F2.

-^

Set locks root-to-leaf. Release locks leaf-to-root.

MGL Complexities

-^

Relational DBMSs use MGL to lock SQL queries,short updates, and scans with updates.

-^

Use lock escalation - start locking at fine-grain andescalate to coarse grain after n

th

lock is set.

Area

File

Record

Index Index Entry

  • The lock type graph is a

directed acyclic graph, nota tree, to cope with indices

  • R-lock one path to an item.

W-lock all paths to it.

MS SQL Server

•^

MS SQL Server can lock at table, page, and row level.

-^

Uses intention read (“share”) and intention write(“exclusive”) locks at the table and page level.

-^

Tries to avoid escalation by choosing the “appropriate”granularity when the scan is instantiated.

Table Page

Index Range

Extent

Hot Spot Techniques (cont’d)

-^

Special techniques are needed to reduce

t

Keep the hot data in main memory

Delay operations on hot data till commit time

Use optimistic methods

Batch up operations to hot spot data

Partition hot spot data

Delaying Operations Until Commit

-^

Data manager logs each transaction’s updates

-^

Only applies the updates (and sets locks) afterreceiving Commit from the transaction

-^

IMS Fast Path uses this for^ –

Data Entry DB

Main Storage DB

-^

Works for write, insert, and delete, but not read

Solving the Threshold Problem

Another IMS Fast Path Technique

-^

Use a blind Decrement (no threshold) andVerify(x, n), which returns true if x

n

-^

Re-execute Verify at commit time^ –

If it returns a different value than it did duringnormal execution, then abort

It’s like checking that the threshold lock you didn’tset during Decrement is still valid.

bEnough = Verify(iQuantity, n);If (bEnough) Decrement(iQuantity, n)else print (“not enough”);

Optimistic Concurrency Control

-^

The Verify trick is optimistic concurrency control

-^

Main idea - execute operations on shared datawithout setting locks. At commit time, test if therewere conflicts on the locks (that you didn’t set).

-^

Often used in client/server systems^ –

Client does all updates in cache without shared locks

At commit time, try to get locks and perform updates