data concurrency control and data recovery group: -lâm hoài minh triết -lê trọng an sinh

59
Data Concurrency Control And Data Recovery Group: -Lâm Hoài Minh Triết -Lê Trọng An Sinh

Upload: emmeline-francis

Post on 29-Dec-2015

222 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Data Concurrency Control And Data Recovery Group: -Lâm Hoài Minh Triết -Lê Trọng An Sinh

Data Concurrency ControlAnd Data Recovery

Group:-Lâm Hoài Minh Triết-Lê Trọng An Sinh

Page 2: Data Concurrency Control And Data Recovery Group: -Lâm Hoài Minh Triết -Lê Trọng An Sinh

Data Concurrency Control

Page 3: Data Concurrency Control And Data Recovery Group: -Lâm Hoài Minh Triết -Lê Trọng An Sinh

Content:

•Why data concurrency control !?

•Deadlock and starvation.

•Data concurrency control techniques:∙(Multiversion) Two-phase locking∙(Multiversion) Timestamp based∙Validation∙Multiple Granularity locking

Page 4: Data Concurrency Control And Data Recovery Group: -Lâm Hoài Minh Triết -Lê Trọng An Sinh

Why data concurrency control

•Databaseshared data

•Update datainconsistency

•Analoguous to Synchronization in OS∙Mutual exclusion∙Deadlock & starvation∙Validation∙Atomic transactions

Page 5: Data Concurrency Control And Data Recovery Group: -Lâm Hoài Minh Triết -Lê Trọng An Sinh

Deadlock and starvation•The same as the concept in OS

•Solutions:∙Deadlock prevention (ex:two phaselocking techniques)

∙Deadlock detection and resolution(using lock tree, and lock table to detect cycles wait-for-graph)

∙Starvation (will not be discussed here)

Page 6: Data Concurrency Control And Data Recovery Group: -Lâm Hoài Minh Triết -Lê Trọng An Sinh

Content:•Why data concurrency control !?

•Deadlock and starvation.

•Data concurrency control techniques:∙Concepts∙(Multiversion) Two-phase locking∙(Multiversion) Timestamp based∙Validation∙Multiple Granularity locking

Page 7: Data Concurrency Control And Data Recovery Group: -Lâm Hoài Minh Triết -Lê Trọng An Sinh

Data concurrency control•Basic transaction:

•Read•Write

•Basic operation:•Lock•Unlockatomic operation

•Basic modes:∙Read (shared) mode∙Write (exclusive) modeon a data item, many transactions can be in read mode, while only one transaction can bein write mode

Page 8: Data Concurrency Control And Data Recovery Group: -Lâm Hoài Minh Triết -Lê Trọng An Sinh

Data concurrency control

•Lock:

Page 9: Data Concurrency Control And Data Recovery Group: -Lâm Hoài Minh Triết -Lê Trọng An Sinh

Data concurrency control

•Unlock:

Page 10: Data Concurrency Control And Data Recovery Group: -Lâm Hoài Minh Triết -Lê Trọng An Sinh

Data concurrency control•Conflict matrix:

Page 11: Data Concurrency Control And Data Recovery Group: -Lâm Hoài Minh Triết -Lê Trọng An Sinh

Data concurrency control•Locking table:

may be implemented using linked list.lock tree•Lock manager

Page 12: Data Concurrency Control And Data Recovery Group: -Lâm Hoài Minh Triết -Lê Trọng An Sinh

Data concurrency control

•Well-formed transaction:•Lock data item before reading/writing

•Not try to unlock a free data item•Not lock an already locked dataitem

Page 13: Data Concurrency Control And Data Recovery Group: -Lâm Hoài Minh Triết -Lê Trọng An Sinh

Data concurrency control

•Lock upgrade:Read lock-->write lock

no other transactions is reading the data item

•Lock downgrade:Write lockread lock

no condition needed to be checked

Page 14: Data Concurrency Control And Data Recovery Group: -Lâm Hoài Minh Triết -Lê Trọng An Sinh

Content:•Why data concurrency control !?

•Deadlock and starvation.

•Data concurrency control techniques:∙Concepts∙(Multiversion) Two-phase locking∙(Multiversion) Timestamp based∙Validation∙Multiple Granularity locking

Page 15: Data Concurrency Control And Data Recovery Group: -Lâm Hoài Minh Triết -Lê Trọng An Sinh

Two-phase locking•Basic two-phase locking

Lock data incrementally (just lock what is being in need)

Page 16: Data Concurrency Control And Data Recovery Group: -Lâm Hoài Minh Triết -Lê Trọng An Sinh

Two-phase locking•Basic two-phase locking

Page 17: Data Concurrency Control And Data Recovery Group: -Lâm Hoài Minh Triết -Lê Trọng An Sinh

Two-phase locking

•Strict basic two-phase lockingLock data incrementally (just lock what is being in need)Unlock the data after terminating.

may cause deadlock

•Conservative: (deadlock avoding)Lock all data in need before starting.

Page 18: Data Concurrency Control And Data Recovery Group: -Lâm Hoài Minh Triết -Lê Trọng An Sinh

Content:•Why data concurrency control !?

•Deadlock and starvation.

•Data concurrency control techniques:∙Concepts∙(Multiversion) Two-phase locking∙(Multiversion) Timestamp based∙Validation∙Multiple Granularity locking

Page 19: Data Concurrency Control And Data Recovery Group: -Lâm Hoài Minh Triết -Lê Trọng An Sinh

Timestamp-based technique

•A monitornically increasing variable

the age of the transaction (timestamp)(the older the more recent)

•Use:To serialize transactions

Page 20: Data Concurrency Control And Data Recovery Group: -Lâm Hoài Minh Triết -Lê Trọng An Sinh

Timestamp-based technique

Page 21: Data Concurrency Control And Data Recovery Group: -Lâm Hoài Minh Triết -Lê Trọng An Sinh

Timestamp-based technique

Strict Order:

“Strict” only one read-transactionat a time

Page 22: Data Concurrency Control And Data Recovery Group: -Lâm Hoài Minh Triết -Lê Trọng An Sinh

Timestamp-based technique

Thomas’s rule:

T is a write-transaction

Page 23: Data Concurrency Control And Data Recovery Group: -Lâm Hoài Minh Triết -Lê Trọng An Sinh

Content:•Why data concurrency control !?

•Deadlock and starvation.

•Data concurrency control techniques:∙Concepts∙(Multiversion) Two-phase locking∙(Multiversion) Timestamp based∙Validation∙Multiple Granularity locking

Page 24: Data Concurrency Control And Data Recovery Group: -Lâm Hoài Minh Triết -Lê Trọng An Sinh

Multiversion techniques

•Modify copies only update to theoriginal version when finish modifying. (Multiverion-two-phase)(new version created when in need to modify data)

•Using timestamp to decide which version of the data will be allocated for a reading transaction.(Mutiversion-timestamp based)(the read transaction will read the version which have timestamp less thanor equal to its timestamp. )

Page 25: Data Concurrency Control And Data Recovery Group: -Lâm Hoài Minh Triết -Lê Trọng An Sinh

Multiversion techniques

•Side effects:•More memory needed.•Garbage collector.

Page 26: Data Concurrency Control And Data Recovery Group: -Lâm Hoài Minh Triết -Lê Trọng An Sinh

Content:•Why data concurrency control !?

•Deadlock and starvation.

•Data concurrency control techniques:∙Concepts∙(Multiversion) Two-phase locking∙(Multiversion) Timestamp based∙Validation ∙Multiple Granularity locking

Page 27: Data Concurrency Control And Data Recovery Group: -Lâm Hoài Minh Triết -Lê Trọng An Sinh

Validation (optimistic) scheme

•Serialization is checked before a write transaction.

•Three phase:•Read•Write divided into 2 phase: validationand write.(write to local copies only)

Page 28: Data Concurrency Control And Data Recovery Group: -Lâm Hoài Minh Triết -Lê Trọng An Sinh

Content:•Why data concurrency control !?

•Deadlock and starvation.

•Data concurrency control techniques:∙Concepts∙(Multiversion) Two-phase locking∙(Multiversion) Timestamp based∙Validation ∙Multiple Granularity locking

Page 29: Data Concurrency Control And Data Recovery Group: -Lâm Hoài Minh Triết -Lê Trọng An Sinh

Multiple Granularity Locking

•What is granularity:If we consider granularity as an index I,Then, the more components the data has,the higher the value of I .

granularity may be understood as thelevel of discreteness.

•Granularity hierachy

Page 30: Data Concurrency Control And Data Recovery Group: -Lâm Hoài Minh Triết -Lê Trọng An Sinh

Multiple Granularity Locking

•What is granularity:

Page 31: Data Concurrency Control And Data Recovery Group: -Lâm Hoài Minh Triết -Lê Trọng An Sinh

Multiple Granularity Locking•Granularity hierachy

Page 32: Data Concurrency Control And Data Recovery Group: -Lâm Hoài Minh Triết -Lê Trọng An Sinh

Multiple Granularity Locking•Three more additional locking modes are •Used:

•Intention-shared(IS): child request a shared lock on parent.

•Intention-exclusive(IX):child request anexclusive lock on parent.

•Shared-Intention-exclusive(SIX):parent is currently locked in shared mode, but Child requests an exclusive lock on parent.

Page 33: Data Concurrency Control And Data Recovery Group: -Lâm Hoài Minh Triết -Lê Trọng An Sinh

Multiple Granularity Locking•Lock-compatibility matrix:

Page 34: Data Concurrency Control And Data Recovery Group: -Lâm Hoài Minh Triết -Lê Trọng An Sinh

Multiple Granularity Locking•Lock-rule description:

Page 35: Data Concurrency Control And Data Recovery Group: -Lâm Hoài Minh Triết -Lê Trọng An Sinh

Database recovery

Page 36: Data Concurrency Control And Data Recovery Group: -Lâm Hoài Minh Triết -Lê Trọng An Sinh

Content:

•Why data recovery?

•Some techniques.

•Database recovey scheme.

•ARIES algorithm

Page 37: Data Concurrency Control And Data Recovery Group: -Lâm Hoài Minh Triết -Lê Trọng An Sinh

Why data recovery

•To bring the database into the State before the failure.

• To preseve transaction properties.

Page 38: Data Concurrency Control And Data Recovery Group: -Lâm Hoài Minh Triết -Lê Trọng An Sinh

Why data recovery

Types of Failure:

• Transaction failure.

• System failure.

• Media failure.

Page 39: Data Concurrency Control And Data Recovery Group: -Lâm Hoài Minh Triết -Lê Trọng An Sinh

Some techniques

Transaction log:

Page 40: Data Concurrency Control And Data Recovery Group: -Lâm Hoài Minh Triết -Lê Trọng An Sinh

Some techniques

Roll back & Roll forward:

Roll Back (Undo): Restore BFIM on to disk (Remove all AFIMs).

Roll Forward (Redo): Restore AFIM on to disk.

Page 41: Data Concurrency Control And Data Recovery Group: -Lâm Hoài Minh Triết -Lê Trọng An Sinh

Some techniques

T1 T2 T3read_item (A) read_item (B) read_item (C)read_item (D) write_item (B) write_item (B)write_item (D) read_item (D) read_item (A)

write_item (A) write_item (A)

Page 42: Data Concurrency Control And Data Recovery Group: -Lâm Hoài Minh Triết -Lê Trọng An Sinh

Some techniques

Data caching:

Data items to be modified are first stored into database cache by the Cache Manager (CM) and after modification they are flushed (written) to the disk.

Page 43: Data Concurrency Control And Data Recovery Group: -Lâm Hoài Minh Triết -Lê Trọng An Sinh

Some techniques

Data update

• Immediate Update

• Deferred Update

• Shadow update

• In-place update

Page 44: Data Concurrency Control And Data Recovery Group: -Lâm Hoài Minh Triết -Lê Trọng An Sinh

Some techniques

Write-Ahead Logging (WAL):

When in-place update (immediate or deferred) is used

For Undo: BFIM is written to a log.For Redo: AFIM is written to a log.

Page 45: Data Concurrency Control And Data Recovery Group: -Lâm Hoài Minh Triết -Lê Trọng An Sinh

Some techniques

Checkpointing:

• Suspend transactions temporarily.• Force write modified buffer data to disk.• Write a [checkpoint] record to the log, save the log to disk.• Resume normal transaction execution.

Page 46: Data Concurrency Control And Data Recovery Group: -Lâm Hoài Minh Triết -Lê Trọng An Sinh

Content:

•Why database recovery

•Some techniques.

•Recovery scheme

•ARIES algorithm.

Page 47: Data Concurrency Control And Data Recovery Group: -Lâm Hoài Minh Triết -Lê Trọng An Sinh

Recovery scheme

• Deferred update

• Immediate update

• Shadow paging

Page 48: Data Concurrency Control And Data Recovery Group: -Lâm Hoài Minh Triết -Lê Trọng An Sinh

Recovery scheme

• After reboot, the log is used to redo all the transactions affected by the failure. • No undo needed.

Deferred update (No Undo/ Redo):

Page 49: Data Concurrency Control And Data Recovery Group: -Lâm Hoài Minh Triết -Lê Trọng An Sinh

Recovery scheme

With check point: transactions which were recorded in the log after the last checkpoint were redone

Deferred update:

Page 50: Data Concurrency Control And Data Recovery Group: -Lâm Hoài Minh Triết -Lê Trọng An Sinh

Recovery scheme

Two table are required:Active table: all active transactionsCommit table: transactions to be committed

Deferred update :

Recovery: redo transactions in commit table only.

Page 51: Data Concurrency Control And Data Recovery Group: -Lâm Hoài Minh Triết -Lê Trọng An Sinh

Recovery scheme

• Undo / No redo:All transactions are undone.

Immediate update:

• Undo / Redo: Undo transactions in commit table & redo transactions in active table.

Page 52: Data Concurrency Control And Data Recovery Group: -Lâm Hoài Minh Triết -Lê Trọng An Sinh

Recovery scheme

Shadow paging:

Page 53: Data Concurrency Control And Data Recovery Group: -Lâm Hoài Minh Triết -Lê Trọng An Sinh

ARIES Recovery Algorithm

The ARIES Recovery Algorithm is based on:1. WAL (Write Ahead Logging)2. Repeating history during redo.3. Logging changes during undo.

Algorithms for Recovery and Isolation Exploiting Semantics

Page 54: Data Concurrency Control And Data Recovery Group: -Lâm Hoài Minh Triết -Lê Trọng An Sinh

ARIES Recovery Algorithm

The algorithm follows 3 steps:

1. Analysis2. Redo3. Undo: log is scanned backwards -> undo in the reverse order.

Page 55: Data Concurrency Control And Data Recovery Group: -Lâm Hoài Minh Triết -Lê Trọng An Sinh

ARIES Recovery Algorithm

A log record is written for: - data update - transaction commit - transaction abort - undo - transaction end - a compensating log when undo

Page 56: Data Concurrency Control And Data Recovery Group: -Lâm Hoài Minh Triết -Lê Trọng An Sinh

ARIES Recovery Algorithm

A log record stores: - Previous LSN - Transaction ID - Type of log record.For a write operation : - Page ID - Length of the updated item - Its offset - BFIM of the item - AFIM of the item

Page 57: Data Concurrency Control And Data Recovery Group: -Lâm Hoài Minh Triết -Lê Trọng An Sinh

ARIES Recovery Algorithm

Transaction table: Contains an entry for each active transaction(ID, status,LSN of the most recent log).

Dirty Page table: Contains an entry for each dirty page in the buffer (page ID and the LSN corresponding to the earliest Update)

The Transaction table and the Dirty Page table

Page 58: Data Concurrency Control And Data Recovery Group: -Lâm Hoài Minh Triết -Lê Trọng An Sinh

ARIES Recovery Algorithm

Page 59: Data Concurrency Control And Data Recovery Group: -Lâm Hoài Minh Triết -Lê Trọng An Sinh

ARIES Recovery Algorithm