Docsity

CONCURRENCY CONTROL - Database Management Systems (DBMS), Lecture notes of Database Management Systems (DBMS)

Toggle sidebar
bg1
UNIT V
Concurrency Control: Lock-based Protocols, Timestamp-based Protocols, Validation-based Protocols,
Multiple Granularity, Multi-version Schemes, Deadlock Handling, Insert and Delete Operations, Weak
Levels of Consistency, Concurrency of Index Structures.
Recovery System: Failure Classification, Storage Structure, Recovery and Atomicity, Log-Based
Recovery, Recovery with Concurrent Transactions, Buffer Management, Failure with Loss of
Nonvolatile Storage, Advanced Recovery Techniques, Remote Backup Systems
CONCURRENCY CONTROL
LOCK-BASED PROTOCOLS:
A locking protocol is a set of rules followed by all transactions while requesting and releasing
locks. Locking protocols restrict the set of possible schedules.
A lock is a mechanism to control concurrent access to a data item. Data items can be locked in two
modes:
1. exclusive (X) mode. Data item can be both read as well as written. X-lock is requested using
lock-X instruction.
2. shared (S) mode. Data item can only be read. S-lock is requested using lock-S instruction.
Lock requests are made to concurrency-control manager. Transaction can proceed only after request
is granted.
Lock-compatibility matrix:
๏ƒ˜ A transaction may be granted a lock on an item if the requested lock is compatible with locks
already held on the item by other transactions
๏ƒ˜ Any number of transactions can hold shared locks on an item,
o But if any transaction holds an exclusive on the item no other transaction may hold any
lock on the item.
๏ƒ˜ If a lock cannot be granted, the requesting transaction is made to wait till all incompatible locks
held by other transactions have been released. The lock is then granted.
Example of a transaction performing locking:
T2: lock-S(A);
read (A);
unlock(A);
lock-S(B);
read (B);
unlock(B);
display(A+B)
๏ƒ˜ Locking as above is not sufficient to guarantee Serializability โ€” if A and B get updated in-
between the read of A and B, the displayed sum would be wrong.
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d

Partial preview of the text

Download CONCURRENCY CONTROL - Database Management Systems (DBMS) and more Lecture notes Database Management Systems (DBMS) in PDF only on Docsity!

UNIT V

Concurrency Control: Lock-based Protocols, Timestamp-based Protocols, Validation-based Protocols, Multiple Granularity, Multi-version Schemes, Deadlock Handling, Insert and Delete Operations, Weak Levels of Consistency, Concurrency of Index Structures. Recovery System: Failure Classification, Storage Structure, Recovery and Atomicity, Log-Based Recovery, Recovery with Concurrent Transactions, Buffer Management, Failure with Loss of Nonvolatile Storage, Advanced Recovery Techniques, Remote Backup Systems

CONCURRENCY CONTROL

LOCK-BASED PROTOCOLS:

A locking protocol is a set of rules followed by all transactions while requesting and releasing locks. Locking protocols restrict the set of possible schedules. A lock is a mechanism to control concurrent access to a data item. Data items can be locked in two modes:

  1. exclusive (X) mode. Data item can be both read as well as written. X-lock is requested using lock-X instruction.
  2. shared (S) mode. Data item can only be read. S-lock is requested using lock-S instruction. Lock requests are made to concurrency-control manager. Transaction can proceed only after request is granted. Lock-compatibility matrix: ๏ƒ˜ A transaction may be granted a lock on an item if the requested lock is compatible with locks already held on the item by other transactions ๏ƒ˜ Any number of transactions can hold shared locks on an item, o But if any transaction holds an exclusive on the item no other transaction may hold any lock on the item. ๏ƒ˜ If a lock cannot be granted, the requesting transaction is made to wait till all incompatible locks held by other transactions have been released. The lock is then granted. Example of a transaction performing locking: T2 : lock-S (A) ; read (A) ; unlock (A) ; lock-S (B) ; read (B) ; unlock (B) ; display (A+B) ๏ƒ˜ Locking as above is not sufficient to guarantee Serializability โ€” if A and B get updated in- between the read of A and B , the displayed sum would be wrong.

Pitfalls of Lock-Based Protocols: Consider the partial schedule Neither T3 nor T4 can make progress โ€” executing lock - S (B) causes T4 to wait for T3 to release its lock on B , while executing lock - X (A) causes T3 to wait for T4 to release its lock on A. Such a situation is called a deadlock. To handle a deadlock one of T3 or T4 must be rolled back and its locks released. The potential for deadlock exists in most locking protocols. ๏ƒ˜ Starvation is also possible if concurrency control manager is badly designed. For example: A transaction may be waiting for an X-lock on an item, while a sequence of other transactions request and are granted an S-lock on the same item. The same transaction is repeatedly rolled back due to deadlocks. ๏ƒ˜ Concurrency control manager can be designed to prevent starvation.

The Two-Phase Locking Protocol: This is a protocol which ensures conflict-

serializable schedules. Phase 1: Growing Phase: The transaction may obtain locks and transaction may not release locks. Phase 2: Shrinking Phase: The transaction may release locks and transaction may not obtain locks. ๏ƒ˜ This protocol assures Serializability. It can be proved that the transactions can be serialized in the order of their lock points (i.e. the point where a transaction acquired its final lock). ๏ƒ˜ Two-phase locking does not ensure freedom from deadlocks ๏ƒ˜ Cascading roll-back is possible under two-phase locking. To avoid this, follow a modified protocol called strict two-phase locking. Here a transaction must hold all its exclusive locks till it commits/aborts. ๏ƒ˜ Rigorous two-phase locking is even stricter: here all locks are held till commit/abort. In this protocol transactions can be serialized in the order in which they commit. ๏ƒ˜ There can be conflict serializable schedules that cannot be obtained if two-phase locking is used. ๏ƒ˜ However, in the absence of extra information (Ex: ordering of access to data), two-phase locking is needed for conflict Serializability in the following sense: Given a transaction T i that does not follow two-phase locking, we can find a transaction Tj that uses two-phase locking, and a schedule for Ti and Tj that is not conflict serializable. Lock Conversions ๏ƒ˜ Two-phase locking with lock conversions: ๏ƒผ First Phase: o can acquire a lock-S on item o can acquire a lock-X on item o can convert a lock-S to a lock-X (upgrade)

granted waiting T 144 T1 T 14 T 17 123 T23 T1 T8 T 1912

Timestamp-Based Protocols:

Each transaction is issued a timestamp when it enters the system. If an old transaction Ti has time- stamp TS ( Ti ), a new transaction Tj is assigned time-stamp TS ( Tj ) such that TS ( Ti ) < TS ( Tj ). ๏ƒ˜ The protocol manages concurrent execution such that the time-stamps determine the Serializability order. ๏ƒ˜ In order to assure such behavior, the protocol maintains for each data Q two timestamp values: o W-timestamp ( Q ) is the largest time-stamp of any transaction that executed write ( Q ) successfully. o R-timestamp ( Q ) is the largest time-stamp of any transaction that executed read ( Q ) successfully. ๏ƒ˜ The timestamp ordering protocol ensures that any conflicting read and write operations are executed in timestamp order. ๏ƒ˜ Suppose a transaction Ti issues a read ( Q ) o If TS( Ti ) ๏‚ฃ W - timestamp( Q ), then Ti needs to read a value of Q that was already overwritten. ๏‚ง Hence, the read operation is rejected, and Ti is rolled back. o If TS( Ti )๏‚ณ W - timestamp( Q ), then the read operation is executed, and R-timestamp( Q ) is set to max (R-timestamp( Q ), TS( Ti )). ๏ƒ˜ Suppose that transaction Ti issues write ( Q ). o If TS( Ti ) < R-timestamp( Q ), then the value of Q that Ti is producing was needed previously, and the system assumed that that value would never be produced. ๏‚ง Hence, the write operation is rejected, and Ti is rolled back. o If TS( Ti ) < W-timestamp( Q ), then Ti is attempting to write an obsolete value of Q. ๏‚ง Hence, this write operation is rejected, and Ti is rolled back. o Otherwise, the write operation is executed, and W-timestamp( Q ) is set to TS( Ti ).

Example Use of the Protocol: A partial schedule for several data items for transactions with timestamps 1, 2, 3, 4, 5 T1 T2 T3 T4 T read(Y) read( X ) read(Y) read( X ) abort write( Y ) write(Z) write(Z) abort read( X ) read(Z) write( Y ) write(Z) Correctness of Timestamp-Ordering Protocol: The timestamp-ordering protocol guarantees Serializability since all the arcs in the precedence graph are of the form: ๏ƒผ Thus, there will be no cycles in the precedence graph Timestamp protocol ensures freedom from deadlock as no transaction ever waits. But the schedule may not be cascade-free, and may not even be recoverable. Recoverability and Cascade Freedom ๏ƒ˜ Problem with timestamp-ordering protocol: o Suppose Ti aborts, but Tj has read a data item written by Ti o Then Tj must abort; if Tj had been allowed to commit earlier, the schedule is not recoverable. o Further, any transaction that has read a data item written by Tj must abort o This can lead to cascading rollback --- that is, a chain of rollbacks ๏ƒ˜ Solution 1: o A transaction is structured such that its writes are all performed at the end of its processing o All writes of a transaction form an atomic action; no transaction may execute while a transaction is being written o A transaction that aborts is restarted with a new timestamp ๏ƒ˜ Solution 2: Limited form of locking: wait for data to be committed before reading it ๏ƒ˜ Solution 3: Use commit dependencies to ensure recoverability

transaction

with

smaller

timestamp

transaction

with larger

timestamp

Schedule Produced by Validation: Example of schedule produced using validation T14 T read ( B ) read ( A ) ( validate ) display ( A + B ) read ( B ) B : = B- 50 read ( A ) A : = A+ ( validate ) write ( B ) write ( A )

MULTIPLE GRANULARITY

๏ƒ˜ Allow data items to be of various sizes and define a hierarchy of data granularities, where the small granularities are nested within larger ones ๏ƒ˜ Can be represented graphically as a tree (but don't confuse with tree-locking protocol) ๏ƒ˜ When a transaction locks a node in the tree explicitly , it implicitly locks all nodes descendents in the same mode. ๏ƒ˜ Granularity of locking (level in tree where locking is done): o fine granularity (lower in tree): high concurrency, high locking overhead o coarse granularity (higher in tree): low locking overhead, low concurrency The levels, starting from the coarsest (top) level are

1. database

  1. area
  2. file
  3. record

Intention Lock Modes: In addition to S and X lock modes, there are three additional lock

modes with multiple granularity:

  1. intention-shared (IS): Indicates explicit locking at a lower level of the tree but only with shared locks.
  2. intention - exclusive (IX): Indicates explicit locking at a lower level with exclusive or shared locks
  3. shared and intention - exclusive (SIX): The sub tree rooted by that node is locked explicitly in shared mode and explicit locking is being done at a lower level with exclusive-mode locks. ๏ƒผ Intention locks allow a higher level node to be locked in S or X mode without having to check all descendent nodes.

Compatibility Matrix with Intention Lock Modes: The compatibility matrix for all lock modes is: Multiple Granularity Locking Scheme: Transaction Ti can lock a node Q , using the following rules:

  1. The lock compatibility matrix must be observed.
  2. The root of the tree must be locked first, and may be locked in any mode.
  3. A node Q can be locked by Ti in S or IS mode only if the parent of Q is currently locked by Ti in either IX or IS mode.
  4. A node Q can be locked by Ti in X, SIX, or IX mode only if the parent of Q is currently locked by Ti in either IX or SIX modes.
  5. Ti can lock a node only if it has not previously unlocked any node (that is, Ti is two- phase).
  6. Ti can unlock a node Q only if none of the children of Q are currently locked by Ti. Observe that locks are acquired in root-to-leaf order, whereas they are released in leaf- to-root order.

MULTIVERSION SCHEMES

๏ƒ˜ Multiversion schemes keep old versions of data item to increase concurrency. o Multiversion Timestamp Ordering o Multiversion Two-Phase Locking ๏ƒ˜ Each successful write results in the creation of a new version of the data item written. ๏ƒ˜ Use timestamps to label versions. ๏ƒ˜ When a read ( Q ) operation is issued, select an appropriate version of Q based on the timestamp of the transaction, and return the value of the selected version. ๏ƒ˜ read s never have to wait as an appropriate version is returned immediately. Multiversion Timestamp Ordering: ๏ƒ˜ Each data item Q has a sequence of versions < Q1, Q2,...., Qm >. Each version Qk contains three data fields: o Content -- the value of version Qk. o W-timestamp ( Qk ) -- timestamp of the transaction that created (wrote) version Qk o R-timestamp ( Qk ) -- largest timestamp of a transaction that successfully read version Qk ๏ƒ˜ When a transaction Ti creates a new version Qk of Q , Qk's W-timestamp and R-timestamp are initialized to TS( Ti ). ๏ƒ˜ R-timestamp of Qk is updated whenever a transaction Tj reads Qk , and TS( Tj ) > R- timestamp( Qk ). ๏ƒ˜ Suppose that transaction Ti issues a read ( Q ) or write ( Q ) operation. Let Qk denote the version of Q whose write timestamp is the largest write timestamp less than or equal to TS( T i). o If transaction Ti issues a read ( Q ), then the value returned is the content of version Qk. o If transaction Ti issues a write ( Q ) ๏‚ง if TS( Ti ) < R-timestamp( Qk ), then transaction Ti is rolled back. ๏‚ง if TS( T i) = W-timestamp( Qk ), the contents of Qk are overwritten ๏‚ง else a new version of Q is created.

๏ƒ˜ System is deadlocked if there is a set of transactions such that every transaction in the set is waiting for another transaction in the set to unlock the data item.

Deadlock Prevention: Deadlock prevention protocols ensure that the system will never enter

into a deadlock state. Some prevention strategies: o Require that each transaction locks all its data items before it begins execution (pre declaration). o Impose partial ordering of all data items and require that a transaction can lock data items only in the order specified by the partial order (graph-based protocol). Deadlock Prevention Strategies: Following schemes use transaction timestamps for the sake of deadlock prevention alone.

  1. Wait-die scheme (non-preemptive): Older transaction may wait for younger one to release data item. Younger transactions never wait for older ones; they are rolled back instead. A transaction may die several times before acquiring needed data item
  2. Wound-wait scheme (preemptive) : Older transaction wounds (forces rollback) of younger transaction instead of waiting for it. Younger transactions may wait for older ones. May be fewer rollbacks than wait-die scheme. Both in wait-die and in wound-wait schemes, a rolled back transaction is restarted with its original timestamp. Older transactions thus have precedence over newer ones, and starvation is hence avoided.
  3. Timeout-Based Schemes: A transaction waits for a lock only for a specified amount of time. After that, the wait times out and the transaction is rolled back. Thus deadlocks are not possible. It is simple to implement; but starvation is possible. It is also difficult to determine good value of the timeout interval.

Deadlock Detection: Deadlocks can be described as a wait-for graph , which consists of a pair

G = ( V , E ).

o V is a set of vertices (all the transactions in the system) o E is a set of edges; each element is an ordered pair Ti ๏‚ฎ Tj.

๏ƒ˜ If Ti ๏‚ฎ Tj is in E , then there is a directed edge from Ti to Tj , implying that Ti is waiting for Tj

to release a data item. ๏ƒ˜ When Ti requests a data item currently being held by Tj , then the edge Ti Tj is inserted in the wait-for graph. This edge is removed only when Tj is no longer holding a data item needed by Ti. ๏ƒ˜ The system is in a deadlock state if and only if the wait-for graph has a cycle. Must invoke a deadlock-detection algorithm periodically to look for cycles. Wait-for graph without a cycle Wait-for graph with a cycle

Deadlock Recovery: When a deadlock is detected:

๏ƒ˜ Some transaction will have to rolled back (made a victim) to break deadlock. Select that transaction as victim that will incur minimum cost. ๏ƒ˜ Rollback -- determine how far to roll back transaction o Total rollback: Abort the transaction and then restart it. o More effective to roll back transaction only as far as necessary to break deadlock. ๏ƒ˜ Starvation happens if same transaction is always chosen as victim. Include the number of rollbacks in the cost factor to avoid starvation

Insert and Delete Operations:

๏ƒ˜ If two-phase locking is used : o A delete operation may be performed only if the transaction deleting the tuple has an exclusive lock on the tuple to be deleted. o A transaction that inserts a new tuple into database is given an X-mode lock on the tuple ๏ƒ˜ Insertions and deletions can lead to the phantom phenomenon. o A transaction that scans a relation (Ex: find sum of balances of all accounts in Perryridge) and a transaction that inserts a tuple in the relation (Ex: insert a new account at Perryridge) conflict (conceptually) in spite of not accessing any tuple in common. o If only tuple locks are used, non-serializable schedules can result ๏‚ง Ex: the scan transaction does not see the new account, but reads some other tuple written by the update transaction ๏ƒ˜ The transaction scanning the relation is reading information that indicates what tuples the relation contains, while a transaction inserting a tuple updates the same information. The information should be locked. ๏ƒ˜ One solution: o Associate a data item with the relation, to represent the information about what tuples the relation contains. o Transactions scanning the relation acquire a shared lock in the data item, o Transactions inserting or deleting a tuple acquire an exclusive lock on the data item. ๏ƒ˜ Above protocol provides very low concurrency for insertions/deletions. ๏ƒ˜ Index locking protocols provide higher concurrency while preventing the phantom phenomenon, by requiring locks on certain index buckets. Index Locking Protocol: According to this protocol every relation must have at least one index. A transaction can access tuples only after finding them through one or more indices on the relation ๏ƒ˜ A transaction Ti that performs a lookup must lock all index leaf nodes that it accesses, in S-mode o Even if the leaf node does not contain any tuple satisfying the index lookup ๏ƒ˜ A transaction Ti that inserts, updates or deletes a tuple ti in a relation r o must update all indices to r o must obtain exclusive locks on all index leaf nodes affected by the insert/update/delete ๏ƒ˜ The rules of the two-phase locking protocol must be observed ๏ƒ˜ Guarantees that phantom phenomenon wonโ€™t occur

Concurrency in Index Structures: Indices are unlike other database items in that their

only job is to help in accessing data. ๏ƒผ Index-structures are typically accessed very often, much more than other database items. o Treating index-structures like other database items, Ex: by 2-phase locking of index nodes can lead to low concurrency. ๏ƒผ There are several index concurrency protocols where locks on internal nodes are released early, and not in a two-phase fashion.

RECOVERY SYSTEM

Failure Classification: Failures are basically classified into three. They are:

  1. Transaction Failure : ๏ƒผ Logical errors : Transaction cannot complete due to some internal error condition ๏ƒผ System errors : The database system must terminate an active transaction due to an error condition (Ex: deadlock)
  2. System Crash : A power failure or other hardware or software failure causes the system to crash. ๏ƒผ Fail-stop assumption : non-volatile storage contents are assumed to not be corrupted by system crash ๏ƒผ Database systems have numerous integrity checks to prevent corruption of disk data
  3. Disk Failure : A head crash or similar disk failure destroys all or part of disk storage ๏ƒผ Destruction is assumed to be detectable: disk drives use checksums to detect failures Recovery Algorithms: Recovery algorithms are techniques to ensure database consistency and transaction atomicity and durability despite failures. Recovery algorithms have two parts: ๏ƒ˜ Actions taken during normal transaction processing to ensure enough information exists to recover from failures ๏ƒ˜ Actions taken after a failure to recover the database contents to a state that ensures atomicity, consistency and durability

Storage Structure:

  1. Volatile storage : Does not survive system crashes. Examples: main memory, cache memory
  2. Nonvolatile storage : Survives system crashes. Examples: disk, tape, flash memory
  3. Stable storage : A mythical form of storage that survives all failures. Approximated by maintaining multiple copies on distinct nonvolatile media.

Stable-Storage Implementation

๏ƒ˜ Maintain multiple copies of each block on separate disks o Copies can be at remote sites to protect against disasters such as fire or flooding. ๏ƒ˜ Failure during data transfer can still result in inconsistent copies: Block transfer can result in o Successful completion o Partial Failure : destination block has incorrect information o Total Failure : destination block was never updated ๏ƒ˜ Protecting storage media from failure during data transfer: o Execute output operation as follows (assuming two copies of each block): ๏‚ง Write the information onto the first physical block. ๏‚ง When the first write successfully completes, write the same information onto the second physical block. ๏‚ง The output is completed only after the second write successfully completes. ๏ƒ˜ Copies of a block may differ due to failure during output operation. To recover from failure: o First find inconsistent blocks: ๏‚ง Expensive solution : Compare the two copies of every disk block. ๏‚ง Better solution : Record in-progress disk writes on non-volatile storage. Use this information during recovery to find blocks that may be inconsistent, and only compare copies of these. Used in hardware RAID systems o If either copy of an inconsistent block is detected to have an error (bad checksum), overwrite it by the other copy. If both have no error, but are different, overwrite the second block by the first block.

Data Access: In memory, Physical blocks are those blocks residing on the disk. Buffer blocks

are the blocks residing temporarily in main memory. ๏ƒ˜ Block movements between disk and main memory are initiated through the following two operations: o input ( B ) transfers the physical block B to main memory. o output ( B ) transfers the buffer block B to the disk, and replaces the appropriate physical block there. ๏ƒ˜ Each transaction Ti has its private work-area in which local copies of all data items accessed and updated by it are kept. o Ti 's local copy of a data item X is called xi. ๏ƒ˜ We assume, for simplicity, that each data item fits in, and is stored inside, a single block. ๏ƒ˜ Transaction transfers data items between system buffer blocks and its private work-area using the following operations : o read ( X ) assigns the value of data item X to the local variable xi. o write ( X ) assigns the value of local variable xi to data item { X } in the buffer block. o both these commands may necessitate the issue of an input (BX) instruction before the assignment, if the block BX in which X resides is not already in memory. ๏ƒ˜ Transactions o Perform read ( X ) while accessing X for the first time; o All subsequent accesses are to the local copy. o After last access, transaction executes write ( X ). ๏ƒ˜ output ( BX ) need not immediately follow write ( X ). System can perform the output operation when it deems fit.

A buffer block is eventually written out to the disk either because the buffer manager needs the memory

space for other purposes or because the database system wishes to reflect the change to B on the disk.

We shall say that the database system performs a force-output of buffer B if it issues an output( B ).

Block Storage Operations:

If log on stable storage at time of crash is as in case: (a) No redo actions need to be taken (b) redo( T 0) must be performed since < T 0 commi t> is present (c) redo ( T 0) must be performed followed by redo( T 1) since < T 0 commit > and < Ti commit> are present Immediate Database Modification: The immediate database modification scheme allows database updates of an uncommitted transaction to be made as the writes are issued o since undoing may be needed, update logs must have both old value and new value ๏ƒ˜ Update log record must be written before database item is written o We assume that the log record is output directly to stable storage o Can be extended to postpone log record output, so long as prior to execution of an output ( B ) operation for a data block B, all log records corresponding to items B must be flushed to stable storage ๏ƒ˜ Output of updated blocks can take place at any time before or after transaction commit ๏ƒ˜ Order in which blocks are output can be different from the order in which they are written. Immediate Database Modification Example Log Write Output < T 0 start > < T0, A, 1000, 950> T o , B, 2000, 2050 A = 950 B = 2050 < T 0 commit > < T 1 start > < T 1, C, 700, 600> C = 600 BB , BC < T 1 commit > BA Note: BX denotes block containing X. ๏ƒ˜ Recovery procedure has two operations instead of one: o undo ( T i) restores the value of all data items updated by Ti to their old values, going backwards from the last log record for Ti o redo ( T i) sets the value of all data items updated by Ti to the new values, going forward from the first log record for Ti ๏ƒ˜ Both operations must be idempotent. i.e., even if the operation is executed multiple times the effect is the same as if it is executed once ๏‚ง Needed since operations may get re-executed during recovery ๏ƒ˜ When recovering after failure: o Transaction Ti needs to be undone if the log contains the record <Ti start > , but does not contain the record <Ti commit >. o Transaction Ti needs to be redone if the log contains both the record <Ti start > and the record <Ti commit >. ๏ƒ˜ Undo operations are performed first, then redo operations.

Immediate DB Modification Recovery Example Below we show the log as it appears at three instances of time. Recovery actions in each case above are: (a) Undo ( T 0): B is restored to 2000 and A to 1000. (b) Undo ( T 1) and redo ( T 0): C is restored to 700, and then A and B are set to 950 and 2050 respectively. (c) Redo ( T 0) and redo ( T 1): A and B are set to 950 and 2050 respectively. Then C is set to 600

Checkpoints:

Problems in recovery procedure include:

  1. Searching the entire log is time-consuming
  2. We might unnecessarily redo transactions which have already
  3. Output their updates to the database. Streamline recovery procedure by periodically performing checkpointing
  4. Output all log records currently residing in main memory onto stable storage.
  5. Output all modified buffer blocks to the disk.
  6. Write a log record < checkpoint > onto stable storage. During recovery we need to consider only the most recent transaction Ti that started before the checkpoint and transactions that started after Ti.
  7. Scan backwards from end of log to find the most recent < checkpoint > record
  8. Continue scanning backwards till a record <Ti start > is found.
  9. Need to only consider the part of log following above star t record. Earlier part of log can be ignored during recovery, and can be erased whenever desired. ๏‚ท For all transactions (starting from Ti or later) with no <Ti commit > , execute undo ( Ti). ๏‚ท Scanning forward in the log, for all transactions starting from Ti or later with a <Ti commit > , execute redo ( Ti). Example of Checkpoints T 1 can be ignored (updates already output to disk due to checkpoint) T 2 and T 3 redone. T 4 undone

Buffer Management:

Log Record Buffering: Log records are buffered in main memory, instead of of being output

directly to stable storage. Log records are output to stable storage when a block of log records in the buffer is full, or a log force operation is executed. ๏ƒผ Log force is performed to commit a transaction by forcing all its log records (including the commit record) to stable storage. ๏ƒผ Several log records can thus be output using a single output operation, reducing the I/O cost. ๏ƒผ The rules below must be followed if log records are buffered: o Log records are output to stable storage in the order in which they are created. o Transaction Ti enters the commit state only when the log record < Ti commit > has been output to stable storage. o Before a block of data in main memory is output to the database, all log records pertaining to data in that block must have been output to stable storage. This rule is called the write-ahead logging or WAL rule ๏‚ง Strictly speaking WAL only requires undo information to be output

Database Buffering: Database maintains an in-memory buffer of data blocks. When a new block

is needed, if buffer is full an existing block needs to be removed from buffer. If the block chosen for removal has been updated, it must be output to disk ๏ƒ˜ If a block with uncommitted updates is output to disk, log records with undo information for the updates are output to the log on stable storage first ๏ƒ˜ No updates should be in progress on a block when it is output to disk. Can be ensured as follows. o Before writing a data item, transaction acquires exclusive lock on block containing the data item o Lock can be released once the write is completed. ๏‚ง Such locks held for short duration are called latches. o Before a block is output to disk, the system acquires an exclusive latch on the block ๏‚ง Ensures no update can be in progress on the block

Buffer Management:

๏ƒผ Database buffer can be implemented either in an area of real main-memory reserved for the database, or in virtual memory ๏ƒผ Implementing buffer in reserved main-memory has drawbacks :

  1. Memory is partitioned before-hand between database buffer and applications, limiting flexibility.
  2. Needs may change, and although operating system knows best how memory should be divided up at any time, it cannot change the partitioning of memory. ๏ƒผ Database buffers are generally implemented in virtual memory in spite of some drawbacks: ๏ƒ˜ When operating system needs to evict a page that has been modified, the page is written to swap space on disk. ๏ƒ˜ When database decides to write buffer page to disk, buffer page may be in swap space, and may have to be read from swap space on disk and output to the database on disk, resulting in extra I/O!. This is known as dual paging problem. ๏ƒ˜ Ideally when OS needs to evict a page from the buffer, it should pass control to database, which in turn should ๏‚— Output the page to database instead of to swap space (making sure to output log records first), if it is modified ๏‚— Release the page from the buffer, for the OS to use Dual paging can thus be avoided, but common operating systems do not support such functionality.

Failure with Loss of Nonvolatile Storage: A technique similar to checkpointing is used to

deal with loss of non-volatile storage ๏ƒผ Periodically dump the entire content of the database to stable storage ๏ƒผ No transaction may be active during the dump procedure; a procedure similar to checkpointing must take place ๏ถ Output all log records currently residing in main memory onto stable storage. ๏ถ Output all buffer blocks onto the disk. ๏ถ Copy the contents of the database to stable storage. ๏ถ Output a record < dump > to log on stable storage. Recovering from Failure of Non-Volatile Storage: To recover from disk failure, Restore DB from most recent dump. Consult log and redo all transactions that committed after the dump. ๏ƒ˜ Can be extended to allow transactions to be active during dump; known as fuzzy dump or online dump Advanced Recovery Algorithm

Key Features:

๏‚ข Support for high-concurrency locking techniques, which release locks early. ๏‚ข Recovery based on โ€œrepeating historyโ€, whereby recovery executes exactly the same actions as normal processing. ๏‚— including redo of log records of incomplete transactions, followed by subsequent undo ๏‚ข Supports logical undo. ๏‚ข Easier to understand/show correctness. Logical Undo Logging: Operations like B+^ tree insertions and deletions release locks early. They cannot be undone by restoring old values ( physical undo ), since once a lock is released, other transactions may have updated the B+^ tree. Instead, insertions (resp. deletions) are undone by executing a deletion (resp. insertion) operation (known as logical undo ).