+ All Categories
Home > Documents > Chapter 15

Chapter 15

Date post: 11-Feb-2016
Category:
Upload: kenna
View: 39 times
Download: 0 times
Share this document with a friend
Description:
Chapter 15. Transaction Management. Outline . Transaction basics Concurrency control Recovery management Transaction design issues Workflow management. Transaction Definition. Supports daily operations of an organization Collection of database operations - PowerPoint PPT Presentation
Popular Tags:
45
Chapter 15 Chapter 15 Transaction Management
Transcript
Page 1: Chapter 15

Chapter 15Chapter 15Transaction Management

Page 2: Chapter 15

Outline Outline

Transaction basicsConcurrency controlRecovery managementTransaction design issuesWorkflow management

Page 3: Chapter 15

Transaction DefinitionTransaction DefinitionSupports daily operations of an

organizationCollection of database operationsReliably and efficiently processed as one

unit of workNo lost data

– Interference among multiple users– Failures

Page 4: Chapter 15

Airline Transaction ExampleAirline Transaction ExampleSTART TRANSACTION

Display greetingGet reservation preferences from userSELECT departure and return flight recordsIf reservation is acceptable then

UPDATE seats remaining of departure flight recordUPDATE seats remaining of return flight recordINSERT reservation recordPrint ticket if requested

End IfOn Error: ROLLBACK

COMMIT

Page 5: Chapter 15

Transaction PropertiesTransaction PropertiesAtomic: all or nothingConsistent: database must be consistent

before and after a transactionIsolated: no unwanted interference from

other usersDurable: database changes are permanent

after the transaction completes

Page 6: Chapter 15

Transaction Processing ServicesTransaction Processing ServicesConcurrency controlRecovery managementService characteristics

– Transparent– Consume significant resources– Significant cost component

Page 7: Chapter 15

Concurrency ControlConcurrency ControlProblem definitionConcurrency control problemsConcurrency control tools

Page 8: Chapter 15

Concurrency Control ProblemConcurrency Control ProblemObjective:

– Maximize work performed– Throughput: number of transactions processed

per unit timeConstraint:

– No interference: serial effect– Interference occurs on commonly manipulated

data known as hot spots

Page 9: Chapter 15

Lost Update ProblemLost Update Problem

Transaction A Time Transaction B Read SR (10) T1 T2 Read SR (10) If SR > 0 then SR = SR -1

T3

T4 If SR > 0 then SR = SR -1

Write SR (9) T5 T6 Write SR (9)

Page 10: Chapter 15

Uncommitted Dependency Uncommitted Dependency ProblemProblem

Transaction A Time Transaction B Read SR (10) T1 SR = SR - 1 T2 Write SR (9) T3 T4 Read SR (9) ROLLBACK T5

Page 11: Chapter 15

Inconsistent Retrieval ProblemsInconsistent Retrieval ProblemsInterference causes inconsistency among

multiple retrievals of a subset of dataIncorrect summary Phantom readNon repeatable read

Page 12: Chapter 15

Incorrect Summary ProblemIncorrect Summary ProblemTransaction A Time Transaction B Read SR1 (10) T1 SR1 = SR1 - 1 T2 Write SR1 (9) T3 T4 Read SR1 (9) T5 Sum = Sum + SR1 T6 Read SR2 (5) T7 Sum = Sum + SR2 Read SR2 (5) T8 SR2 = SR2 - 1 T9 Write SR2 (4) T10

Page 13: Chapter 15

Locking FundamentalsLocking FundamentalsFundamental tool of concurrency controlObtain lock before accessing an itemWait if a conflicting lock is held

– Shared lock: conflicts with exclusive locks– Exclusive lock: conflicts with all other kinds

of locksConcurrency control manager maintains

the lock table

Page 14: Chapter 15

Locking GranularityLocking GranularityDatabase

Table

Page

Row

Column

Index

Page 15: Chapter 15

Deadlock (Mutual Waiting)Deadlock (Mutual Waiting)

Transaction A Time Transaction B

XLock SR1 T1

T2 XLock SR2

XLock SR2 (wait) T3

T4 XLock SR1 (wait)

Page 16: Chapter 15

Deadlock ResolutionDeadlock ResolutionDetection

– Can involve significant overhead– Not widely used

Timeout– Waiting limit– Can abort transactions that are not deadlocked– Widely used although timeout interval is

difficult to determine

Page 17: Chapter 15

Two Phase Locking (2PL)Two Phase Locking (2PL)Protocol to prevent lost update problemsAll transactions must followConditions

– Obtain lock before accessing item– Wait if a conflicting lock is held– Cannot obtain new locks after releasing locks

Page 18: Chapter 15

2PL Implementation2PL Implementation

Time

Growing phase

BOT EOT

Shrinkingphase

Lock

s he

ld

Page 19: Chapter 15

Optimistic ApproachesOptimistic ApproachesAssumes conflicts are rareNo locksCheck for conflicts

– After each read and write– At end of transaction

Evaluation– Less overhead– More variability

Page 20: Chapter 15

Recovery ManagementRecovery ManagementDevice characteristics and failure typesRecovery toolsRecovery processes

Page 21: Chapter 15

Storage Device BasicsStorage Device BasicsVolatile: loses state after a shutdownNonvolatile: retains state after a shutdownNonvolatile is more reliable than volatile

but failures can cause loss of dataUse multiple levels and redundant levels

of nonvolatile storage for valuable data

Page 22: Chapter 15

Failure TypesFailure TypesLocal

– Detected and abnormal termination– Limited to a single transaction

Operating System– Affects all active transactions– Less common than local failures

Device– Affects all active and past transactions– Least common

Page 23: Chapter 15

Transaction LogTransaction LogHistory of database changesLarge storage overheadOperations

– Undo: revert to previous state– Redo: reestablish a new state

Fundamental tool of recovery management

Page 24: Chapter 15

Transaction Log ExampleTransaction Log Example

LSN TransNo Action Time Table Row Column Old New

1 101001 START 10:29 2 101001 UPDATE 10:30 Acct 10001 AcctBal 100 200 3 101001 UPDATE 10:30 Acct 15147 AcctBal 500 400 4 101001 INSERT 10:32 Hist 25045 * <1002,

500, …>

5 101001 COMMIT 10:33

Page 25: Chapter 15

CheckpointsCheckpointsReduces restart work but adds overhead

– Checkpoint log record– Write log buffers and database buffers

Checkpoint interval: time between checkpoints

Types of checkpoints– Cache consistent– Fuzzy

Page 26: Chapter 15

Other Recovery ToolsOther Recovery ToolsForce writing

– Checkpoint time– End of transaction

Database backup– Complete– Incremental

Page 27: Chapter 15

Recovery from a Media FailureRecovery from a Media FailureRestore database from the most recent

backupRedo all committed transactions since the

most recent backupRestart active transactions

Page 28: Chapter 15

Recovery TimelineRecovery Timeline

Time

T1

T5

T4

T3

T2

Checkpoint Failure

Page 29: Chapter 15

Recovery ProcessesRecovery ProcessesDepend on timing of database writesImmediate update approach:

– Before commit– Log records written first (write-ahead log

protocol)Deferred update approach

– After commit– Undo operations not needed

Page 30: Chapter 15

Immediate Update RecoveryImmediate Update RecoveryClass Description Restart Work T1 Finished before CP None T2 Started before CP;

finished before failure Redo forward from checkpoint

T3 Started after CP; finished before failure

Redo forward from checkpoint

T4 Started before CP; not yet finished

Undo backwards from most recent log record

T5 Started after CP; not yet finished

Undo backwards from most recent log record

Page 31: Chapter 15

Deferred Update RecoveryDeferred Update RecoveryClass Description Restart Work T1 Finished before CP None T2 Started before CP;

finished before failure Redo forward from first log record

T3 Started after CP; finished before failure

Redo forward from first log record

T4 Started before CP; not yet finished

None

T5 Started after CP; not yet finished

None

Page 32: Chapter 15

Transaction Design IssuesTransaction Design IssuesTransaction boundaryIsolation levelsDeferred constraint checkingSavepoints

Page 33: Chapter 15

Transaction Boundary Transaction Boundary DecisionsDecisionsDivision of work into transactionsObjective: minimize transaction durationConstraint: enforcement of important

integrity constraintsTransaction boundary decision can affect

hot spots

Page 34: Chapter 15

Registration Form ExampleRegistration Form Example

Page 35: Chapter 15

Transaction Boundary ChoicesTransaction Boundary ChoicesOne transaction for the entire formOne transaction for the main form and one

transaction for all subform recordsOne transaction for the main form and

separate transactions for each subform record

Page 36: Chapter 15

Isolation LevelsIsolation LevelsDegree to which a transaction is separated

from the actions of other transactionsBalance concurrency control overhead

with interference problemsSome transactions can tolerate

uncommitted dependency and inconsistent retrieval problems

Specify using the SET TRANSACTION statement

Page 37: Chapter 15

SQL Isolation LevelsSQL Isolation LevelsLevel XLocks SLocks PLocks Interference

Read uncommitted

None None None Uncommitted dependency

Read committed

Long Short None All except uncommitted dependency

Repeatable read

Long Long Short (S), Long (X)

Phantom reads

Serializable Long Long Long None

Page 38: Chapter 15

Scholar’s Lost UpdateScholar’s Lost UpdateTransaction A Time Transaction BObtain S lock on SR T1

Read SR (10) T2

Release S lock on SR T3

If SR > 0 then SR = SR -1 T4

T5 Obtain S lock on SR

T6 Read SR (10)

T7 Release S lock on SR

T8 If SR > 0 then SR = SR -1 Obtain X lock on SR T9

Write SR (9) T10

Commit T11

T12 Obtain X lock on SR

T13 Write SR (9)

Page 39: Chapter 15

Integrity Constraint TimingIntegrity Constraint TimingMost constraints checked immediatelyCan defer constraint checking to EOTSQL SET CONSTRAINTS statement

Page 40: Chapter 15

Save PointsSave PointsSome transactions have tentative actionsSAVEPOINT statement determines

intermediate pointsROLLBACK to specified save points

Page 41: Chapter 15

Workflow ManagementWorkflow ManagementWorkflow descriptionEnabling technologiesAdvanced transaction management

Page 42: Chapter 15

WorkflowsWorkflowsSet of tasks to accomplish a business

processHuman-oriented vs. computer-oriented

– Amount of judgment– Amount of automation

Task structure vs. task complexity– Relationships among tasks– Difficulty of performing individual tasks

Page 43: Chapter 15

Enabling TechnologiesEnabling TechnologiesDistributed object management

– Many kinds of non traditional data– Data often dispersed in location

Workflow modeling– Specification– Simulation– Optimization

Page 44: Chapter 15

Advanced Transaction Advanced Transaction ManagementManagementConversational transactionsTransactions with complex structureTransactions involving legacy systemsCompensating transactionsMore flexible transaction processing

Page 45: Chapter 15

SummarySummaryTransaction: user-defined collection of workDBMSs support ACID propertiesKnowledge of concurrency control and

recovery important for managing databasesTransaction design issues are importantTransaction processing is an important part

of workflow management


Recommended