Top Banner
Concurrency Control Concurrency Control In In Dynamic Database Systems Dynamic Database Systems Laurel Jones Laurel Jones
22
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Concurrency Control In Dynamic Database Systems Laurel Jones.

Concurrency ControlConcurrency ControlInIn

Dynamic Database SystemsDynamic Database Systems

Laurel JonesLaurel Jones

Page 2: Concurrency Control In Dynamic Database Systems Laurel Jones.

OverviewOverview

Quick Review of what we already knowQuick Review of what we already know

Some Concurrency Control Model for Some Concurrency Control Model for Static DatabasesStatic Databases

Concurrency Control Models for Dynamic Concurrency Control Models for Dynamic DatabasesDatabases

Quick Review of what we already knowQuick Review of what we already know

Some Concurrency Control Model for Some Concurrency Control Model for Static DatabasesStatic Databases

Concurrency Control Models for Dynamic Concurrency Control Models for Dynamic DatabasesDatabases

Page 3: Concurrency Control In Dynamic Database Systems Laurel Jones.

Basic DefinitionsBasic Definitions

Concurrency ControlConcurrency Control: : Software included within the DBMS that Software included within the DBMS that

ensures data integrity in a multiuser databaseensures data integrity in a multiuser database

TransactionTransaction: : An event that has a start and stopAn event that has a start and stop Modifies the dataModifies the data

Page 4: Concurrency Control In Dynamic Database Systems Laurel Jones.

Basic Definitions con’tBasic Definitions con’tLockingLocking: : A lock is a variable associated with a data item that A lock is a variable associated with a data item that

describes the status of the item with respect to describes the status of the item with respect to possible operations that can be applied to it.possible operations that can be applied to it.

Binary Locks: mutually exclusiveBinary Locks: mutually exclusive Multiple Mode Lock:Multiple Mode Lock:

Shared/Exclusive or Read/WriteShared/Exclusive or Read/Write

Granularity:Granularity: The size of a data itemThe size of a data item Fine (small) – field of some recordFine (small) – field of some record Course (large) – whole record or disk blockCourse (large) – whole record or disk block

Page 5: Concurrency Control In Dynamic Database Systems Laurel Jones.

Basic Definitions con’tBasic Definitions con’t

Serial / Serializability / SerializableSerial / Serializability / Serializable SerialSerial – all the operations of a given – all the operations of a given

transaction are executed consecutivelytransaction are executed consecutively SerializabilitySerializability – which schedules are correct – which schedules are correct

when transactions have interleaving of their when transactions have interleaving of their operationsoperations

SerializableSerializable – refers to a schedule of – refers to a schedule of transactions that is equivalent to some serial transactions that is equivalent to some serial schedule of those same transactionsschedule of those same transactions

Page 6: Concurrency Control In Dynamic Database Systems Laurel Jones.

ExampleExample

Using binary locks or Using binary locks or read/write locks does read/write locks does NOT guarantee NOT guarantee serializability of serializability of schedules on its own.schedules on its own.

To guarantee To guarantee serializability, we must serializability, we must follow an additional follow an additional protocol concerning the protocol concerning the positioning of locking and positioning of locking and unlocking operations in unlocking operations in every transaction.every transaction.

Page 7: Concurrency Control In Dynamic Database Systems Laurel Jones.

Protocols to Maintain SerializationProtocols to Maintain Serialization

Two-Phase Locking (2PL)Two-Phase Locking (2PL)

Timestamps OrderingTimestamps Ordering

Mulitversion ConcurrencyMulitversion Concurrency

Multiversion based on TimestampMultiversion based on Timestamp

Multiversion 2PL with certify locksMultiversion 2PL with certify locks

Optimistic Concurrency Control (OCC)Optimistic Concurrency Control (OCC)

Page 8: Concurrency Control In Dynamic Database Systems Laurel Jones.

Two-Phase Locking ProtocolTwo-Phase Locking Protocol(2PL)(2PL)

All locking operations (read or write) precede the All locking operations (read or write) precede the first unlock operation in the transaction.first unlock operation in the transaction. Expanding Phase – new locks acquired but none Expanding Phase – new locks acquired but none

releasedreleased Shrinking Phase – existing locks can be released but Shrinking Phase – existing locks can be released but

no new locks can be acquired.no new locks can be acquired.

Conservative - Strict - RigorousConservative - Strict - Rigorous Conservative – locks all items accessed before Conservative – locks all items accessed before

transaction begins execution.transaction begins execution.

All but Conservative have deadlock problemsAll but Conservative have deadlock problems

Page 9: Concurrency Control In Dynamic Database Systems Laurel Jones.

Dealing with DeadlockDealing with Deadlock

TimestampsTimestampsTimeouts – aborts transactionTimeouts – aborts transactionWait-for GraphsWait-for Graphs

Page 10: Concurrency Control In Dynamic Database Systems Laurel Jones.

Optimistic Concurrency ControlOptimistic Concurrency Control(OCC)(OCC)

No checking for serialization is done while No checking for serialization is done while the transaction is executingthe transaction is executing

During transaction execution, all updates During transaction execution, all updates are applied to are applied to local copieslocal copies of the data of the data items that are kept for the transactionitems that are kept for the transaction

During a validation phase the transactions During a validation phase the transactions updates are check to see if they violate updates are check to see if they violate serializabilityserializability

Page 11: Concurrency Control In Dynamic Database Systems Laurel Jones.

Three Phases of Optimistic CCThree Phases of Optimistic CCRead PhaseRead Phase: A transaction can read values of : A transaction can read values of committed data items from the database. committed data items from the database. However, updates are applied only to local However, updates are applied only to local copies (versions) of the data items kept in the copies (versions) of the data items kept in the transaction workspacetransaction workspaceValidation PhaseValidation Phase: Checking is performed to : Checking is performed to ensure that serializability will not be violated if ensure that serializability will not be violated if the transaction updates are applied to the the transaction updates are applied to the databasedatabaseWrite PhaseWrite Phase: If the validation phase is : If the validation phase is successful, the transaction updates are applied successful, the transaction updates are applied to the database; otherwise the updates are to the database; otherwise the updates are discarded and the transaction is restarteddiscarded and the transaction is restarted

Page 12: Concurrency Control In Dynamic Database Systems Laurel Jones.

Optimistic CC con’tOptimistic CC con’t

The idea behind OCC is to do all the The idea behind OCC is to do all the checks at oncechecks at onceIf there is little interference between If there is little interference between transactions, most will be validated transactions, most will be validated successfully.successfully.Extra Requirements:Extra Requirements: Local CopyLocal Copy Transaction TimestampsTransaction Timestamps Must keep track of write_set & read_setMust keep track of write_set & read_set

Page 13: Concurrency Control In Dynamic Database Systems Laurel Jones.

OCC Validation PhaseOCC Validation PhaseDuring Validation the current transaction is During Validation the current transaction is checked against other transactions that are either checked against other transactions that are either in the validation phase or have been committedin the validation phase or have been committed

Given the current transaction TGiven the current transaction T i i and the and the

transactions it is being checked against Ttransactions it is being checked against T j j :: TTjj completes its write phase before T completes its write phase before T ii starts read phase. starts read phase.

TTii completes its write phase after T completes its write phase after T jj completes its write phase and T completes its write phase and T ii’s read_set has ’s read_set has

no items in common with Tno items in common with T jj’s write_set.’s write_set.

TTii read_set & write_set have no common items to T read_set & write_set have no common items to T jj’s write_set, and T’s write_set, and Tjj completes completes

its read phase before Tits read phase before Tii completes its read phase. completes its read phase.

These are checked in order and if at least one is These are checked in order and if at least one is true the transaction validates otherwise it is true the transaction validates otherwise it is restarted.restarted.

Page 14: Concurrency Control In Dynamic Database Systems Laurel Jones.

What is a Dynamic Database?What is a Dynamic Database?

Real-Time DBReal-Time DB Timing Constraints called “deadlines”Timing Constraints called “deadlines”

Soft/Firm vs HardSoft/Firm vs Hard

Firm transactions must give in to hard transations Firm transactions must give in to hard transations due to their stringent timing requirement.due to their stringent timing requirement.

Active DB Systems:Active DB Systems: A DB that is capable of initiation actionsA DB that is capable of initiation actions Event – Condition – Action (triggering)Event – Condition – Action (triggering)

Put these together and you get:Put these together and you get:

Page 15: Concurrency Control In Dynamic Database Systems Laurel Jones.

Real-Time Active Database Real-Time Active Database Systems (RTABS)Systems (RTABS)

““The application domains for such The application domains for such databases are numerous – network databases are numerous – network management, manufacturing process management, manufacturing process control, intelligent highway systems and control, intelligent highway systems and air traffic control.”air traffic control.”

Let’s take a look at a real world example:Let’s take a look at a real world example: Traffic Collision Avoidance SystemTraffic Collision Avoidance System July 1, 2002July 1, 2002 Timeliness and correctness of data is crucialTimeliness and correctness of data is crucial

Page 16: Concurrency Control In Dynamic Database Systems Laurel Jones.

The Importance of Concurrency The Importance of Concurrency Control in Dynamic DatabasesControl in Dynamic Databases

Many spin-offs of 2PL and OCCMany spin-offs of 2PL and OCC““In firm or hard real-time scenarios (i.e. In firm or hard real-time scenarios (i.e. where late transactions are worthless), where late transactions are worthless), optimistic concurrency control (OCC) optimistic concurrency control (OCC) outperforms locking over a large spectrum outperforms locking over a large spectrum of system loading and resource contention of system loading and resource contention conditions.” conditions.” Datta & SonDatta & Son

Page 17: Concurrency Control In Dynamic Database Systems Laurel Jones.

Modifying OCCModifying OCC

““It has been repeatedly shown that it is the It has been repeatedly shown that it is the number of restarts that determines the number of restarts that determines the performance of real-time CC algorithms.”performance of real-time CC algorithms.”Datta & SonDatta & Son

This has given rise to:This has given rise to: OCC-FV (forward validation)OCC-FV (forward validation) OCC-BV (backward validation)OCC-BV (backward validation) OCC-DA (dynamic adjust)OCC-DA (dynamic adjust) OCC-BC (broadcast commit)OCC-BC (broadcast commit) OCC-APFO (Adaptive Priority Fan Out)OCC-APFO (Adaptive Priority Fan Out)

Page 18: Concurrency Control In Dynamic Database Systems Laurel Jones.

Decreasing Restarts in OCCDecreasing Restarts in OCC

Dynamically Adjusting the serializationDynamically Adjusting the serialization Backward Validation (BV) – check against Backward Validation (BV) – check against

committed transactionscommitted transactions Forward Validation (FV) – check against Forward Validation (FV) – check against

concurrent executing transactionsconcurrent executing transactions

Page 19: Concurrency Control In Dynamic Database Systems Laurel Jones.

When Transactions Conflict When Transactions Conflict IrreconcilablyIrreconcilably

Which one do you restart?Which one do you restart? DeadlinesDeadlines

Transaction A might be targeted to restart but if it Transaction A might be targeted to restart but if it is restarted it has no hope of making its deadline. is restarted it has no hope of making its deadline. If transaction B will have time to complete restart it If transaction B will have time to complete restart it instead.instead. Firm/soft transactions continually blocked by hardFirm/soft transactions continually blocked by hard

TriggeringTriggeringIf transaction A is targeted to restart but it has If transaction A is targeted to restart but it has triggered several other transactions while B does triggered several other transactions while B does not you might want to restart B instead.not you might want to restart B instead.Deadlines of triggered transactions.Deadlines of triggered transactions.

Page 20: Concurrency Control In Dynamic Database Systems Laurel Jones.

Adaptive Priority Fan OutAdaptive Priority Fan Out OCC-APFO OCC-APFO

In this model the “Fan Out” refers to In this model the “Fan Out” refers to adjusting for the number of “triggered” adjusting for the number of “triggered” transactionstransactions

A Concurrency Priority Index (CPI) which A Concurrency Priority Index (CPI) which takes into account the deadlines and fan-takes into account the deadlines and fan-out of the transactionsout of the transactions

Page 21: Concurrency Control In Dynamic Database Systems Laurel Jones.

Adaptive Priority Fan OutAdaptive Priority Fan Out OCC-APFO con’t OCC-APFO con’t

This model also takes into consideration This model also takes into consideration that if a specific transaction is targeted for that if a specific transaction is targeted for restart it still may not have enough time to restart it still may not have enough time to meet it’s deadline.meet it’s deadline.““OCC-APFO attempts to satisfy this goal OCC-APFO attempts to satisfy this goal (of reducing restarts) by restarting (of reducing restarts) by restarting validating transactions only when it feels validating transactions only when it feels that the restarted transaction is very likely that the restarted transaction is very likely to commit eventually” to commit eventually” Datta & SonDatta & Son

Page 22: Concurrency Control In Dynamic Database Systems Laurel Jones.

In ConclusionIn ConclusionThere are many different models used to ensure There are many different models used to ensure concurrency control in Dynamic Databases.concurrency control in Dynamic Databases.

OCC-APFO is one model that seemed to take in OCC-APFO is one model that seemed to take in a variety variables when trying to reduce a variety variables when trying to reduce restarts:restarts: Dynamic serialization adjustmentsDynamic serialization adjustments DeadlinesDeadlines Triggered TransactionTriggered Transaction

How many, and their deadlinesHow many, and their deadlines Will the restarted transaction be able to commitWill the restarted transaction be able to commit

Back to reality (TCAS vs. Humans (ATC))Back to reality (TCAS vs. Humans (ATC))