CSCI 453 -- Transaction Processing Concepts 1 TRANSACTION PROCESSING CONCEPTS Dr. Awad Khalil...

40
CSCI 453 -- Transaction P rocessing Concepts 1 TRANSACTION PROCESSING CONCEPTS Dr. Awad Khalil Dr. Awad Khalil Computer Science Department Computer Science Department AUC AUC

Transcript of CSCI 453 -- Transaction Processing Concepts 1 TRANSACTION PROCESSING CONCEPTS Dr. Awad Khalil...

Page 1: CSCI 453 -- Transaction Processing Concepts 1 TRANSACTION PROCESSING CONCEPTS Dr. Awad Khalil Computer Science Department AUC.

CSCI 453 -- Transaction Processing Concepts

1

TRANSACTION PROCESSING CONCEPTS

Dr. Awad KhalilDr. Awad Khalil

Computer Science DepartmentComputer Science Department

AUCAUC

Page 2: CSCI 453 -- Transaction Processing Concepts 1 TRANSACTION PROCESSING CONCEPTS Dr. Awad Khalil Computer Science Department AUC.

CSCI 453 -- Transaction Processing Concepts

2

Content

Types of ProcessingTypes of Processing

The Concept of TransactionThe Concept of Transaction

Concurrency & Recovery ControlsConcurrency & Recovery Controls The System LogThe System Log SchedulesSchedulesSerializability of SchedulesSerializability of Schedules

Page 3: CSCI 453 -- Transaction Processing Concepts 1 TRANSACTION PROCESSING CONCEPTS Dr. Awad Khalil Computer Science Department AUC.

CSCI 453 -- Transaction Processing Concepts

3

Types of Processing: Single-User versus Multiuser Systems

AA DBMS DBMS isis single-usersingle-user if at most one user at time if at most one user at time can use the system.can use the system.

  

AA DBMS DBMS isis multiusermultiuser if many users can use the if many users can use the system concurrently - that is at the same time.system concurrently - that is at the same time.

Page 4: CSCI 453 -- Transaction Processing Concepts 1 TRANSACTION PROCESSING CONCEPTS Dr. Awad Khalil Computer Science Department AUC.

CSCI 453 -- Transaction Processing Concepts

4

Types of Processing: Interleaved versus simultaneous concurrency

Page 5: CSCI 453 -- Transaction Processing Concepts 1 TRANSACTION PROCESSING CONCEPTS Dr. Awad Khalil Computer Science Department AUC.

CSCI 453 -- Transaction Processing Concepts

5

Transaction

In multiuser DBMSs, the stored In multiuser DBMSs, the stored data itemsdata items are the are the primary resources that may be accessed primary resources that may be accessed concurrentlyconcurrently by user programs, which are constantly retrieving by user programs, which are constantly retrieving information from and modifying the database.information from and modifying the database.

  

The execution of a program that accesses or changes The execution of a program that accesses or changes the contents of the database is called the contents of the database is called transactiontransaction..

Page 6: CSCI 453 -- Transaction Processing Concepts 1 TRANSACTION PROCESSING CONCEPTS Dr. Awad Khalil Computer Science Department AUC.

CSCI 453 -- Transaction Processing Concepts

6

Transaction (Cont’d)

The database access operations that a transaction can The database access operations that a transaction can include are:include are:

  

read_itemread_item((XX):): Reads a database item named Reads a database item named XX into into a program variable named alsoa program variable named also X X..

  

write_itemwrite_item((XX):): Writes the value of program Writes the value of program variable variable XX into the database item named into the database item named XX..

Page 7: CSCI 453 -- Transaction Processing Concepts 1 TRANSACTION PROCESSING CONCEPTS Dr. Awad Khalil Computer Science Department AUC.

CSCI 453 -- Transaction Processing Concepts

7

Transaction – read_item(X)

1.1. Find the address of the disk block that contains item Find the address of the disk block that contains item XX..

2.2. Copy that disk block into a buffer in main memory (if Copy that disk block into a buffer in main memory (if that disk block is not already in some main memory that disk block is not already in some main memory buffer).buffer).

3.3. Copy item Copy item XX from the buffer to the program variable from the buffer to the program variable named named XX..

Page 8: CSCI 453 -- Transaction Processing Concepts 1 TRANSACTION PROCESSING CONCEPTS Dr. Awad Khalil Computer Science Department AUC.

CSCI 453 -- Transaction Processing Concepts

8

Transaction – write_item(X)

1.1. Find the address of the disk block that contains item Find the address of the disk block that contains item XX..

2.2. Copy that disk block into a buffer in main memory (if Copy that disk block into a buffer in main memory (if that disk block is not already in some main memory that disk block is not already in some main memory buffer).buffer).

3.3. Copy item Copy item XX from the program variable named from the program variable named XX into into its correct location in the buffer.its correct location in the buffer.

4.4. Store the updated block from the buffer back to disk.Store the updated block from the buffer back to disk.

Page 9: CSCI 453 -- Transaction Processing Concepts 1 TRANSACTION PROCESSING CONCEPTS Dr. Awad Khalil Computer Science Department AUC.

CSCI 453 -- Transaction Processing Concepts

9

Transaction – An Example

TransactionTransaction T1T1 TransactionTransaction T2T2---------------------------------------------- ------------------------------------------------------------------------------------------------ --------------------------------------------------

read_item (X);read_item (X); read_item (X);read_item (X);

X := X - N;X := X - N; X := X + M; X := X + M;

write_item(X);write_item(X); write_item(X); write_item(X);

read_item(Y);read_item(Y);

Y := Y + N;Y := Y + N;

write_item(Y);write_item(Y);

Page 10: CSCI 453 -- Transaction Processing Concepts 1 TRANSACTION PROCESSING CONCEPTS Dr. Awad Khalil Computer Science Department AUC.

CSCI 453 -- Transaction Processing Concepts

10

Concurrency & Recovery Controls

ConcurrencyConcurrency and and RecoveryRecovery controls are mainly controls are mainly concerned with the database access commands in a concerned with the database access commands in a transaction.transaction.

    

Transactions submitted by the various users may Transactions submitted by the various users may execute concurrently and may access and update the execute concurrently and may access and update the same database items. If this concurrent execution is same database items. If this concurrent execution is uncontrolled, it may lead to problems such as uncontrolled, it may lead to problems such as inconsistent databaseinconsistent database..

Page 11: CSCI 453 -- Transaction Processing Concepts 1 TRANSACTION PROCESSING CONCEPTS Dr. Awad Khalil Computer Science Department AUC.

CSCI 453 -- Transaction Processing Concepts

11

Why Concurrency Control ?

Several problems can occur when concurrent transactions execute Several problems can occur when concurrent transactions execute in an uncontrolled manner.in an uncontrolled manner.

  

We assume a simple airline reservation database in which a We assume a simple airline reservation database in which a record is stored for each airline flight. Each record includes the record is stored for each airline flight. Each record includes the number of reserved seats on that flight as a named data item, number of reserved seats on that flight as a named data item, among other information.among other information.

The same program can be used to execute many transactions, each The same program can be used to execute many transactions, each with different flights and number of seats to be booked. with different flights and number of seats to be booked.

  

For concurrency control purpose, a transaction is a For concurrency control purpose, a transaction is a particular particular executionexecution of a of a programprogram on a specific date, flight, and number of on a specific date, flight, and number of seats.seats.

Page 12: CSCI 453 -- Transaction Processing Concepts 1 TRANSACTION PROCESSING CONCEPTS Dr. Awad Khalil Computer Science Department AUC.

CSCI 453 -- Transaction Processing Concepts

12

Transaction – An Example

TransactionTransaction T1T1 TransactionTransaction T2T2---------------------------------------------- ------------------------------------------------------------------------------------------------ --------------------------------------------------

read_item (X);read_item (X); read_item (X);read_item (X);

X := X - N;X := X - N; X := X + M; X := X + M;

write_item(X);write_item(X); write_item(X); write_item(X);

read_item(Y);read_item(Y);

Y := Y + N;Y := Y + N;

write_item(Y);write_item(Y);

Page 13: CSCI 453 -- Transaction Processing Concepts 1 TRANSACTION PROCESSING CONCEPTS Dr. Awad Khalil Computer Science Department AUC.

CSCI 453 -- Transaction Processing Concepts

13

Problems: The Lost Update

This occurs This occurs when two when two transactions that transactions that access the same access the same database items database items have their have their operations operations interleaved in a interleaved in a way that makes way that makes the value of the value of some database some database item incorrect.item incorrect.

Page 14: CSCI 453 -- Transaction Processing Concepts 1 TRANSACTION PROCESSING CONCEPTS Dr. Awad Khalil Computer Science Department AUC.

CSCI 453 -- Transaction Processing Concepts

14

Problems: The Temporary Update “Dirty Read”

This occurs when This occurs when one transaction one transaction updates a updates a database item database item and then the and then the transaction fails transaction fails for some reason. for some reason. The updated item The updated item is accessed by is accessed by another another transaction transaction before it is before it is changed back to changed back to its original value.its original value.

Page 15: CSCI 453 -- Transaction Processing Concepts 1 TRANSACTION PROCESSING CONCEPTS Dr. Awad Khalil Computer Science Department AUC.

CSCI 453 -- Transaction Processing Concepts

15

Problems: The Incorrect Summary This occurs when This occurs when

one transaction is one transaction is calculating an calculating an aggregate summary aggregate summary function on a number function on a number of records while of records while other transactions are other transactions are updating some of updating some of these records. In this these records. In this situation, the situation, the aggregate function aggregate function may calculate some may calculate some values before they values before they are updated and are updated and others after they are others after they are updated.updated.

Page 16: CSCI 453 -- Transaction Processing Concepts 1 TRANSACTION PROCESSING CONCEPTS Dr. Awad Khalil Computer Science Department AUC.

CSCI 453 -- Transaction Processing Concepts

16

Why Recovery Control? Whenever a transaction is submitted to a DBMS for Whenever a transaction is submitted to a DBMS for

execution, the system is responsible for making sure execution, the system is responsible for making sure that either:that either: all the operations in the transaction are completed all the operations in the transaction are completed

successfully and their effect is recorded permanently successfully and their effect is recorded permanently in the database, ORin the database, OR

The transaction has no effect whatsoever on the The transaction has no effect whatsoever on the database or on any other transactions.database or on any other transactions.

The DBMS must not permit some operations of a The DBMS must not permit some operations of a transaction T to be applied to the database while other transaction T to be applied to the database while other operations of T are not.operations of T are not.

This may happen if a transaction This may happen if a transaction failsfails after executing after executing some of its operations but before executing all of them.some of its operations but before executing all of them.

Page 17: CSCI 453 -- Transaction Processing Concepts 1 TRANSACTION PROCESSING CONCEPTS Dr. Awad Khalil Computer Science Department AUC.

CSCI 453 -- Transaction Processing Concepts

17

Types of Failures1.1. A computer failure (system crash):A computer failure (system crash): A hardware or software error A hardware or software error

occurs in the computer system during transaction execution.occurs in the computer system during transaction execution.

2.2. A transaction or system errorA transaction or system error: : Some operation in the transaction Some operation in the transaction may cause it to fail, such as integer overflow or division by zero.may cause it to fail, such as integer overflow or division by zero.

3.3. Local errors or exception conditions:Local errors or exception conditions: During transaction execution, During transaction execution, certain conditions may occur that necessitate cancellation of the certain conditions may occur that necessitate cancellation of the transaction. For example, data for the transaction may not be found, or transaction. For example, data for the transaction may not be found, or insufficient account balance in a banking database. insufficient account balance in a banking database.

4.4. Concurrency control enforcement:Concurrency control enforcement: The concurrency control The concurrency control method may decide to abort the transaction, to be restarted later, because method may decide to abort the transaction, to be restarted later, because it violates serializability or because several transactions are in a state of it violates serializability or because several transactions are in a state of deadlock.deadlock.

5.5. Disk failure: Disk failure: Some disk blocks may lose their data because of a read or Some disk blocks may lose their data because of a read or write malfunction or because of a disk read/write head crash.write malfunction or because of a disk read/write head crash.

6.6. Physical problems and catastrophes: Physical problems and catastrophes: Such as power or air-Such as power or air-conditioning failure, fire, theft, sabotage, overwriting disks by mistake, … conditioning failure, fire, theft, sabotage, overwriting disks by mistake, … etc.etc.

Page 18: CSCI 453 -- Transaction Processing Concepts 1 TRANSACTION PROCESSING CONCEPTS Dr. Awad Khalil Computer Science Department AUC.

CSCI 453 -- Transaction Processing Concepts

18

Transaction Concepts

A transaction is an A transaction is an atomic unit of work that atomic unit of work that is either completed in its is either completed in its entirety or not done at all.entirety or not done at all.

  

For recovery purposes, the For recovery purposes, the system needs to keep track system needs to keep track of when the transaction of when the transaction starts, terminates, and starts, terminates, and commits or aborts:commits or aborts:

BEGIN_TRANSACTION.BEGIN_TRANSACTION. READ or WRITE.READ or WRITE. END_TRANSACTION.END_TRANSACTION. COMMIT_TRANSACTION.COMMIT_TRANSACTION. ROLLBACK (or ABORT).ROLLBACK (or ABORT).

UNDO.UNDO. REDO.REDO.

Page 19: CSCI 453 -- Transaction Processing Concepts 1 TRANSACTION PROCESSING CONCEPTS Dr. Awad Khalil Computer Science Department AUC.

CSCI 453 -- Transaction Processing Concepts

19

Transaction States

Page 20: CSCI 453 -- Transaction Processing Concepts 1 TRANSACTION PROCESSING CONCEPTS Dr. Awad Khalil Computer Science Department AUC.

CSCI 453 -- Transaction Processing Concepts

20

The System Log

To be able to recover from transaction failures, the To be able to recover from transaction failures, the system maintains a system maintains a loglog ( (journaljournal).).

  

The The loglog keeps track of all transactions that affect the keeps track of all transactions that affect the values of database items. The values of database items. The loglog is kept on disk and is kept on disk and includes the following entries:includes the following entries: [[start_transactionstart_transaction,, T T]] [[write_itemwrite_item,,TT,,XX,old_value,new_value],old_value,new_value] [[read_itemread_item,,TT,,XX]] [[commitcommit,,TT]] [[abortabort,,TT]]

Page 21: CSCI 453 -- Transaction Processing Concepts 1 TRANSACTION PROCESSING CONCEPTS Dr. Awad Khalil Computer Science Department AUC.

CSCI 453 -- Transaction Processing Concepts

21

The System Log (Cont’d)

If the system crashes, we can recover a consistent If the system crashes, we can recover a consistent database state by examining the log and using one of the database state by examining the log and using one of the recovery techniques.recovery techniques.

  

The Recovery manager can The Recovery manager can undoundo the effect of each the effect of each WRITEWRITE operation of a transaction operation of a transaction TT by tracing backward by tracing backward through the log and resetting all items changed by the through the log and resetting all items changed by the WRITEWRITE operation of operation of TT to their old_values. to their old_values.

  

The Recovery manager can also The Recovery manager can also redoredo the effect of the the effect of the WRITEWRITE operations of a transaction operations of a transaction TT by tracing forward by tracing forward through the log and setting all items changed by a through the log and setting all items changed by a WRITEWRITE operation of operation of TT to their new_values. to their new_values.

Page 22: CSCI 453 -- Transaction Processing Concepts 1 TRANSACTION PROCESSING CONCEPTS Dr. Awad Khalil Computer Science Department AUC.

CSCI 453 -- Transaction Processing Concepts

22

Commit Point of a Transaction

A transaction A transaction TT reaches its reaches its commit pointcommit point when all its when all its operations that access the database have been executed operations that access the database have been executed successfully and the effect of all the transaction successfully and the effect of all the transaction operations on the database has been recorded in theoperations on the database has been recorded in the loglog..

  

Beyond the commit point, the transaction is said to be Beyond the commit point, the transaction is said to be committedcommitted, and its effect is assumed to be , and its effect is assumed to be permanently recordedpermanently recorded in the database. in the database.

  

The transaction then writes an entry The transaction then writes an entry [[commitcommit,,TT]] into into the the loglog..

Page 23: CSCI 453 -- Transaction Processing Concepts 1 TRANSACTION PROCESSING CONCEPTS Dr. Awad Khalil Computer Science Department AUC.

CSCI 453 -- Transaction Processing Concepts

23

Checkpoints A A [[checkpointcheckpoint]] record is written into record is written into

the the loglog periodically at the point when periodically at the point when the system writes out to the database on the system writes out to the database on disk the effect of all disk the effect of all WRITEWRITE operations operations of committed transactionsof committed transactions

   All transactions that have their All transactions that have their

[[commitcommit,,TT] entries in the ] entries in the loglog before a before a [[checkpointcheckpoint] entry do not need to have ] entry do not need to have their their WRITEWRITE operations operations redoneredone in in case of system crash.case of system crash.

   Taking a checkpoint consists of the Taking a checkpoint consists of the

following actions:following actions:

1.1. Suspend execution of Suspend execution of transactions temporarily.transactions temporarily.

2.2. Force-write all update Force-write all update operations of committed operations of committed transactions from main transactions from main memory buffers to disk.memory buffers to disk.

3.3. Write a [Write a [checkpointcheckpoint] ] record to the record to the loglog, and , and force-write the force-write the loglog to to disk.disk.

4.4. Resume executing Resume executing transactions.transactions.

Page 24: CSCI 453 -- Transaction Processing Concepts 1 TRANSACTION PROCESSING CONCEPTS Dr. Awad Khalil Computer Science Department AUC.

CSCI 453 -- Transaction Processing Concepts

24

Desirable Properties of Transaction

Atomic transactions should possess several properties. These Atomic transactions should possess several properties. These are often called theare often called the ACIDACID properties: properties:

1.1. Atomicity:Atomicity: A transaction is an atomic unit of processing; it is A transaction is an atomic unit of processing; it is either performed in its entirety or not performed at all.either performed in its entirety or not performed at all.

2.2. Consistency preservationConsistency preservation:: A correct execution of the A correct execution of the transaction must take the database from one consistent state to transaction must take the database from one consistent state to another.another.

3.3. Isolation:Isolation: A transaction should not make its updates visible to A transaction should not make its updates visible to other transactions until it is committed.other transactions until it is committed.

4.4. Durability or permanencyDurability or permanency:: Once a transaction changes the Once a transaction changes the database and changes are committed, these changes must never database and changes are committed, these changes must never be lost because of subsequent failure.be lost because of subsequent failure.

Page 25: CSCI 453 -- Transaction Processing Concepts 1 TRANSACTION PROCESSING CONCEPTS Dr. Awad Khalil Computer Science Department AUC.

CSCI 453 -- Transaction Processing Concepts

25

Schedules & Recoverability

A A scheduleschedule (or (or historyhistory) ) SS of of nn transactions transactions T1T1, , T2T2, ...,, ...,TnTn is an is an ordering of the operations of the transactions subject to the ordering of the operations of the transactions subject to the constraint that, for each transaction constraint that, for each transaction TiTi that participates in that participates in S S, the , the operations of operations of TiTi in in S S must appear in the same order in which must appear in the same order in which they occur in they occur in TiTi..

  

Sa: r1(X); r2(X); w1(X); r1(Y); w2(X); c2;w1(Y); c1;  

Sb: r1(X); w1(X); r2(X); w2(X); c2; r1(Y); a1;

Two operations in a schedule are said to conflict if they belong Two operations in a schedule are said to conflict if they belong to different transactions, if they access the same item X, and if to different transactions, if they access the same item X, and if one of the two operations is a write_item(X).one of the two operations is a write_item(X).

Page 26: CSCI 453 -- Transaction Processing Concepts 1 TRANSACTION PROCESSING CONCEPTS Dr. Awad Khalil Computer Science Department AUC.

CSCI 453 -- Transaction Processing Concepts

26

Schedules (Cont’d)

A schedule A schedule SS of n transactions of n transactions T1T1, , T2T2, ...,, ...,Tn,Tn, is said to is said to be abe a complete schedulecomplete schedule if the following conditions if the following conditions hold:hold:

  

The operations in S are exactly those operations in The operations in S are exactly those operations in T1T1, , T2T2, ...,, ...,TnTn, including a commit or abort operation as the last , including a commit or abort operation as the last operation for each transaction in the schedule.operation for each transaction in the schedule.

  

For any pair of operations from the same transaction For any pair of operations from the same transaction TiTi, their , their order of appearance in order of appearance in SS is the same as their order of is the same as their order of appearance in appearance in TiTi..

For any two conflicting operations, one of the two must occur For any two conflicting operations, one of the two must occur before the other in the schedule.before the other in the schedule.

Page 27: CSCI 453 -- Transaction Processing Concepts 1 TRANSACTION PROCESSING CONCEPTS Dr. Awad Khalil Computer Science Department AUC.

CSCI 453 -- Transaction Processing Concepts

27

Characterizing Schedules based on Recoverability

1- recoverable Schedule

A A scheduleschedule SS is said to be is said to be recoverablerecoverable if no transaction if no transaction TT in in SS commits until all transactions commits until all transactions T’T’ that have written an item that that have written an item that TT reads have committed.reads have committed.

  

T is said to read from transaction T’ in a schedule S if some item X T is said to read from transaction T’ in a schedule S if some item X is first written by T’ and later read by T.is first written by T’ and later read by T.

  

Sa: r1(X); r2(X); w1(X); r1(Y); w2(X); c2; w1(Y); c1; is recoverable !

Sc: r1(X); w1(X); r2(X); r1(Y); w2(X); c2; a1; is not recoverable ! 

Sd: r1(X); w1(X); r2(X); r1(Y); w2(X); w1(Y); c1; c2; is recoverable !

Page 28: CSCI 453 -- Transaction Processing Concepts 1 TRANSACTION PROCESSING CONCEPTS Dr. Awad Khalil Computer Science Department AUC.

CSCI 453 -- Transaction Processing Concepts

28

Characterizing Schedules based on Recoverability

2- Avoiding Cascading Rollback Schedule

    In a recoverable schedule, no committed transaction ever needs to In a recoverable schedule, no committed transaction ever needs to be rolled back. However, it is still possible for a phenomenon be rolled back. However, it is still possible for a phenomenon known as known as cascadingcascading rollback rollback to occur, where an uncommitted to occur, where an uncommitted transaction has to be rolled back because it read an item from a transaction has to be rolled back because it read an item from a transaction that failed.transaction that failed.

  Se: r1(X); w1(X); r2(X); r1(Y); w2(X); w1(Y); a1; T2 has to be rolled back !

A schedule is said to avoid cascading rollback if every transaction A schedule is said to avoid cascading rollback if every transaction in the schedule only reads items that were written by committed in the schedule only reads items that were written by committed transactions. In this case, all items read will be committed, so no transactions. In this case, all items read will be committed, so no cascading rollback will occur.cascading rollback will occur.

Page 29: CSCI 453 -- Transaction Processing Concepts 1 TRANSACTION PROCESSING CONCEPTS Dr. Awad Khalil Computer Science Department AUC.

CSCI 453 -- Transaction Processing Concepts

29

Characterizing Schedules based on Recoverability

3- Strict Schedule  

Strict schedule is a third type of schedule in which Strict schedule is a third type of schedule in which transactions can neither read nor write an item X until transactions can neither read nor write an item X until the last transaction that wrote X has committed (or the last transaction that wrote X has committed (or aborted). Strict schedules simplify the process of aborted). Strict schedules simplify the process of recovering write operations to a matter of restoring the recovering write operations to a matter of restoring the before image of a data item X, which is the value that X before image of a data item X, which is the value that X had prior to the aborted write operation.had prior to the aborted write operation.

    Sf: w1(X, 5); w2(X, 8); a1; !

Page 30: CSCI 453 -- Transaction Processing Concepts 1 TRANSACTION PROCESSING CONCEPTS Dr. Awad Khalil Computer Science Department AUC.

CSCI 453 -- Transaction Processing Concepts

30

Serializability of Schedules

An important aspect of concurrency control, called An important aspect of concurrency control, called serializability theoryserializability theory, attempts to determine which schedules , attempts to determine which schedules are are “correct”“correct” and which are not to develop techniques that and which are not to develop techniques that allow only correct schedules.allow only correct schedules.

TransactionTransaction T1T1 TransactionTransaction T2T2---------------------------------------------- ------------------------------------------------------------------------------------------------ --------------------------------------------------

read_item (X);read_item (X); read_item (X);read_item (X);

X := X - N;X := X - N; X := X + M; X := X + M;write_item(X);write_item(X); write_item(X); write_item(X);read_item(Y);read_item(Y);Y := Y + N;Y := Y + N;write_item(Y);write_item(Y);

Page 31: CSCI 453 -- Transaction Processing Concepts 1 TRANSACTION PROCESSING CONCEPTS Dr. Awad Khalil Computer Science Department AUC.

CSCI 453 -- Transaction Processing Concepts

31

Serial Schedules & Nonserial Schedules

Page 32: CSCI 453 -- Transaction Processing Concepts 1 TRANSACTION PROCESSING CONCEPTS Dr. Awad Khalil Computer Science Department AUC.

CSCI 453 -- Transaction Processing Concepts

32

Serial Schedules & Nonserial Schedules

A schedule A schedule SS is is serialserial if, for every transaction T if, for every transaction T participating in the schedule, all the operations of T participating in the schedule, all the operations of T are executed consecutively in the schedule; otherwise, are executed consecutively in the schedule; otherwise, the schedule is called the schedule is called nonserialnonserial..

  

If we consider the transactions to be If we consider the transactions to be independentindependent, , then every then every serial schedule is considered correct !!serial schedule is considered correct !!

  

The problem with serial schedules is that they limit The problem with serial schedules is that they limit concurrency or interleaving of operations. Hence, concurrency or interleaving of operations. Hence, serial schedules are considered, in general, serial schedules are considered, in general, unacceptable.unacceptable.

Page 33: CSCI 453 -- Transaction Processing Concepts 1 TRANSACTION PROCESSING CONCEPTS Dr. Awad Khalil Computer Science Department AUC.

CSCI 453 -- Transaction Processing Concepts

33

Serializable Schedules

A schedule A schedule SS is is serializableserializable if it is equivalent to some if it is equivalent to some serial schedule of the same serial schedule of the same nn transactions. transactions.

   Saying that a nonserial schedule Saying that a nonserial schedule SS is is serializableserializable is is

equivalent to saying that it is equivalent to saying that it is correctcorrect, because it is , because it is equivalent to a serial schedule, which is considered equivalent to a serial schedule, which is considered correct.correct.

  

Page 34: CSCI 453 -- Transaction Processing Concepts 1 TRANSACTION PROCESSING CONCEPTS Dr. Awad Khalil Computer Science Department AUC.

CSCI 453 -- Transaction Processing Concepts

34

Schedules Equivalence

1.1. Result EquivalencyResult Equivalency:: Two schedules are called Two schedules are called result result

equivalentequivalent if they produce the same final if they produce the same final state of the database.state of the database.

  

However, two different schedules may However, two different schedules may accidentally produce the same final state.accidentally produce the same final state.

  

S1S1 S2S2  

read_item(X);read_item(X); read_item(X);read_item(X);

X:=X+10;X:=X+10; X:=X*1.1; X:=X*1.1;

write_item(X);write_item(X); write_item(X);write_item(X);

  

Hence, result equivalence is Hence, result equivalence is notnot used to used to define equivalence of schedules.define equivalence of schedules.

2.2. Conflict Equivalency:Conflict Equivalency: Two schedules are called Two schedules are called conflict conflict

equivalentequivalent if the order of any two if the order of any two conflicting operations is the same conflicting operations is the same in both schedules.in both schedules.

   Schedule Schedule SS is conflict serializable is conflict serializable

if it is (conflict) equivalent to if it is (conflict) equivalent to some serial schedulesome serial schedule S’ S’. In such a . In such a case, we can reorder the case, we can reorder the nonconflicting operations in nonconflicting operations in SS until we form the equivalent serial until we form the equivalent serial schedule schedule S’S’..

Page 35: CSCI 453 -- Transaction Processing Concepts 1 TRANSACTION PROCESSING CONCEPTS Dr. Awad Khalil Computer Science Department AUC.

CSCI 453 -- Transaction Processing Concepts

35

Testing Algorithm for Conflict Equivalence of Schedules

The algorithm looks at only the read_item and write_item The algorithm looks at only the read_item and write_item operations in the schedule to construct a precedence graph (or operations in the schedule to construct a precedence graph (or serialization graph).serialization graph).

  

A precedence graph is a directed graph G = (N,E) that consists A precedence graph is a directed graph G = (N,E) that consists of a set of nodes N = {T1, T2, ..., Tn} and a set of directed of a set of nodes N = {T1, T2, ..., Tn} and a set of directed edges E = {e1, e2, ..., em}.edges E = {e1, e2, ..., em}.

  

There is one node in the graph for each transaction Ti in the There is one node in the graph for each transaction Ti in the schedule. schedule.

  

Each edge ei in the graph is of the form (Tj Each edge ei in the graph is of the form (Tj Tk), 1 Tk), 1 j j n, n, where Tj is called the starting node of ei and Tk is called the where Tj is called the starting node of ei and Tk is called the ending node of ei such that one of the operations in Tj appears ending node of ei such that one of the operations in Tj appears in the schedule before some conflicting operation in Tk.in the schedule before some conflicting operation in Tk.

Page 36: CSCI 453 -- Transaction Processing Concepts 1 TRANSACTION PROCESSING CONCEPTS Dr. Awad Khalil Computer Science Department AUC.

CSCI 453 -- Transaction Processing Concepts

36

Testing Algorithm for Conflict Equivalence of Schedules

1.1. for each transaction Ti participating in schedule S create a for each transaction Ti participating in schedule S create a node labeled Ti in the precedence graph;node labeled Ti in the precedence graph;

  

2.2. for each case in S where Tj executes a for each case in S where Tj executes a read_item(X) read_item(X) after a write_item(X) command after a write_item(X) command executed by Ti create executed by Ti create an edge (Ti an edge (Ti Tj) in the precedence graph;Tj) in the precedence graph;

  

3.3. for each case in S where Tj executes a for each case in S where Tj executes a write_item(X) write_item(X) after Ti executes a read_item(X) create an edge (Ti after Ti executes a read_item(X) create an edge (Ti Tj) in Tj) in the precedence graph;the precedence graph;

  

4.4. for each case in S where Tj executes a for each case in S where Tj executes a write_item(X) write_item(X) command after Ti executes a command after Ti executes a write_item(X) command create write_item(X) command create an edge (Ti an edge (Ti Tj) in the precedence graph;Tj) in the precedence graph;

  

5.5. the schedule S is serializable if and only if the the schedule S is serializable if and only if the precedence graph has no cycles;precedence graph has no cycles;

Page 37: CSCI 453 -- Transaction Processing Concepts 1 TRANSACTION PROCESSING CONCEPTS Dr. Awad Khalil Computer Science Department AUC.

CSCI 453 -- Transaction Processing Concepts

37

Testing Conflict Equivalence of Schedules

Constructing the Constructing the precedence graphs for precedence graphs for schedules A to D to test schedules A to D to test for conflict serializability.for conflict serializability.

(a) Precedence graph for (a) Precedence graph for schedule A.schedule A.

(b) Precedence graph for (b) Precedence graph for schedule B.schedule B.

(c) Precedence graph for (c) Precedence graph for schedule C (not schedule C (not serializable).serializable).

(d) Precedence graph for (d) Precedence graph for schedule D (serializable, schedule D (serializable, equivalent to schedule equivalent to schedule A).A).

Page 38: CSCI 453 -- Transaction Processing Concepts 1 TRANSACTION PROCESSING CONCEPTS Dr. Awad Khalil Computer Science Department AUC.

CSCI 453 -- Transaction Processing Concepts

38

Testing Conflict Equivalence of Schedules

Page 39: CSCI 453 -- Transaction Processing Concepts 1 TRANSACTION PROCESSING CONCEPTS Dr. Awad Khalil Computer Science Department AUC.

CSCI 453 -- Transaction Processing Concepts

39

Testing Conflict Equivalence of Schedules

Page 40: CSCI 453 -- Transaction Processing Concepts 1 TRANSACTION PROCESSING CONCEPTS Dr. Awad Khalil Computer Science Department AUC.

CSCI 453 -- Transaction Processing Concepts

40

Thank you