SlideShare une entreprise Scribd logo
1  sur  52
Concurrency Control & Recovery
 Database Consistency
 Multi User Environment(Data Sharing)
Transactions interference
System Crash
Hardware failure
Software failure
Concurrency Control
Safeguard against transaction interference
Database Recovery
Restore database to earlier consistent state
The concept of Transaction
 Action(s) by user or program to read/write in the database
 Logical unit of work against a database
 either done entirely or not even a bit of it
 Consist of SQL query and/or programming instructions
DBMS/Database Architecture
The concept of Transaction
States of Transaction
The concept of Transaction
ACID Properties of Transaction
 Atomicity : All or Nothing
 Consistency : Transform database from one consistent state to next
 Isolation : Independent of each other
 Durability : Permanent effects
Concurrency Control
Database: Shared Data
Multiple transactions, concurrent access, potential
interference
Multiple reads, No problem
Multiple reads, at least one write: Potential
interference
Concurrency: Managing concurrent access to avoid
interference
Transactional Interference: Potential Problems
Lost Update
Transactional Interference: Potential Problems
Uncommitted Dependency(Dirty Read)
Transactional Interference: Potential Problems
Inconsistent Analysis
Serializability
Schedule:A sequence of the operations by a set of
concurrent transactions that preserves the order of the
operations in each of the individual transactions.
Serial Schedule:A schedule where the operations of
each transaction are executed consecutively without any
interleaved operations from other transactions.
Nonserial Schedule:A schedule where the operations
from a set of concurrent transactions are interleaved.
Serializability
Two transactions—same data item—only read
(No Problem)
Two transaction—different data items—read/write
(No problem)
Two transactions—same data items—either of
them write (Potential Problem, the order matters)
Serializable Schedule: If the interleaved operations
of the two concurrent transactions produce the
same results, are called seriazable schedule.
Concurrency Control: Serializability
(a) And (b) are two equivalent serializable schedules
(c) Is the serial schedule
Concurrency Control: Recoverability
Serializability
●
Serialiazable schedules maitain consistency
●
Assumption: No failure
●
Potential Problem: Irrecoverable Schedule
Irrecoverable Schedule
Concurrency Control: Recoverability
Recoverable Schedule
If ITEM(a) was updated by Transaction Ti and latter on read by Tj,
then Ti should commit prior to Tj.
Concurrency Control Techniques
• Locking
• Time Stamping
• Optimistic Techniques
Concurrency Control Techniques: Locking
An item accessed/updated by one transaction may be
denied access by another transaction.
Locking
• Shared Lock(read): can only read
• Exclusive Lock(write): can do both read and write
• System support for upgrade/downgrade of locks
Two-Phase 2PL Locking Protocol
All the locking operation in a transaction must
precede the first unlock
 Growing Phase:A lock is required as soon as a data
item is accessed. May be read or write.All locks are
secured. No Unlock
 Shrinking Phase: No new lock could be acquired
after first unlock. Locks are only released.
 Upgrade allowed only in growing phase
 Downgrade allowed only in shrinking phase
Two-Phase 2PL Locking Protocol
Preventing Lost Update Problem
Two-Phase 2PL Locking Protocol
Preventing Uncommitted Dependence Problem
Two-Phase 2PL Locking Protocol
Preventing Inconsistent Analysis Problem
Two-Phase 2PL Locking Protocol
Creating Cascade rollback Problem
Two-Phase 2PL Locking Protocol
Possible Solution to cascade rollback
 Rigorous 2PL: Release all unlock at the end
 Strict 2PL: hold only exclusive unlocks till end
Deadlock:A locking problem
When two(or more) transactions wait for each other to
release their corresponding locks.
Problem: Deadlock
Deadlock:A locking problem
Solution: Rollback certain transaction(s) and restart
User should be unaware of deadlock and solution
Solution:
 Timing
 Deadlock Prevention
 Deadlock detection and recovery
Deadlock: Solutions
Timing
• System defined time slice
• If transaction timed out, aborted and restarted
automatically
• transaction may not necessarily be in deadlock
• Simple protocol, used by many commercial DBMSs
Deadlock: Solutions
Deadlock Prevention
• Two solutions by proposed by Rosenkrants et. al. (1978)
• Timestamp assigned to each transaction
• Wait-Die: older transaction wait for younger
• If younger request lock hold by older, younger aborted(die), restarted with same
timestamp (eventually gets oldest)
• Wound-Wait: younger wait for older
• If older request a lock hold by younger, younger is aborted(wounded)
Conservative 2PL
• Acquire and release all locks at once
• Advantage if lock contention is heavy: No blocking, no wait
• Low Contention: Locks are held longer
• High lock setting overheads: Must release all locks even if single
of them not granted.
• Not practical: Advanced knowledge of locks required
Deadlock: Solutions
Deadlock detection and Recovery
•TiTj shows Ti is dependent on Tj
•Shows Tj hold a resource required by Ti
•Deadlock exists if WFG contains circle TiTjTk
•Frequency of deadlock detection
• Too large: deadlock undetected
• Too small: time waisted
• Dynamic approach
Wait-for-graph
Deadlock: Solutions
Recovery
• Choice of deadlock victim
• Transaction that has been running the long
• How many dataitems have been updated
• How many dataitems to update
• How far to rallback
• Avoiding starvation
• The same transaction is the victim repeatidly
• Use a counter to count number of time a
transaction rollbacked
• If reach upper limit, use different protocol
Timestamping (Another concurrency control protocol)
Timestamp:
A unique identifier, represent the relative
starting time/order of the transactions
-- System clock or logical counter is used
Timestamping:
Older transactions get priority incase of conflict
A read and write by a transaction on a data item is
allowed only if the preceding update to the data item was made
by older transaction
Timestamping ( Timestamping continues…)
 A transact T has timestamp ts(T)
 A dataitem x has read timestamp as
read_timestamp(x) and write timestamp as
write_timestamp(x)
 Transaction T wants read x
Allowed only if ts(T)>write_timestamp(x)
 otherwise an older(earlier) transaction is trying to read a value
updated by younger(newer) transaction
Older transaction is too late, rollbacked and restarted with new
time stamp
Set read_timestamp=max(ts(T), read_timestamp(x)
Timestamping ( Timestamping continues…)
 Transaction T wants write x
 Allowed only if ts(T)>read_timestamp(x) and
ts(T)>write_timestamp(x)
If ts(T)<read_timestamp(x) then younger (newer)
transaction has already read it and is using it and older is late
in updating
Similarly if ts(T)<write_timestamp(x) then T is trying to
update x to an obsolete value
In both cases Restart T with later timestamp
Otherwise the transaction can proceed
Timestamping is serializable, but not recoverable
Timestamping(Thomas’s Write Rule)
 Transaction T wants write x
 Allowed only if ts(T)>read_timestamp(x) and
ts(T)>write_timestamp(x)
If ts(T)<read_timestamp(x) then younger (newer)
transaction has already read it and is using it and older is late
in updating
Similarly if ts(T)<write_timestamp(x) then T is trying to
update x to an obsolete value
In first case Restart T with later timestamp, as before
In the second case simply ignore update, called Ignore
Obsolete Write Rule
Otherwise the transaction can proceed
Optimistic Techniques
 Conflict (interaction between transactions) is rare, is
the basic premise
 No conflict checking, No delays
 Efficient policy where conflicts are less frequent
 Before commit, check for conflict, rollback if found
 Very efficient: No locks, no concurrency checks
 According to premise less transaction rollback
 Intolerable in environment where conflicts are frequent
 Choose another concurrency control
Optimistic Techniques
Three phases in OT
 Read Phase
Extends from start to commit
All values are read and stored in locally
Changes are made to local variables
Validation Phase
Checks serializibilty not violated, database
remain consistent
Restart transaction if conflict occurred, restart
Write Phase
If update transaction, apply changes to database
stored locally
Optimistic Techniques
 Assign timestamps start(T), validation(T), finish(T)
to each transaction T
 Validation is passed only if
All earlier should finish before T i.e.
finish(E)<start(T)
If finish(E)>start(T) then
Data items written by E are diff than read by T
 (Writes done serially)
Start(T)<finish(E)<validation(T)
Granularity for Dataitems
The size of
data item
used as unit
of
protection
Granularity of Data item
 The size of data item used as unit of protection
 Granularity has greater performance implications on concurrency
control algorith
 There is a tradeof between coarse vs fine granularity
 E.g. Granularity is not the same for updating a single record vs
80% records of a table
Coarse granularity, low degree of concurrency, low locking
information maintenance
 Fine granularity, High degree of concurrency, more locking
information maintenance
 A better approach, mixed granularity, upgrade and downgrade of
locks
Database Recovery
Restore database to correct state incase of failure
 DBMS is resilient if it is fault tolerant
Storage MediaTypes
 Volatile Primary Memory, random access, fast, but
expensive
 Non-volatile online secondary memory disk
storage, random access
 Other non volatile offline secondary storages:
MagneticTape and Optical Disk
 Suit only backup, slow, MT sequential access
Types of Failures
 System crash
 Media failure
 Application software errors
 Natural physical disasters
 Carelessness
 Sabotage
All failures involve either main memory or disk copy
Transactions and Recovery
 Unit of recovery is transaction
 Recovery manager guarantee atomicity and durability
 Database buffer complicate the issue
 Durability guarantees when database buffer flushed
 Committed transactions may not reach the database
 Buffer flushed either when full or forced written
Transactions and Recovery (continue)
In the event of failure
oActive transactions(incomplete) udone, i.e.
rollbacked
oCommitted tranactions are redone, called
rollforward
oPartial undo, when single transaction roll back
oGlobal undo, when all active transactions
rollbacked
Transactions and Recovery (continue)
Example transactions rollback/rollforward
Buffer Management
Pages brought in as soon as requested
When buffer is full, old pages replaced with new ones
Page replacement policies: FIFO, LRU
Two var associated with each page: pinCount, Dirty
On each request pinCount is incr, also called pinned
Decr by the system when done
Pinned pages can’nt be replaced
Write to disk if Dirty is set, on replacement
For new page Dirty is set to 0
Buffer Management (Continued…)
When writing pages two policies used
o Steal Policy
o Pinned pages could be stolen from the transaction, i.e.
written to disk
oAlternative is no-steal
o Force Policy
o Dirty pages are immediately written to disk on committ
o Alternative no-force
 No steal and force is simple to implement
With no-steal no rollback, with force no rollforward
 Steal and force
Steal obviate the need for large buffer space
no-force provide opportunity for later transaction to update and
then write
Recovery Facilities
o Backup Mechanism
o Logging (also called journaling)
o Checkpointing
o Recovery meneger
Backup
Offline storage of data and log files
Used if database is distroyed or damaged
Tacken at regular interval
Either complete or incremental Backup
Incr is changes after last full/incr backup
Log/Journal File
Only for
insert and
update
Type of
Record
Only for
delete
and
Update
NextRecordof thistransaction
Log/Journal File (Continues…)
Important in both recovery and performance
• Log file is some times duplexed or triplexed
• for performance, log stored on separate physical drive
• backup log file where log data is huge
• minor failures recovered from online log in short time
• Major failure from offline log
Checkpoint
 The point of synchronization b/w data and log files
 Buffers are force written
 Force write all committed and active transactions
 Also a check point record is written(consist of IDs of
Active transactions)
During Recovery
o Rollforward transactions with commit record after the
last checkpoint
o Rollback transactions without commit record
Recovery Techniques
Two types
• Major recovery if database file damaged
• Restore last back
• Apply changes from log file after last backup
• Assumption: Log file not damaged, separate
storage
• Minor recovery such as after system crash
• Rollforward/rollback certain transactions
• Use the before and after image in log file
• Two protocols deferred update and
immediate update are used
Recovery Techniques(continues…)
Deferred Update
 Don’t write until commit, no undoing if aborted
 Requires redoing committed transaction
Log File Use
1. Write start record at start
2. During write, write log record except before image, don’t
write anything to buffer or database
3. If transaction commit, write commit log record, also record
changes to database buffer/database
4. If transaction abort, do nothing, just ignore log record
During Recovery
Only rollforward, repeated failures, write operations idempotant
Recovery Techniques(continues…)
Deferred Update
 Immediately record every change, need undoing if aborted
 But still requires redoing committed transaction
Log File Use
1. Write start record at start
2. During write, write log record, both before and after image
3. After writing log, now record the changes to buffer
4. Actual changes will reach database when buffer next flushed
5. If transaction commit, write commit to database buffer
6. If transaction abort, undo required, use before image log
7. Write-ahead log protocol is a must
During Recovery
Both rollforward, using after-image, and rollback, using before-image
Recovery Techniques(continues…)
Shadow Paging
o Log-less protocol
o Maintains two page tables for a transaction, current page table
and shadow page table
o Both are the same in start
o Shadow never changed, used for recovery
o changes recorded to current
o After transaction complete, current page becomes shadow
Advantages
 No log no log overheads
 faster recovery, no undo/redo
Disadvantage
 Data fragmentation
 Periodic garbage collection of inaccessible blocks

Contenu connexe

Tendances

Transaction management DBMS
Transaction  management DBMSTransaction  management DBMS
Transaction management DBMSMegha Patel
 
16. Concurrency Control in DBMS
16. Concurrency Control in DBMS16. Concurrency Control in DBMS
16. Concurrency Control in DBMSkoolkampus
 
Presentation on dbms(relational calculus)
Presentation on dbms(relational calculus)Presentation on dbms(relational calculus)
Presentation on dbms(relational calculus)yourbookworldanil
 
Overview of Concurrency Control & Recovery in Distributed Databases
Overview of Concurrency Control & Recovery in Distributed DatabasesOverview of Concurrency Control & Recovery in Distributed Databases
Overview of Concurrency Control & Recovery in Distributed DatabasesMeghaj Mallick
 
File organization 1
File organization 1File organization 1
File organization 1Rupali Rana
 
Lock based protocols
Lock based protocolsLock based protocols
Lock based protocolsChethanMp7
 
Introduction to transaction processing concepts and theory
Introduction to transaction processing concepts and theoryIntroduction to transaction processing concepts and theory
Introduction to transaction processing concepts and theoryZainab Almugbel
 
protocols of concurrency control
protocols of concurrency controlprotocols of concurrency control
protocols of concurrency controlMOHIT DADU
 
Concurrency control
Concurrency  controlConcurrency  control
Concurrency controlJaved Khan
 
ACID- Database Transaction Properties
ACID- Database Transaction PropertiesACID- Database Transaction Properties
ACID- Database Transaction PropertiesMarkajul Hasnain Alif
 
Lecture 10 distributed database management system
Lecture 10   distributed database management systemLecture 10   distributed database management system
Lecture 10 distributed database management systememailharmeet
 

Tendances (20)

Transaction management DBMS
Transaction  management DBMSTransaction  management DBMS
Transaction management DBMS
 
16. Concurrency Control in DBMS
16. Concurrency Control in DBMS16. Concurrency Control in DBMS
16. Concurrency Control in DBMS
 
Presentation on dbms(relational calculus)
Presentation on dbms(relational calculus)Presentation on dbms(relational calculus)
Presentation on dbms(relational calculus)
 
2 phase locking protocol DBMS
2 phase locking protocol DBMS2 phase locking protocol DBMS
2 phase locking protocol DBMS
 
Overview of Concurrency Control & Recovery in Distributed Databases
Overview of Concurrency Control & Recovery in Distributed DatabasesOverview of Concurrency Control & Recovery in Distributed Databases
Overview of Concurrency Control & Recovery in Distributed Databases
 
File organization 1
File organization 1File organization 1
File organization 1
 
Lock based protocols
Lock based protocolsLock based protocols
Lock based protocols
 
Schedule in DBMS
Schedule in DBMSSchedule in DBMS
Schedule in DBMS
 
Introduction to transaction processing concepts and theory
Introduction to transaction processing concepts and theoryIntroduction to transaction processing concepts and theory
Introduction to transaction processing concepts and theory
 
Acid properties
Acid propertiesAcid properties
Acid properties
 
protocols of concurrency control
protocols of concurrency controlprotocols of concurrency control
protocols of concurrency control
 
Concurrency control
Concurrency  controlConcurrency  control
Concurrency control
 
NESTED SUBQUERY.pptx
NESTED SUBQUERY.pptxNESTED SUBQUERY.pptx
NESTED SUBQUERY.pptx
 
ACID- Database Transaction Properties
ACID- Database Transaction PropertiesACID- Database Transaction Properties
ACID- Database Transaction Properties
 
Serializability
SerializabilitySerializability
Serializability
 
Timestamp protocols
Timestamp protocolsTimestamp protocols
Timestamp protocols
 
Unit 6
Unit 6Unit 6
Unit 6
 
Database fragmentation
Database fragmentationDatabase fragmentation
Database fragmentation
 
Concurrency control
Concurrency control Concurrency control
Concurrency control
 
Lecture 10 distributed database management system
Lecture 10   distributed database management systemLecture 10   distributed database management system
Lecture 10 distributed database management system
 

En vedette

Should I move my database to the cloud?
Should I move my database to the cloud?Should I move my database to the cloud?
Should I move my database to the cloud?James Serra
 
Relational Database Design - Lecture 4 - Introduction to Databases (1007156ANR)
Relational Database Design - Lecture 4 - Introduction to Databases (1007156ANR)Relational Database Design - Lecture 4 - Introduction to Databases (1007156ANR)
Relational Database Design - Lecture 4 - Introduction to Databases (1007156ANR)Beat Signer
 
Oracle 12.2 sharded database management
Oracle 12.2 sharded database managementOracle 12.2 sharded database management
Oracle 12.2 sharded database managementLeyi (Kamus) Zhang
 
Oracle Multitenant Database 2.0 - Improvements in Oracle Database 12c Release 2
Oracle Multitenant Database 2.0 - Improvements in Oracle Database 12c Release 2Oracle Multitenant Database 2.0 - Improvements in Oracle Database 12c Release 2
Oracle Multitenant Database 2.0 - Improvements in Oracle Database 12c Release 2Markus Flechtner
 
How to generate customized java 8 code from your database
How to generate customized java 8 code from your databaseHow to generate customized java 8 code from your database
How to generate customized java 8 code from your databaseSpeedment, Inc.
 
Functional Database Strategies at Scala Bay
Functional Database Strategies at Scala BayFunctional Database Strategies at Scala Bay
Functional Database Strategies at Scala BayJason Swartz
 
Veri yapıları
Veri yapılarıVeri yapıları
Veri yapılarıtugba1107
 
Veri yapıları
Veri yapılarıVeri yapıları
Veri yapılarıtugba1107
 
Oracle Database | Computer Science
Oracle Database | Computer ScienceOracle Database | Computer Science
Oracle Database | Computer ScienceTransweb Global Inc
 
Business Intelligence and Multidimensional Database
Business Intelligence and Multidimensional DatabaseBusiness Intelligence and Multidimensional Database
Business Intelligence and Multidimensional DatabaseRussel Chowdhury
 
Deep Dive: Amazon Relational Database Service (March 2017)
Deep Dive: Amazon Relational Database Service (March 2017)Deep Dive: Amazon Relational Database Service (March 2017)
Deep Dive: Amazon Relational Database Service (March 2017)Julien SIMON
 
Multi-model database
Multi-model databaseMulti-model database
Multi-model databaseJiaheng Lu
 
Migrating to Amazon RDS with Database Migration Service
Migrating to Amazon RDS with Database Migration ServiceMigrating to Amazon RDS with Database Migration Service
Migrating to Amazon RDS with Database Migration ServiceAmazon Web Services
 
Yzm 2116 - Bölüm 4 (Stack, Yığın, Yığıt)
Yzm 2116 - Bölüm 4 (Stack, Yığın, Yığıt)Yzm 2116 - Bölüm 4 (Stack, Yığın, Yığıt)
Yzm 2116 - Bölüm 4 (Stack, Yığın, Yığıt)Deniz KILINÇ
 
Oracle Database Administration Part I covering Both Oracle 11g r2 and 12c r1
Oracle Database Administration Part I covering Both Oracle 11g r2 and 12c r1Oracle Database Administration Part I covering Both Oracle 11g r2 and 12c r1
Oracle Database Administration Part I covering Both Oracle 11g r2 and 12c r1John Boyle
 
Child psychology
Child psychologyChild psychology
Child psychologyAtul Thakur
 
Re-implementing Thrift using MDE
Re-implementing Thrift using MDERe-implementing Thrift using MDE
Re-implementing Thrift using MDESina Madani
 
Thesis: Slicing of Java Programs using the Soot Framework (2006)
Thesis:  Slicing of Java Programs using the Soot Framework (2006) Thesis:  Slicing of Java Programs using the Soot Framework (2006)
Thesis: Slicing of Java Programs using the Soot Framework (2006) Arvind Devaraj
 

En vedette (20)

Should I move my database to the cloud?
Should I move my database to the cloud?Should I move my database to the cloud?
Should I move my database to the cloud?
 
Relational Database Design - Lecture 4 - Introduction to Databases (1007156ANR)
Relational Database Design - Lecture 4 - Introduction to Databases (1007156ANR)Relational Database Design - Lecture 4 - Introduction to Databases (1007156ANR)
Relational Database Design - Lecture 4 - Introduction to Databases (1007156ANR)
 
Oracle 12.2 sharded database management
Oracle 12.2 sharded database managementOracle 12.2 sharded database management
Oracle 12.2 sharded database management
 
Oracle Multitenant Database 2.0 - Improvements in Oracle Database 12c Release 2
Oracle Multitenant Database 2.0 - Improvements in Oracle Database 12c Release 2Oracle Multitenant Database 2.0 - Improvements in Oracle Database 12c Release 2
Oracle Multitenant Database 2.0 - Improvements in Oracle Database 12c Release 2
 
How to generate customized java 8 code from your database
How to generate customized java 8 code from your databaseHow to generate customized java 8 code from your database
How to generate customized java 8 code from your database
 
Functional Database Strategies at Scala Bay
Functional Database Strategies at Scala BayFunctional Database Strategies at Scala Bay
Functional Database Strategies at Scala Bay
 
Veri yapıları
Veri yapılarıVeri yapıları
Veri yapıları
 
Veri yapıları
Veri yapılarıVeri yapıları
Veri yapıları
 
Oracle Database | Computer Science
Oracle Database | Computer ScienceOracle Database | Computer Science
Oracle Database | Computer Science
 
Business Intelligence and Multidimensional Database
Business Intelligence and Multidimensional DatabaseBusiness Intelligence and Multidimensional Database
Business Intelligence and Multidimensional Database
 
SQL azure database for DBA
SQL azure database for DBASQL azure database for DBA
SQL azure database for DBA
 
Deep Dive: Amazon Relational Database Service (March 2017)
Deep Dive: Amazon Relational Database Service (March 2017)Deep Dive: Amazon Relational Database Service (March 2017)
Deep Dive: Amazon Relational Database Service (March 2017)
 
Multi-model database
Multi-model databaseMulti-model database
Multi-model database
 
Migrating to Amazon RDS with Database Migration Service
Migrating to Amazon RDS with Database Migration ServiceMigrating to Amazon RDS with Database Migration Service
Migrating to Amazon RDS with Database Migration Service
 
Yzm 2116 - Bölüm 4 (Stack, Yığın, Yığıt)
Yzm 2116 - Bölüm 4 (Stack, Yığın, Yığıt)Yzm 2116 - Bölüm 4 (Stack, Yığın, Yığıt)
Yzm 2116 - Bölüm 4 (Stack, Yığın, Yığıt)
 
Oracle Database Administration Part I covering Both Oracle 11g r2 and 12c r1
Oracle Database Administration Part I covering Both Oracle 11g r2 and 12c r1Oracle Database Administration Part I covering Both Oracle 11g r2 and 12c r1
Oracle Database Administration Part I covering Both Oracle 11g r2 and 12c r1
 
Child psychology
Child psychologyChild psychology
Child psychology
 
Mktgplan2017
Mktgplan2017Mktgplan2017
Mktgplan2017
 
Re-implementing Thrift using MDE
Re-implementing Thrift using MDERe-implementing Thrift using MDE
Re-implementing Thrift using MDE
 
Thesis: Slicing of Java Programs using the Soot Framework (2006)
Thesis:  Slicing of Java Programs using the Soot Framework (2006) Thesis:  Slicing of Java Programs using the Soot Framework (2006)
Thesis: Slicing of Java Programs using the Soot Framework (2006)
 

Similaire à Database concurrency control &amp; recovery (1)

DBMS Presentation.pptx
DBMS Presentation.pptxDBMS Presentation.pptx
DBMS Presentation.pptxPravinBhargav1
 
Databases: Locking Methods
Databases: Locking MethodsDatabases: Locking Methods
Databases: Locking MethodsDamian T. Gordon
 
DBMS (Deadlock, deadlock prevention, 2phase locking)
DBMS (Deadlock, deadlock prevention, 2phase locking)DBMS (Deadlock, deadlock prevention, 2phase locking)
DBMS (Deadlock, deadlock prevention, 2phase locking)Gaurav Solanki
 
Chapter Three _Concurrency Control Techniques_ETU.ppt
Chapter Three _Concurrency Control Techniques_ETU.pptChapter Three _Concurrency Control Techniques_ETU.ppt
Chapter Three _Concurrency Control Techniques_ETU.ppthaymanot taddesse
 
database management system Chapter 5
database management system Chapter 5database management system Chapter 5
database management system Chapter 5Mohamad Syazwan
 
concurrencycontrol from power pint pdf a
concurrencycontrol  from power pint pdf aconcurrencycontrol  from power pint pdf a
concurrencycontrol from power pint pdf aMdAyanParwez
 
Design & Development of an Advanced Database Management System Using Multiver...
Design & Development of an Advanced Database Management System Using Multiver...Design & Development of an Advanced Database Management System Using Multiver...
Design & Development of an Advanced Database Management System Using Multiver...IOSR Journals
 
Adbms 42 deadlocks and starvation
Adbms 42 deadlocks and starvationAdbms 42 deadlocks and starvation
Adbms 42 deadlocks and starvationVaibhav Khanna
 
Svetlin Nakov - Database Transactions
Svetlin Nakov - Database TransactionsSvetlin Nakov - Database Transactions
Svetlin Nakov - Database TransactionsSvetlin Nakov
 
Concurrency note.pdf
Concurrency note.pdfConcurrency note.pdf
Concurrency note.pdfBijayNag1
 
VALIDATION BASED PROTOCOL AND MULTIPLE GRANULARITY.pptx
VALIDATION BASED PROTOCOL AND MULTIPLE GRANULARITY.pptxVALIDATION BASED PROTOCOL AND MULTIPLE GRANULARITY.pptx
VALIDATION BASED PROTOCOL AND MULTIPLE GRANULARITY.pptxSamyakJain710491
 
Unit 5 rdbms study_material
Unit 5  rdbms study_materialUnit 5  rdbms study_material
Unit 5 rdbms study_materialgayaramesh
 
Concurrency Control & Deadlock Handling
Concurrency Control & Deadlock HandlingConcurrency Control & Deadlock Handling
Concurrency Control & Deadlock HandlingMeghaj Mallick
 
Concurrency Control.pptx
Concurrency Control.pptxConcurrency Control.pptx
Concurrency Control.pptxVijaySourtha
 
Concurrency control PPT
Concurrency control PPTConcurrency control PPT
Concurrency control PPTShushrutGupta
 
Concurrency Control in Distributed Systems.pptx
Concurrency Control in Distributed Systems.pptxConcurrency Control in Distributed Systems.pptx
Concurrency Control in Distributed Systems.pptxMArshad35
 
Adbms 43 multiversion concurrency control
Adbms 43 multiversion concurrency controlAdbms 43 multiversion concurrency control
Adbms 43 multiversion concurrency controlVaibhav Khanna
 

Similaire à Database concurrency control &amp; recovery (1) (20)

DBMS Presentation.pptx
DBMS Presentation.pptxDBMS Presentation.pptx
DBMS Presentation.pptx
 
Databases: Locking Methods
Databases: Locking MethodsDatabases: Locking Methods
Databases: Locking Methods
 
DBMS (Deadlock, deadlock prevention, 2phase locking)
DBMS (Deadlock, deadlock prevention, 2phase locking)DBMS (Deadlock, deadlock prevention, 2phase locking)
DBMS (Deadlock, deadlock prevention, 2phase locking)
 
Chapter Three _Concurrency Control Techniques_ETU.ppt
Chapter Three _Concurrency Control Techniques_ETU.pptChapter Three _Concurrency Control Techniques_ETU.ppt
Chapter Three _Concurrency Control Techniques_ETU.ppt
 
database management system Chapter 5
database management system Chapter 5database management system Chapter 5
database management system Chapter 5
 
concurrencycontrol from power pint pdf a
concurrencycontrol  from power pint pdf aconcurrencycontrol  from power pint pdf a
concurrencycontrol from power pint pdf a
 
F017213747
F017213747F017213747
F017213747
 
F017213747
F017213747F017213747
F017213747
 
Design & Development of an Advanced Database Management System Using Multiver...
Design & Development of an Advanced Database Management System Using Multiver...Design & Development of an Advanced Database Management System Using Multiver...
Design & Development of an Advanced Database Management System Using Multiver...
 
Adbms 42 deadlocks and starvation
Adbms 42 deadlocks and starvationAdbms 42 deadlocks and starvation
Adbms 42 deadlocks and starvation
 
Svetlin Nakov - Database Transactions
Svetlin Nakov - Database TransactionsSvetlin Nakov - Database Transactions
Svetlin Nakov - Database Transactions
 
Concurrency note.pdf
Concurrency note.pdfConcurrency note.pdf
Concurrency note.pdf
 
VALIDATION BASED PROTOCOL AND MULTIPLE GRANULARITY.pptx
VALIDATION BASED PROTOCOL AND MULTIPLE GRANULARITY.pptxVALIDATION BASED PROTOCOL AND MULTIPLE GRANULARITY.pptx
VALIDATION BASED PROTOCOL AND MULTIPLE GRANULARITY.pptx
 
Unit 5 rdbms study_material
Unit 5  rdbms study_materialUnit 5  rdbms study_material
Unit 5 rdbms study_material
 
Concurrency Control & Deadlock Handling
Concurrency Control & Deadlock HandlingConcurrency Control & Deadlock Handling
Concurrency Control & Deadlock Handling
 
Concurrency Control.pptx
Concurrency Control.pptxConcurrency Control.pptx
Concurrency Control.pptx
 
Concurrency control PPT
Concurrency control PPTConcurrency control PPT
Concurrency control PPT
 
Concurrency Control in Distributed Systems.pptx
Concurrency Control in Distributed Systems.pptxConcurrency Control in Distributed Systems.pptx
Concurrency Control in Distributed Systems.pptx
 
Adbms 43 multiversion concurrency control
Adbms 43 multiversion concurrency controlAdbms 43 multiversion concurrency control
Adbms 43 multiversion concurrency control
 
Unit 5 dbms
Unit 5 dbmsUnit 5 dbms
Unit 5 dbms
 

Dernier

Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Seán Kennedy
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfJemuel Francisco
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxlancelewisportillo
 
Millenials and Fillennials (Ethical Challenge and Responses).pptx
Millenials and Fillennials (Ethical Challenge and Responses).pptxMillenials and Fillennials (Ethical Challenge and Responses).pptx
Millenials and Fillennials (Ethical Challenge and Responses).pptxJanEmmanBrigoli
 
TEACHER REFLECTION FORM (NEW SET........).docx
TEACHER REFLECTION FORM (NEW SET........).docxTEACHER REFLECTION FORM (NEW SET........).docx
TEACHER REFLECTION FORM (NEW SET........).docxruthvilladarez
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management SystemChristalin Nelson
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptxmary850239
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...Postal Advocate Inc.
 
ClimART Action | eTwinning Project
ClimART Action    |    eTwinning ProjectClimART Action    |    eTwinning Project
ClimART Action | eTwinning Projectjordimapav
 
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...JojoEDelaCruz
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptxmary850239
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parentsnavabharathschool99
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Celine George
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfErwinPantujan2
 

Dernier (20)

Paradigm shift in nursing research by RS MEHTA
Paradigm shift in nursing research by RS MEHTAParadigm shift in nursing research by RS MEHTA
Paradigm shift in nursing research by RS MEHTA
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
 
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptxYOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
 
Millenials and Fillennials (Ethical Challenge and Responses).pptx
Millenials and Fillennials (Ethical Challenge and Responses).pptxMillenials and Fillennials (Ethical Challenge and Responses).pptx
Millenials and Fillennials (Ethical Challenge and Responses).pptx
 
TEACHER REFLECTION FORM (NEW SET........).docx
TEACHER REFLECTION FORM (NEW SET........).docxTEACHER REFLECTION FORM (NEW SET........).docx
TEACHER REFLECTION FORM (NEW SET........).docx
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management System
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
 
ClimART Action | eTwinning Project
ClimART Action    |    eTwinning ProjectClimART Action    |    eTwinning Project
ClimART Action | eTwinning Project
 
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
 
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptxLEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
 
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptxINCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parents
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
 

Database concurrency control &amp; recovery (1)

  • 1. Concurrency Control & Recovery  Database Consistency  Multi User Environment(Data Sharing) Transactions interference System Crash Hardware failure Software failure Concurrency Control Safeguard against transaction interference Database Recovery Restore database to earlier consistent state
  • 2. The concept of Transaction  Action(s) by user or program to read/write in the database  Logical unit of work against a database  either done entirely or not even a bit of it  Consist of SQL query and/or programming instructions
  • 4. The concept of Transaction States of Transaction
  • 5. The concept of Transaction ACID Properties of Transaction  Atomicity : All or Nothing  Consistency : Transform database from one consistent state to next  Isolation : Independent of each other  Durability : Permanent effects
  • 6. Concurrency Control Database: Shared Data Multiple transactions, concurrent access, potential interference Multiple reads, No problem Multiple reads, at least one write: Potential interference Concurrency: Managing concurrent access to avoid interference
  • 8. Transactional Interference: Potential Problems Uncommitted Dependency(Dirty Read)
  • 9. Transactional Interference: Potential Problems Inconsistent Analysis
  • 10. Serializability Schedule:A sequence of the operations by a set of concurrent transactions that preserves the order of the operations in each of the individual transactions. Serial Schedule:A schedule where the operations of each transaction are executed consecutively without any interleaved operations from other transactions. Nonserial Schedule:A schedule where the operations from a set of concurrent transactions are interleaved.
  • 11. Serializability Two transactions—same data item—only read (No Problem) Two transaction—different data items—read/write (No problem) Two transactions—same data items—either of them write (Potential Problem, the order matters) Serializable Schedule: If the interleaved operations of the two concurrent transactions produce the same results, are called seriazable schedule.
  • 12. Concurrency Control: Serializability (a) And (b) are two equivalent serializable schedules (c) Is the serial schedule
  • 13. Concurrency Control: Recoverability Serializability ● Serialiazable schedules maitain consistency ● Assumption: No failure ● Potential Problem: Irrecoverable Schedule Irrecoverable Schedule
  • 14. Concurrency Control: Recoverability Recoverable Schedule If ITEM(a) was updated by Transaction Ti and latter on read by Tj, then Ti should commit prior to Tj. Concurrency Control Techniques • Locking • Time Stamping • Optimistic Techniques
  • 15. Concurrency Control Techniques: Locking An item accessed/updated by one transaction may be denied access by another transaction. Locking • Shared Lock(read): can only read • Exclusive Lock(write): can do both read and write • System support for upgrade/downgrade of locks
  • 16. Two-Phase 2PL Locking Protocol All the locking operation in a transaction must precede the first unlock  Growing Phase:A lock is required as soon as a data item is accessed. May be read or write.All locks are secured. No Unlock  Shrinking Phase: No new lock could be acquired after first unlock. Locks are only released.  Upgrade allowed only in growing phase  Downgrade allowed only in shrinking phase
  • 17. Two-Phase 2PL Locking Protocol Preventing Lost Update Problem
  • 18. Two-Phase 2PL Locking Protocol Preventing Uncommitted Dependence Problem
  • 19. Two-Phase 2PL Locking Protocol Preventing Inconsistent Analysis Problem
  • 20. Two-Phase 2PL Locking Protocol Creating Cascade rollback Problem
  • 21. Two-Phase 2PL Locking Protocol Possible Solution to cascade rollback  Rigorous 2PL: Release all unlock at the end  Strict 2PL: hold only exclusive unlocks till end
  • 22. Deadlock:A locking problem When two(or more) transactions wait for each other to release their corresponding locks. Problem: Deadlock
  • 23. Deadlock:A locking problem Solution: Rollback certain transaction(s) and restart User should be unaware of deadlock and solution Solution:  Timing  Deadlock Prevention  Deadlock detection and recovery
  • 24. Deadlock: Solutions Timing • System defined time slice • If transaction timed out, aborted and restarted automatically • transaction may not necessarily be in deadlock • Simple protocol, used by many commercial DBMSs
  • 25. Deadlock: Solutions Deadlock Prevention • Two solutions by proposed by Rosenkrants et. al. (1978) • Timestamp assigned to each transaction • Wait-Die: older transaction wait for younger • If younger request lock hold by older, younger aborted(die), restarted with same timestamp (eventually gets oldest) • Wound-Wait: younger wait for older • If older request a lock hold by younger, younger is aborted(wounded) Conservative 2PL • Acquire and release all locks at once • Advantage if lock contention is heavy: No blocking, no wait • Low Contention: Locks are held longer • High lock setting overheads: Must release all locks even if single of them not granted. • Not practical: Advanced knowledge of locks required
  • 26. Deadlock: Solutions Deadlock detection and Recovery •TiTj shows Ti is dependent on Tj •Shows Tj hold a resource required by Ti •Deadlock exists if WFG contains circle TiTjTk •Frequency of deadlock detection • Too large: deadlock undetected • Too small: time waisted • Dynamic approach Wait-for-graph
  • 27. Deadlock: Solutions Recovery • Choice of deadlock victim • Transaction that has been running the long • How many dataitems have been updated • How many dataitems to update • How far to rallback • Avoiding starvation • The same transaction is the victim repeatidly • Use a counter to count number of time a transaction rollbacked • If reach upper limit, use different protocol
  • 28. Timestamping (Another concurrency control protocol) Timestamp: A unique identifier, represent the relative starting time/order of the transactions -- System clock or logical counter is used Timestamping: Older transactions get priority incase of conflict A read and write by a transaction on a data item is allowed only if the preceding update to the data item was made by older transaction
  • 29. Timestamping ( Timestamping continues…)  A transact T has timestamp ts(T)  A dataitem x has read timestamp as read_timestamp(x) and write timestamp as write_timestamp(x)  Transaction T wants read x Allowed only if ts(T)>write_timestamp(x)  otherwise an older(earlier) transaction is trying to read a value updated by younger(newer) transaction Older transaction is too late, rollbacked and restarted with new time stamp Set read_timestamp=max(ts(T), read_timestamp(x)
  • 30. Timestamping ( Timestamping continues…)  Transaction T wants write x  Allowed only if ts(T)>read_timestamp(x) and ts(T)>write_timestamp(x) If ts(T)<read_timestamp(x) then younger (newer) transaction has already read it and is using it and older is late in updating Similarly if ts(T)<write_timestamp(x) then T is trying to update x to an obsolete value In both cases Restart T with later timestamp Otherwise the transaction can proceed Timestamping is serializable, but not recoverable
  • 31. Timestamping(Thomas’s Write Rule)  Transaction T wants write x  Allowed only if ts(T)>read_timestamp(x) and ts(T)>write_timestamp(x) If ts(T)<read_timestamp(x) then younger (newer) transaction has already read it and is using it and older is late in updating Similarly if ts(T)<write_timestamp(x) then T is trying to update x to an obsolete value In first case Restart T with later timestamp, as before In the second case simply ignore update, called Ignore Obsolete Write Rule Otherwise the transaction can proceed
  • 32. Optimistic Techniques  Conflict (interaction between transactions) is rare, is the basic premise  No conflict checking, No delays  Efficient policy where conflicts are less frequent  Before commit, check for conflict, rollback if found  Very efficient: No locks, no concurrency checks  According to premise less transaction rollback  Intolerable in environment where conflicts are frequent  Choose another concurrency control
  • 33. Optimistic Techniques Three phases in OT  Read Phase Extends from start to commit All values are read and stored in locally Changes are made to local variables Validation Phase Checks serializibilty not violated, database remain consistent Restart transaction if conflict occurred, restart Write Phase If update transaction, apply changes to database stored locally
  • 34. Optimistic Techniques  Assign timestamps start(T), validation(T), finish(T) to each transaction T  Validation is passed only if All earlier should finish before T i.e. finish(E)<start(T) If finish(E)>start(T) then Data items written by E are diff than read by T  (Writes done serially) Start(T)<finish(E)<validation(T)
  • 35. Granularity for Dataitems The size of data item used as unit of protection
  • 36. Granularity of Data item  The size of data item used as unit of protection  Granularity has greater performance implications on concurrency control algorith  There is a tradeof between coarse vs fine granularity  E.g. Granularity is not the same for updating a single record vs 80% records of a table Coarse granularity, low degree of concurrency, low locking information maintenance  Fine granularity, High degree of concurrency, more locking information maintenance  A better approach, mixed granularity, upgrade and downgrade of locks
  • 37. Database Recovery Restore database to correct state incase of failure  DBMS is resilient if it is fault tolerant
  • 38. Storage MediaTypes  Volatile Primary Memory, random access, fast, but expensive  Non-volatile online secondary memory disk storage, random access  Other non volatile offline secondary storages: MagneticTape and Optical Disk  Suit only backup, slow, MT sequential access
  • 39. Types of Failures  System crash  Media failure  Application software errors  Natural physical disasters  Carelessness  Sabotage All failures involve either main memory or disk copy
  • 40. Transactions and Recovery  Unit of recovery is transaction  Recovery manager guarantee atomicity and durability  Database buffer complicate the issue  Durability guarantees when database buffer flushed  Committed transactions may not reach the database  Buffer flushed either when full or forced written
  • 41. Transactions and Recovery (continue) In the event of failure oActive transactions(incomplete) udone, i.e. rollbacked oCommitted tranactions are redone, called rollforward oPartial undo, when single transaction roll back oGlobal undo, when all active transactions rollbacked
  • 42. Transactions and Recovery (continue) Example transactions rollback/rollforward
  • 43. Buffer Management Pages brought in as soon as requested When buffer is full, old pages replaced with new ones Page replacement policies: FIFO, LRU Two var associated with each page: pinCount, Dirty On each request pinCount is incr, also called pinned Decr by the system when done Pinned pages can’nt be replaced Write to disk if Dirty is set, on replacement For new page Dirty is set to 0
  • 44. Buffer Management (Continued…) When writing pages two policies used o Steal Policy o Pinned pages could be stolen from the transaction, i.e. written to disk oAlternative is no-steal o Force Policy o Dirty pages are immediately written to disk on committ o Alternative no-force  No steal and force is simple to implement With no-steal no rollback, with force no rollforward  Steal and force Steal obviate the need for large buffer space no-force provide opportunity for later transaction to update and then write
  • 45. Recovery Facilities o Backup Mechanism o Logging (also called journaling) o Checkpointing o Recovery meneger Backup Offline storage of data and log files Used if database is distroyed or damaged Tacken at regular interval Either complete or incremental Backup Incr is changes after last full/incr backup
  • 46. Log/Journal File Only for insert and update Type of Record Only for delete and Update NextRecordof thistransaction
  • 47. Log/Journal File (Continues…) Important in both recovery and performance • Log file is some times duplexed or triplexed • for performance, log stored on separate physical drive • backup log file where log data is huge • minor failures recovered from online log in short time • Major failure from offline log
  • 48. Checkpoint  The point of synchronization b/w data and log files  Buffers are force written  Force write all committed and active transactions  Also a check point record is written(consist of IDs of Active transactions) During Recovery o Rollforward transactions with commit record after the last checkpoint o Rollback transactions without commit record
  • 49. Recovery Techniques Two types • Major recovery if database file damaged • Restore last back • Apply changes from log file after last backup • Assumption: Log file not damaged, separate storage • Minor recovery such as after system crash • Rollforward/rollback certain transactions • Use the before and after image in log file • Two protocols deferred update and immediate update are used
  • 50. Recovery Techniques(continues…) Deferred Update  Don’t write until commit, no undoing if aborted  Requires redoing committed transaction Log File Use 1. Write start record at start 2. During write, write log record except before image, don’t write anything to buffer or database 3. If transaction commit, write commit log record, also record changes to database buffer/database 4. If transaction abort, do nothing, just ignore log record During Recovery Only rollforward, repeated failures, write operations idempotant
  • 51. Recovery Techniques(continues…) Deferred Update  Immediately record every change, need undoing if aborted  But still requires redoing committed transaction Log File Use 1. Write start record at start 2. During write, write log record, both before and after image 3. After writing log, now record the changes to buffer 4. Actual changes will reach database when buffer next flushed 5. If transaction commit, write commit to database buffer 6. If transaction abort, undo required, use before image log 7. Write-ahead log protocol is a must During Recovery Both rollforward, using after-image, and rollback, using before-image
  • 52. Recovery Techniques(continues…) Shadow Paging o Log-less protocol o Maintains two page tables for a transaction, current page table and shadow page table o Both are the same in start o Shadow never changed, used for recovery o changes recorded to current o After transaction complete, current page becomes shadow Advantages  No log no log overheads  faster recovery, no undo/redo Disadvantage  Data fragmentation  Periodic garbage collection of inaccessible blocks

Notes de l'éditeur

  1. &amp;lt;number&amp;gt;