Database Transactions

ACID properties:
  • Atomicity: An atomic transaction is either fully completed, or is not begun at all. Any updates that a transaction might affect on a system are completed in their entirety.
  • Consistency: Ensuring that at the end of any transaction the system is in a valid state. If the transaction completes successfully, then all changes to the system will have been properly made, and the system will be in a valid state. If any error occurs in a transaction, then any changes already made will be automatically rolled back.
  • Isolation: Transaction are execute as if it was the only one on the system, transaction doesn't interfere each other
  • Durability: A transaction is durable in that once it has been successfully completed, all of the changes it made to the system are permanent.
Atomic Disk Writes

Either entire block is written correctly on disk or the contents of the block is unchanged. To achieve atomic disk writes we require duplex write.

  • a block of data is written two disk blocks sequentially
  • we can determine whether the contents of a disk block has an error or not by means of its CRC.
  • each block is associated with a version number.
  • the block which contains the latest version number is the one which contains most recent data.
  • if one of the writes fail system can issue another write to the disk block that failed.
  • it always guarantees at least one block has consistent data.

BASE properties:

  • Basic Availability: Indicates that the system does guarantee availability, in terms of the CAP theorem.
  • Soft state: Stores don’t have to be write-consistent, nor do different replicas have to be mutually consistent all the time.
  • Eventual consistency: Stores exhibit consistency at some later point

Transaction Processing in application development:

  • Resource managers:
    Responsible for providing ACID operations on objects they implement
    1.Database systems
    2.Persistent programming languages
    3.Reliable communication managers

  • Durable state:
    The application designer represents the application state as durable data stored by the resource manager.

  • Transaction programming Language

Transaction Processing System Features

  • Application development features

  • Repository features

  • TP monitor:
    1.Responsible for authentication
    2.Provides execution environment for processing the requests

  • Data communication features provide reliable
    1.Recording every message sent
    2.Resent failed messages if no acknowledgement
    3.Igoring duplicated messages

  • Database features
    1.Provide stable repository
    2.Location independency
    3.Provides standard interfaces to data definition and manipulation (SQL)
    4.Data control

  • Database Display

  • Database Operational Utilities for administering the database

Types of Actions:
  • Unprotected actions: no ACID
  • Protected actions: these actions are not externalised before they are completely done. These actions are controlled and can be rolled back if required. They have ACID
  • Real actions: these are real physical actions once performed cannot be undone

Transaction models:

  • Flat transaction

    1. Simplest Type
    2. Basic building block for organizing an application into atomic actions
    3. Encloses a program with brackets:
      BEGIN_TRANSACTION
      END_TRANSACTION
    4. All that is between the brackets is performed or nothing at all
      Strictly satisfies ACID
    5. Limitation
      All-or-nothing is not always appropriate
      It is beneficial to commit partial results (violate atomicity)
      Trip Planning: commit part of a transaction
      Bulk Updates: can be expensive to undo all updates
  • Nested transaction

    1. They organize Transactions(T) actions into a hierarchy
    2. A nested T is a tree of T’s; sub-trees are flat or nested
    3. Leaf T’s are flat
    4. Root T = top-level T; all other are subTs
    5. SubT can commit or roll back. Its commit will not take effect unless the root commits
      Trip Planning: commit part of a transaction
    6. When a subT rolls back, all its children are rolled back
      Satisfy ACI, not the D (except for top level)

TP monitor:

  • Batch process
    Large units of work
  • Time-sharing
  • Real-Time processing
    Event-driven operation
  • Client-server processing
  • Transaction-Oriented Processing

你可能感兴趣的:(Database Transactions)