TRANSACTION PROCESSING TECHNIQUES

Post on 21-Mar-2016

72 views 3 download

Tags:

description

TRANSACTION PROCESSING TECHNIQUES. BY SON NGUYEN VIJAY RAO. Presentation Overview. Transactions ○ Definition ○ ACIDS Properties ○ Isolation levels ○ Concurrency & failures issues ○ Forms of transaction processing ○ Example: Airline Reservation System - PowerPoint PPT Presentation

Transcript of TRANSACTION PROCESSING TECHNIQUES

TRANSACTION TRANSACTION PROCESSING PROCESSING TECHNIQUESTECHNIQUES

BYBYSON NGUYENSON NGUYEN

VIJAY RAOVIJAY RAO

2

Presentation OverviewPresentation Overview TransactionsTransactions

○ ○ DefinitionDefinition○ ○ ACIDS PropertiesACIDS Properties○ ○ Isolation levelsIsolation levels○ ○ Concurrency & failures issuesConcurrency & failures issues○ ○ Forms of transaction processingForms of transaction processing○ ○ Example: Airline Reservation SystemExample: Airline Reservation System○ ○ Two types of transaction: Simple and ConcurrentTwo types of transaction: Simple and Concurrent○ ○ Concurrency controls: Optimistic, Pessimistic and 2 Phase LockingConcurrency controls: Optimistic, Pessimistic and 2 Phase Locking

Failures RecoveryFailures Recovery○ ○ Types of failuresTypes of failures○ ○ Single site recovery: Abort recoverySingle site recovery: Abort recovery

Distributed TransactionsDistributed Transactions○ ○ Two phase commitTwo phase commit

SummarySummary

3

What are Transactions?What are Transactions?► Can be defined as an indivisible unit of work Can be defined as an indivisible unit of work

comprised of several operations, all or none comprised of several operations, all or none of which must be performedof which must be performed

►Has ACID propertiesHas ACID properties◊ ◊ AtomicityAtomicity◊ ◊ ConsistencyConsistency◊ ◊ IsolationIsolation◊ ◊ DurabilityDurability

4

ACID Properties (cont)ACID Properties (cont)►AtomicityAtomicity

Operations are treated as a single unit Operations are treated as a single unit (indivisible) (indivisible) one which will either complete one which will either complete fully or not at allfully or not at all

►ConsistencyConsistencyMust maintain consistency of data before and Must maintain consistency of data before and after after a a transactiontransaction

► IsolationIsolationTransactions should not affect other transactionsTransactions should not affect other transactions

►DurabilityDurabilityRequires result of a committed transaction be made Requires result of a committed transaction be made permanentpermanent

5

Isolation levels of TransactionIsolation levels of Transaction► ReadUncommitted/Dirty ReadReadUncommitted/Dirty Read

Updated data not yet committed by a transaction may Updated data not yet committed by a transaction may be read by other transactionsbe read by other transactions

► ReadCommittedReadCommittedOnly committed data can be read by other Only committed data can be read by other transactionstransactions

► RepeatableReadRepeatableReadDirty reads and nonrepeatable reads cannot occurDirty reads and nonrepeatable reads cannot occur

► SerializableSerializableMost restrictive isolation level. Exclusive access to Most restrictive isolation level. Exclusive access to

read/write dataread/write data

6

Why are Transactions Why are Transactions needed?needed?

To resolve:To resolve:►Concurrency issuesConcurrency issues

◊ ◊ Race conditionRace condition◊ ◊ Inconsistent updatesInconsistent updates

►Failures issuesFailures issues◊ ◊ System failuresSystem failures◊ ◊ Communication failuresCommunication failures

7

Forms of transaction processingForms of transaction processing►Sequential specificationSequential specification

◊ ◊ Transactions are executed in orderTransactions are executed in order◊ ◊ Do not allow concurrencyDo not allow concurrency◊ ◊ Allow failuresAllow failures

►Concurrent specificationConcurrent specification◊ ◊ Allow transactions to happen concurrentlyAllow transactions to happen concurrently◊ ◊ Record the history and the result values of Record the history and the result values of operations executed by each transaction operations executed by each transaction ◊ ◊ Use transaction identifiers to distinguish Use transaction identifiers to distinguish concurrent transaction’s operationsconcurrent transaction’s operations◊ ◊ Allow failuresAllow failures

8

Applications that use Applications that use transactionstransactions

►Banking systemsBanking systems►Airline reservation systemAirline reservation system►Online shoppingOnline shopping

9

Airline Reservation example Airline Reservation example (cont)(cont)

►What happens if the reservation What happens if the reservation system tries to book the same seat system tries to book the same seat concurrently?concurrently?◊ ◊ Two passengers might end up with the same seat Two passengers might end up with the same seat (concurrency issue)(concurrency issue)

► Invalid booking also happens if:Invalid booking also happens if:◊ ◊ Reservation system reads data from one of its Reservation system reads data from one of its replicated database that has not been updated due replicated database that has not been updated due to a network failureto a network failure

10

Simple TransactionSimple Transaction►Turn AutoCommit offTurn AutoCommit off►Execute a bunch of inserts and Execute a bunch of inserts and

updatesupdates►CommitCommit►If error then rollbackIf error then rollback

What happens if multiple threads are What happens if multiple threads are running?running?

11

Concurrent TransactionsConcurrent Transactions►Need a robust transaction processing Need a robust transaction processing

application server with services to manage application server with services to manage all the issues with concurrent processingall the issues with concurrent processing

► JTA (Java transaction API) provides the API JTA (Java transaction API) provides the API for managing transactionsfor managing transactions

► Application servers such as BEA Weblogic Application servers such as BEA Weblogic and IBM Websphere provide a robust and IBM Websphere provide a robust implementation for transaction implementation for transaction managementmanagement

12

Concurrency ControlConcurrency Control►Optimistic concurrencyOptimistic concurrency

◊ ◊ Operations are simply carried outOperations are simply carried out◊ ◊ Synchronization takes place at the end of a transactionSynchronization takes place at the end of a transaction

► Pessimistic concurrencyPessimistic concurrency◊ ◊ Use Murphy’s law “If something can go wrong, it will”Use Murphy’s law “If something can go wrong, it will”◊ ◊ Operations are synchronized before they are carried outOperations are synchronized before they are carried out

► 2 Phase Locking2 Phase Locking ◊ ◊ An algorithm to keep transactions in syncAn algorithm to keep transactions in sync◊ ◊ Acquire/Release locks conceptAcquire/Release locks concept◊ ◊ Growing phase and Shrinking phaseGrowing phase and Shrinking phase◊ ◊ Locks must be strong to ensure only one transaction can Locks must be strong to ensure only one transaction can write at a time. Read is not allowed while writing.write at a time. Read is not allowed while writing.

13

Concurrency Control – 2 Phase Concurrency Control – 2 Phase LockingLocking

14

Concurrency Control – 2 Phase Concurrency Control – 2 Phase Locking (cont)Locking (cont)

►Problems with 2 Phase lockingProblems with 2 Phase locking◊ ◊ DeadlocksDeadlocks

►Solutions?Solutions?

15

Single Site RecoverySingle Site Recovery►Possible types of failures:Possible types of failures:

◊ ◊ Transaction abort Transaction abort ◊ ◊ System crashSystem crash◊ ◊ Media failuresMedia failures◊ ◊ CatastropheCatastrophe

►Possible ways of recoveryPossible ways of recovery◊ ◊ Abort recovery Abort recovery ◊ ◊ Crash recovery Crash recovery

16

Single Site Recovery - Abort Single Site Recovery - Abort RecoveryRecovery

Two methods to recover from transactionTwo methods to recover from transactionabort:abort:►Update-in-placeUpdate-in-place

◊ ◊ Update the database as a transaction runs and Update the database as a transaction runs and undoing updates if aborts.undoing updates if aborts.◊ ◊ Actions implementation:Actions implementation:□ □ Update: record old value in an undo log and updateUpdate: record old value in an undo log and update□ □ Read: simply just read the desired dataRead: simply just read the desired data□ □ Commit: discard transaction’s undo logCommit: discard transaction’s undo log□ □ Abort: use undo log to back out updatesAbort: use undo log to back out updates

17

Single Site Recovery - Abort Single Site Recovery - Abort Recovery (cont)Recovery (cont)

►Deferred updateDeferred update◊ ◊ Saving a transaction’s updates while it runs and Saving a transaction’s updates while it runs and using the saved updates to update the database using the saved updates to update the database when the transaction commits.when the transaction commits.◊ ◊ Actions implementation:Actions implementation:□ □ Update: record updated value in an redo log Update: record updated value in an redo log □ □ Read: combine the redo log and the database Read: combine the redo log and the database □ □ Commit: update the database by applying redo log Commit: update the database by applying redo log □ □ Abort: discard the transaction’s redo logAbort: discard the transaction’s redo log

►Which method is better?Which method is better?

18

Single Site Recovery – Crash Single Site Recovery – Crash RecoveryRecovery

►Use log to record updates, commits, Use log to record updates, commits, and abort statusand abort status

►Use log information to tell which Use log information to tell which updates belong on disk and which do updates belong on disk and which do notnot

►Abort transaction that doesn’t have a Abort transaction that doesn’t have a commit record in the log.commit record in the log.

19

Distributed TransactionsDistributed Transactions►Distributed Transactions include one or more Distributed Transactions include one or more

statements that individually or as a group statements that individually or as a group update data at two distinct nodes in a update data at two distinct nodes in a distributed environment.distributed environment.

► Example of distributed transactions in OracleExample of distributed transactions in OracleUPDATE scott.dept@hq.us.acme.com SET loc = UPDATE scott.dept@hq.us.acme.com SET loc =

'REDWOOD SHORES' WHERE deptno = 10; 'REDWOOD SHORES' WHERE deptno = 10; UPDATE scott.emp SET deptno = 11 WHERE deptno = 10;UPDATE scott.emp SET deptno = 11 WHERE deptno = 10;UPDATE scott.bldg@maint.us.acme.com SET room = 1225 UPDATE scott.bldg@maint.us.acme.com SET room = 1225

WHERE room = 1163; WHERE room = 1163; COMMIT; COMMIT;

20

Distributed Transactions Distributed Transactions (Contd.)(Contd.)

21

Distributed Transactions – 2 Distributed Transactions – 2 Phase CommitPhase Commit

►A distributed transaction involves altering A distributed transaction involves altering data across multiple databases.data across multiple databases.

►Databases can be geographically located Databases can be geographically located like database 1 in SFO and 2 in NYClike database 1 in SFO and 2 in NYC

►This protocol ensures integrity of data This protocol ensures integrity of data ►This consists of 2 phases managed by a This consists of 2 phases managed by a

global co-ordinatorglobal co-ordinator Prepare PhasePrepare Phase Commit PhaseCommit Phase

22

2 Phase Commit (Contd.)2 Phase Commit (Contd.)► The global coordinator sends a message to The global coordinator sends a message to

check for preparedness to commit by all check for preparedness to commit by all participantsparticipants

►Once all participants have acknowledged it Once all participants have acknowledged it issues a Commit or rollback.issues a Commit or rollback.

23

2 Phase Commit - Failure2 Phase Commit - Failure► Failure during Prepare PhaseFailure during Prepare Phase

► Failure during Commit PhaseFailure during Commit Phase

24

Real Life ExamplesReal Life Examples► Transactions in J2EETransactions in J2EE

Java Transaction API (JTA)Java Transaction API (JTA)► Enterprise Java BeansEnterprise Java Beans

Robust and scalable component in J2EE Robust and scalable component in J2EE architecture that can participate in architecture that can participate in transactions.transactions.

► Transaction Attributes for EJBTransaction Attributes for EJBDeclarative Transaction ManagementDeclarative Transaction ManagementRequired, RequiresNew, Mandatory, Supports, Required, RequiresNew, Mandatory, Supports, NotSupported and NeverNotSupported and Never

25

Nested TransactionsNested Transactions►Transactions within transactionsTransactions within transactions►Sub-transactions can commit but outer Sub-transactions can commit but outer

transaction could rollback…?transaction could rollback…?►Complex Issues!Complex Issues!►Not supported by J2EE and hence Not supported by J2EE and hence

JDBC!JDBC!►Only flat transactions are supportedOnly flat transactions are supported

26

SummarySummary►Transactions are importantTransactions are important►Transactions in a distributed Transactions in a distributed

environment are much more complex environment are much more complex compare to a single site transactionscompare to a single site transactions

►Must handle transactions appropriatelyMust handle transactions appropriately►Failed to recovery a transaction might Failed to recovery a transaction might

cause a lot of troublescause a lot of troubles

27

BibliographyBibliography► http://www.javaworld.com/javaworld/jw-07-2000/jw-http://www.javaworld.com/javaworld/jw-07-2000/jw-

0714-transaction.html0714-transaction.html► http://www.mssqlcity.com/Articles/General/TIL.htmlhttp://www.mssqlcity.com/Articles/General/TIL.html► http://www.cse.scu.edu/~jholliday/transproc.htmlhttp://www.cse.scu.edu/~jholliday/transproc.html► http://www.ietf.org/rfc/rfc2371.txthttp://www.ietf.org/rfc/rfc2371.txt► http://www.cs.umb.edu/cs634/ora9idocs/server.920/http://www.cs.umb.edu/cs634/ora9idocs/server.920/

a96521/ds_txns.htma96521/ds_txns.htm► http://www.cogs.susx.ac.uk/users/ianw/teach/dist-http://www.cogs.susx.ac.uk/users/ianw/teach/dist-

sys/ds-node246.htmlsys/ds-node246.html► Distributed Systems: Principles and Paradigms by Distributed Systems: Principles and Paradigms by

Tanenbaum and Van SteenTanenbaum and Van Steen

28

Q&AQ&A►Q&AQ&A