Transaction Management Overview - PowerPoint PPT Presentation

Loading...

PPT – Transaction Management Overview PowerPoint presentation | free to download - id: 71d278-YTQ1Z



Loading


The Adobe Flash plugin is needed to view this content

Get the plugin now

View by Category
About This Presentation
Title:

Transaction Management Overview

Description:

R & G Chapter 16 Lecture 19 There are three side effects of acid. Enhanced long term memory, decreased short term memory, and I forget the third. – PowerPoint PPT presentation

Number of Views:39
Avg rating:3.0/5.0
Slides: 31
Provided by: RaghuRa98
Category:

less

Write a Comment
User Comments (0)
Transcript and Presenter's Notes

Title: Transaction Management Overview


1
Transaction Management Overview
  • R G Chapter 16
  • Lecture 19

There are three side effects of acid. Enhanced
long term memory, decreased short term memory,
and I forget the third. - Timothy Leary
2
Administrivia
  • Homework 3 Due Next Sunday, 7pm
  • Use ANALYZE to get correct statistics
  • No office hours Thursday, today 130-230 instead

3
Review Last Week
  • Tree Indexes BTrees and ISAM
  • good for range queries, o.k. for equality queries
  • ISAM for static data, B-Trees for dynamic data
  • Hash Indexes
  • best for equality queries, useless for range
    queries
  • Static Hashing
  • Extendable Hashing
  • Linear Hashing

4
Review The Big Picture
  • Data Modelling
  • Relational E-R
  • Database design and Functional Dependencies
  • Storing Data
  • File Organization
  • File Indexes, Trees and Hash Tables
  • Buffer Pool Management
  • Query Languages
  • SQL, Relational Algebra, Relational Calculus
  • Query Optimization
  • External Sorting
  • Join Algorithms
  • Query Plans, Cost Estimation
  • Database Applications
  • Transactions and Concurrency Control
  • Logging and Crash Recovery

5
Concurrency Control and Recovery
  • They help support A.C.I.D. properties

Atomicity
Consistency
Isolation
Durability
  • More formal definitions shortly

6
Concurrency Control Recovery
  • Concurrency Control
  • Provide correct and highly available access to
    data in the presence of concurrent access by
    large and diverse user populations
  • Recovery
  • Ensures database is fault tolerant, and not
    corrupted by software, system or media failure
  • 7x24 access to mission critical data
  • Existence of CCR allows applications to be
    written without explicit concern for concurrency
    and fault tolerance

7
Roadmap
  • Overview (Today)
  • Concurrency Control (2 lectures)
  • Recovery (1-2 lectures)

8
Structure of a DBMS
These layers must consider concurrency control
and recovery (Transaction, Lock, Recovery
Managers)
9
Transactions
  • Transaction is unit of atomicity
  • transaction should either finish, or never start
  • Transaction is a sequence of operations
  • for database, only reads, writes matter

10
Transactions and Concurrent Execution
  • Transaction - DBMSs abstract view of user
    program (or activity)
  • A sequence of reads and writes of database
    objects.
  • Unit of work that must commit and abort as a
    single atomic unit
  • Transaction Manager controls the execution of
    transactions.
  • User program may carry out many operations on the
    data retrieved from the database, but the DBMS is
    only concerned about what data is read/written
    from/to the database.
  • Concurrent execution of multiple transactions
    essential for good performance.
  • Disk is the bottleneck (slow, frequently used)
  • Must keep CPU busy w/many queries
  • Better response time

11
ACID properties of Transaction Executions
  • A tomicity All actions in the Xact happen, or
    none happen.
  • C onsistency If each Xact is consistent, and
    the DB starts consistent, it ends up consistent.
  • I solation Execution of one Xact is isolated
    from that of other Xacts.
  • D urability If a Xact commits, its effects
    persist.

12
Atomicity and Durability
  • A transaction might commit after completing all
    its actions, or it could abort (or be aborted by
    the DBMS) after executing some actions. Also, the
    system may crash while the transaction is in
    progress.
  • Important properties
  • Atomicity Either executing all its actions, or
    none of its actions.
  • Durability The effects of committed
    transactions must survive failures.
  • DBMS ensures the above by logging all actions
  • Undo the actions of aborted/failed transactions.
  • Redo actions of committed transactions not yet
    propagated to disk when system crashes.

13
Transaction Consistency
  • A transaction performed on a database that is
    internally consistent will leave the database in
    an internally consistent state.
  • Consistency of database is expressed as a set of
    declarative Integrity Constraints
  • CREATE TABLE/ASSERTION statements
  • E.g. Each CS186 student can only register in one
    project group. Each group must have 3 students.
  • Application-level
  • E.g. Bank account of each customer must stay the
    same during a transfer from savings to checking
    account
  • Transactions that violate ICs are aborted.

14
Isolation (Concurrency)
  • Concurrency is achieved by DBMS, which
    interleaves actions (reads/writes of DB objects)
    of various transactions.
  • DBMS ensures transactions do not step onto one
    another.
  • Each transaction executes as if it was running by
    itself.
  • Transactions behavior is not impacted by the
    presence of other transactions that are accessing
    the same database concurrently.
  • Net effect must be identical to executing all
    transactions for some serial order.
  • Users understand a transaction without
    considering the effect of other concurrently
    executing transactions.

15
Example
  • Consider two transactions (Xacts)

T1 BEGIN AA100, BB-100 END T2 BEGIN
A1.06A, B1.06B END
  • 1st xact transfers 100 from Bs account to As
  • 2nd credits both accounts with 6 interest.
  • Assume at first A and B each have 1000. What
    are the legal outcomes of running T1 and T2?
  • T1 T2 (A1166,B954)
  • T2 T1 (A1160,B960)
  • In either case, AB 2000 1.06 2120
  • There is no guarantee that T1 will execute before
    T2 or vice-versa, if both are submitted together.

16
Example (Contd.)
  • Consider a possible interleaved schedule

T1 AA100, BB-100 T2
A1.06A, B1.06B
  • This is OK (same as T1T2). But what about

T1 AA100, BB-100 T2
A1.06A, B1.06B
  • Result A1166, B960 AB 2126, bank loses 6
    !
  • The DBMSs view of the second schedule

T1 R(A), W(A), R(B), W(B) T2
R(A), W(A), R(B), W(B)
17
Scheduling Transactions
  • Serial schedule Schedule that does not
    interleave the actions of different transactions.
  • Equivalent schedules For any database state,
    the effect (on the set of objects in the
    database) of executing the first schedule is
    identical to the effect of executing the second
    schedule.
  • Serializable schedule A schedule that is
    equivalent to some serial execution of the
    transactions.
  • (Note If each transaction preserves
    consistency, every serializable schedule
    preserves consistency. )

18
Anomalies with Interleaved Execution
  • Reading Uncommitted Data (WR Conflicts, dirty
    reads)
  • Unrepeatable Reads (RW Conflicts)

T1 R(A), W(A), R(B), W(B),
Abort T2 R(A), W(A), C
T1 R(A), R(A), W(A), C T2 R(A),
W(A), C
19
Anomalies (Continued)
  • Overwriting Uncommitted Data (WW Conflicts)

T1 W(A), W(B), C T2 W(A), W(B), C
20
How to prevent anomolies? Locks!
  • Database allows objects to be locked
  • object might be entire database, file, page,
    tuple
  • Two kinds of locks
  • Shared or Read Lock
  • No one else is allowed to write the object if you
    have this
  • Exclusive or Write Lock
  • No one else is allowed to read or write the object

21
Locks not enough
  • If lock/unlock objects right away, anomolies
    still possible
  • Idea Two Phase Locking
  • In a transaction,
  • only acquire locks in one phase
  • only release locks in a second phase
  • once one lock has been released, can never aquire
    another lock during transaction

locks
Time
22
Lock-Based Concurrency Control
  • Two-phase Locking (2PL) Protocol
  • Each Xact must obtain
  • a S (shared) lock on object before reading, and
  • an X (exclusive) lock on object before writing.
  • If an Xact holds an X lock on an object, no other
    Xact can get a lock (S or X) on that object.
  • System can obtain these locks automatically
  • Two phases acquiring locks, and releasing them
  • No lock is ever acquired after one has been
    released
  • Growing phase followed by shrinking phase.
  • Lock Manager keeps track of request for locks and
    grants locks on database objects when they become
    available.

23
Strict 2PL
  • 2PL allows only serializable schedules but is
    subjected to cascading aborts.
  • Example rollback of T1 requires rollback of T2!
  • To avoid Cascading aborts, use Strict 2PL
  • Strict Two-phase Locking (Strict 2PL) Protocol
  • Same as 2PL, except
  • All locks held by a transaction are released only
    when the transaction completes

T1 R(A), W(A),
Abort T2 R(A), W(A), R(B), W(B)
locks
vs
24
Strict 2PL (cont)
  • One advantage no other transaction even reads
    anything you write until you commit.
  • I.e. you can only read committed data.

locks
25
What about Durability?
  • If a transaction commits, you want its data made
    permanent
  • What if power failure 1ns after commit?
  • What if some data still not written to disk?
  • If transaction is aborted, you want any data
    changes undone
  • What if some data writes already on disk?
  • To solve these problems, we have
  • Logging
  • Crash Recovery Algorithms

26
Introduction to Crash Recovery
  • Recovery Manager
  • When a DBMS is restarted after crashes, the
    recovery manager must bring the database to a
    consistent state
  • Ensures transaction atomicity and durability
  • Undos actions of transactions that do not commit
  • Redos actions of committed transactions during
    system failures and media failures (corrupted
    disk).
  • Recovery Manager maintains log information during
    normal execution of transactions for use during
    crash recovery

27
The Log
  • Log consists of records that are written
    sequentially.
  • Typically chained together by Xact id
  • Log is often duplexed and archived on stable
    storage.
  • Log stores modifications to the database
  • if Ti writes an object, write a log record with
  • If UNDO required need before image
  • IF REDO required need after image.
  • Ti commits/aborts a log record indicating this
    action.
  • Need for UNDO and/or REDO depend on Buffer Mgr.
  • UNDO required if uncommitted data can overwrite
    stable version of committed data (STEAL buffer
    management).
  • REDO required if xact can commit before all its
    updates are on disk (NO FORCE buffer management).

28
Logging Continued
  • Write Ahead Logging (WAL) protocol
  • Log record must go to disk before the changed
    page!
  • implemented via a handshake between log manager
    and the buffer manager.
  • All log records for a transaction (including its
    commit record) must be written to disk before the
    transaction is considered Committed.
  • All log related activities (and in fact, all CC
    related activities such as lock/unlock, dealing
    with deadlocks etc.) are handled transparently by
    the DBMS.

29
ARIES Recovery
  • There are 3 phases in ARIES recovery
  • Analysis Scan the log forward (from the most
    recent checkpoint) to identify all Xacts that
    were active, and all dirty pages in the buffer
    pool at the time of the crash.
  • Redo Redoes all updates to dirty pages in the
    buffer pool, as needed, to ensure that all logged
    updates are in fact carried out and written to
    disk.
  • Undo The writes of all Xacts that were active
    at the crash are undone (by restoring the before
    value of the update, as found in the log),
    working backwards in the log.
  • At the end --- all committed updates and only
    those updates are reflected in the database.
  • Some care must be taken to handle the case of a
    crash occurring during the recovery process!

30
Summary
  • Concurrency control and recovery are among the
    most important functions provided by a DBMS.
  • Concurrency control is automatic.
  • System automatically inserts lock/unlock requests
    and schedules actions of different Xacts in such
    a way as to ensure that the resulting execution
    is equivalent to executing the Xacts one after
    the other in some order.
  • Write-ahead logging (WAL) and the recovery
    protocol are used to undo the actions of aborted
    transactions and to restore the system to a
    consistent state after a crash.
About PowerShow.com