Transaction Management Part 1 - PowerPoint PPT Presentation

1 / 27
About This Presentation
Title:

Transaction Management Part 1

Description:

Key function of DBMS is to ensure that data in the database is reliable and ... Developer can delimit transactions with KEYWORDS available from most DBMS' ... – PowerPoint PPT presentation

Number of Views:49
Avg rating:3.0/5.0
Slides: 28
Provided by: valu84
Category:

less

Transcript and Presenter's Notes

Title: Transaction Management Part 1


1
Transaction ManagementPart 1
2
Chapter - Objectives
  • Function and importance of transactions.
  • Properties of transactions.
  • Concurrency Control
  • Recovery Control

3
DBMS functions
  • Key function of DBMS is to ensure that data in
    the database is reliable and remains in a
    consistent state while allowing many users to
    access the database simultaneously
  • To ensure this DBMS provide transaction support,
    concurrency control and recovery services

4
DBMS Transaction Subsystem
Transaction Manager coordinates transactions for
application programs Scheduler implements
concurrency control sometimes called lock
manager Recovery Manager recovers database
from a failure. Buffer Manager Manages transfer
of data between disk and main memory
5
Transaction Support
  • Transaction
  • Action, or series of actions, carried out by
    user or application, which accesses or changes
    contents of database.
  • Logical unit of work on the database.
  • Transaction can range from very simple (INSERT)
    to complex (READ, READ, UPDATE, INSERT)
  • Transactions are defined by application designers
  • Transforms database from one consistent state to
    another, although consistency may be violated
    during transaction.

6
Example Transaction
For example (b), how might the database be in an
inconsistent state during the transaction?
7
Transaction Support
  • DBMS has no inherent way of knowing when
    transaction starts/ends
  • Developer can delimit transactions with KEYWORDS
    available from most DBMS
  • BEGIN TRANSACTION (may be implied)
  • COMMIT
  • ROLLBACK

8
Transaction Support
  • Can have one of two outcomes
  • Success - transaction commits and database
    reaches a new consistent state.
  • Failure - transaction aborts, and database must
    be restored to consistent state before it
    started.
  • Such a transaction is rolled back or undone.
  • Committed transaction cannot be aborted.
  • Aborted transaction that is rolled back can be
    restarted later.

9
State Transition Diagram for Transaction
Begin_Transaction notifies DBMS that a
transaction is beginning (resp. of developer to
create transactions) Partially committed
transaction has completed. If transaction has
interfered with another transaction, or has
violated an integrity constraint, it is deemed to
have failed Failed occurs if transaction cant
be committed or aborts during active state
10
Properties of Transactions
  • Four basic (ACID) properties of a transaction
    are
  • Atomicity 'All or nothing' property. A
    transaction is an indivisible unit.
  • Consistency Must transform database from one
    consistent state to another.
  • Isolation Transactions execute independently.
    Partial effects of incomplete transactions should
    not be visible to other transactions.
  • Durability Effects of a committed transaction are
    permanent and must not be lost because of later
    failure.

11
Concurrency Control
  • Process of managing simultaneous operations on
    the database without having them interfere with
    one another.
  • Prevents interference when two or more users are
    accessing database simultaneously and at least
    one is updating data.
  • Although two transactions may be correct in
    themselves, interleaving (concurrent execution)
    of operations may produce an incorrect result.

12
Need for Concurrency Control
  • Three examples of potential problems caused by
    concurrently executing transactions
  • Lost update problem
  • Uncommitted dependency problem
  • Inconsistent analysis problem.

13
Lost Update Problem
14
Lost Update Problem
  • Successfully completed update is overridden by
    another user.
  • T1 withdrawing 10 from an account with balx,
    initially 100.
  • T2 depositing 100 into same account.
  • Serially, final balance would be 190.
  • Loss of T2's update avoided by preventing T1 from
    reading balx until after update.

15
Uncommitted Dependency Problem
16
Uncommitted Dependency Problem
  • Occurs when one transaction can see intermediate
    results of another transaction before it has
    committed.
  • T4 updates balx to 200 but it aborts, so balx
    should be back at original value of 100.
  • T3 has read new value of balx (200) and uses
    value as basis of 10 reduction, giving a new
    balance of 190, instead of 90.
  • Problem avoided by preventing T3 from reading
    balx until after T4 commits or aborts.

17
Inconsistent Analysis Problem
18
Inconsistent Analysis Problem
  • Occurs when transaction reads several values but
    second transaction updates some of them during
    execution of first.
  • T6 is totaling balances of account x (100),
    account y (50), and account z (25).
  • Meantime, T5 has transferred 10 from balx to
    balz, so T6 now has wrong result (10 too high).
  • Problem avoided by preventing T6 from reading
    balx and balz until after T5 completed updates.

19
Serializability
  • Objective of a concurrency control protocol is to
    schedule transactions in such a way as to avoid
    any interference.
  • Could run transactions serially, but this limits
    degree of concurrency or parallelism in system.
  • Serializability identifies those executions of
    transactions guaranteed to ensure consistency.

20
Serializability
  • Schedule
  • Sequence of reads/writes by set of concurrent
    transactions that preserves the order of the
    operations in each individual transaction.
  • Serial Schedule
  • Schedule where operations of each transaction
    are executed consecutively without any
    interleaved operations from other transactions.

21
Nonserial Schedule
  • Schedule where operations from set of concurrent
    transactions are interleaved.
  • Objective of serializability is to find nonserial
    schedules that allow transactions to execute
    concurrently without interfering with one
    another.
  • In other words, want to find nonserial schedules
    that are equivalent to some serial schedule. Such
    a schedule is called serializable.

22
Serializability
  • In serializability, ordering of read/writes is
    important
  • If two transactions only read a data item, they
    do not conflict and order is not important.
  • If two transactions either read or write
    completely separate data items, they do not
    conflict and order is not important.
  • If one transaction writes a data item and another
    reads or writes same data item, order of
    execution is important.

23
Example of Conflict Serializability
Are transactions (a) and (b) serializable?
24
Serializability
  • Conflict serializable schedule orders any
    conflicting operations in same way as some serial
    execution.
  • Use precedence graph to test for serializability.

25
Precedence Graph
  • Create
  • Node (circle) for each transaction
  • Draw a ? from TA to TB, if TB reads the value of
    an item written by TA
  • Draw a ? from TA to TB, if TB writes a value into
    an item after it has been read by TA.
  • Draw a ? from TA to TB, if TB writes a value into
    an item after it has been written by TA.
  • If precedence graph contains a loop, the schedule
    is not conflict serializable (loops are bad).

26
Example
  • Draw a ? from TA to TB, if TB reads the value of
    an item written by TA
  • Draw a ? from TA to TB, if TB writes a value into
    an item after it has been read by TA.
  • Draw a ? from TA to TB, if TB writes a value into
    an item after it has been written by TA.

27
Non-conflict serializable transaction
  • T9 is transferring 100 from one account with
    balance balx to another account with balance
    baly.
  • T10 is increasing balance of these two accounts
    by 10.
  • Precedence graph has a cycle and so is not
    serializable.
  • If at start, balx 100, baly 400, result
    should be
  • balx 220, baly 330, if T9 executes before
    T10, or
  • balx 210, baly 340, if T10 executes before
    T9.
  • However, result gives balx 220 and baly 340.
Write a Comment
User Comments (0)
About PowerShow.com