Presentation is loading. Please wait.

Presentation is loading. Please wait.

Sekolah Tinggi Ilmu Statistik (STIS) 1 Dr. Said Mirza Pahlevi, M.Eng.

Similar presentations


Presentation on theme: "Sekolah Tinggi Ilmu Statistik (STIS) 1 Dr. Said Mirza Pahlevi, M.Eng."— Presentation transcript:

1 Sekolah Tinggi Ilmu Statistik (STIS) 1 Dr. Said Mirza Pahlevi, M.Eng.

2 Lecture 2 2 Dr. Said Mirza Pahlevi, M.Eng.

3 Sekolah Tinggi Ilmu Statistik (STIS) Today’s Lecture Transaction  Function and importance of transactions.  Properties of transactions. Concurrency Control  Meaning of serializability  Conflict serializability 3 Dr. Said Mirza Pahlevi, M.Eng.

4 First Topic Dr. Said Mirza Pahlevi, M.Eng. 4

5 Sekolah Tinggi Ilmu Statistik (STIS) Transaction Support Transaction is:  An action, or series of actions, carried out by user or application, which reads or updates contents of database.  A logical unit of work on the database; it may be an entire program, apart of a program, or a single command (e.g., SQL INSERT) Application program execution is:  One or more transactions with non-database processing taking place in between Transaction transforms database from one consistent state to another, although consistency may be violated during transaction. 5 Dr. Said Mirza Pahlevi, M.Eng.

6 Sekolah Tinggi Ilmu Statistik (STIS) Example Transaction 1 Update the salary of a particular member of staff given the staff number A transaction consisting of two database operations: read and write and a non- database operation (salary = salary x 1.1) Staff (staffNo, fName, lName, position, sex, DOB, salary, branchNo) 6 Dr. Said Mirza Pahlevi, M.Eng.

7 Sekolah Tinggi Ilmu Statistik (STIS) Example Transaction 2 Delete the member of staff with a given staff number x As well as having to delete the tuple in the Staff relation, we also need to PropertyFor Rent tuple managed by the staff to a different member PropertyForRent (propertyNo, street, city, postcode, type, rooms, rent, ownerNo, staffNo, branchNo) 7 Dr. Said Mirza Pahlevi, M.Eng.

8 Sekolah Tinggi Ilmu Statistik (STIS) 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. 8 Dr. Said Mirza Pahlevi, M.Eng.

9 Sekolah Tinggi Ilmu Statistik (STIS) State Transition Diagram for Transaction PARTIALLY COMMITTED: occurs after the final statement has been executed  Abort if has violated serializability or violated an integrity constraint FAILED: occurs if the transaction cannot be committed or the transaction is aborted while in the ACTIVE state READ/WRITE 9 Dr. Said Mirza Pahlevi, M.Eng.

10 Sekolah Tinggi Ilmu Statistik (STIS) Transaction Delimitter DBMS has no way of knowing which updates are grouped together to form a single logical transaction The way to indicate transaction  Keywords BEGIN TRANSACTION, COMMIT, ROLLBACK If there are no delimitters, the entire program is usually regarded as a single transaction 10 Dr. Said Mirza Pahlevi, M.Eng.

11 Sekolah Tinggi Ilmu Statistik (STIS) Properties of Transactions Four basic ACID properties of a transaction are:  Atomicity: all or nothing property.  Consistency: must transform database from one consistent state to another.  DBMS can ensure consistency by enforcing the constraints that have been specified on the database schema, such as integrity and enterprise/general constraints.  Isolation: 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 Dr. Said Mirza Pahlevi, M.Eng.

12 Sekolah Tinggi Ilmu Statistik (STIS) DBMS Transaction Subsystem 12 Dr. Said Mirza Pahlevi, M.Eng. Transaction manager: coordinate transaction on behalve of application program Scheduler: responsible for implementing a particular strategy for concurrency control Transaction manager: coordinate transaction on behalve of application program Scheduler: responsible for implementing a particular strategy for concurrency control Recovery manager: if a failure occur during the transaction, it ensures that database is restored to the previous state Buffer manager: responsible for efficient transfer of data between disk storage & main memory Recovery manager: if a failure occur during the transaction, it ensures that database is restored to the previous state Buffer manager: responsible for efficient transfer of data between disk storage & main memory

13 Second Topic 13 Dr. Said Mirza Pahlevi, M.Eng.

14 Sekolah Tinggi Ilmu Statistik (STIS) Topics 1. Concurrency control and serializability 2. Conflict serializability 3. View serializability  next week 14 Dr. Said Mirza Pahlevi, M.Eng.

15 First Subtopic 15 Dr. Said Mirza Pahlevi, M.Eng.

16 Sekolah Tinggi Ilmu Statistik (STIS) 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 of operations may produce an incorrect result. 16 Dr. Said Mirza Pahlevi, M.Eng.

17 Sekolah Tinggi Ilmu Statistik (STIS) Need for Concurrency Control Three examples of potential problems caused by concurrency:  Lost update problem.  Uncommitted dependency problem.  Inconsistent analysis problem. 17 Dr. Said Mirza Pahlevi, M.Eng.

18 Sekolah Tinggi Ilmu Statistik (STIS) Lost Update Problem Successfully completed update is overridden by another user. 1.T1 withdrawing £10 from an account with bal x, initially £100. 2.T2 depositing £100 into same account. 3.Serially, final balance would be £190. 18 Dr. Said Mirza Pahlevi, M.Eng.

19 Sekolah Tinggi Ilmu Statistik (STIS) Uncommitted Dependency Problem Occurs when one transaction can see intermediate results of another transaction before it has committed.  T4 updates bal x to £200 but it aborts, so bal x should be back at original value of £100.  T3 has read new value of bal x (£200) and uses value as basis of £10 reduction, giving a new balance of £190, instead of £90. 19 Dr. Said Mirza Pahlevi, M.Eng.

20 Sekolah Tinggi Ilmu Statistik (STIS) Inconsistent Analysis Problem Occurs when transaction reads several values but second transaction updates some of them during execution of first.  Sometimes referred to as dirty read or unrepeatable read.  T6 is totaling balances of account x, account y, and account z.  Meantime, T5 has transferred £10 from bal x to bal z, so T6 now has wrong result (£10 too high) 20 Dr. Said Mirza Pahlevi, M.Eng.

21 Sekolah Tinggi Ilmu Statistik (STIS) Transaction Schedule Multiple transactions can be executed concurrently by interleaving their operations Ordering of execution of operations from various transactions T 1, T 2, …, T n is called a schedule S Constraint: for each transaction T i, the order in which operations occur in S must be the same as in T i Only interested in read(r), write(w), commit(c), abort(a) 21 Dr. Said Mirza Pahlevi, M.Eng.

22 Sekolah Tinggi Ilmu Statistik (STIS) 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. 22 Dr. Said Mirza Pahlevi, M.Eng.

23 Sekolah Tinggi Ilmu Statistik (STIS) Serializability Schedule  Sequence of reads/writes by set of concurrent transactions. Serial Schedule  Schedule where operations of each transaction are executed consecutively without any interleaved operations from other transactions. No guarantee that results of all serial executions of a given set of transactions will be identical.  e.g., in banking, it matters whether interest is calculated on an account before a large deposit is made or after 23 Dr. Said Mirza Pahlevi, M.Eng.

24 Sekolah Tinggi Ilmu Statistik (STIS) 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. 24 Dr. Said Mirza Pahlevi, M.Eng.

25 Second Subtopic 25 Dr. Said Mirza Pahlevi, M.Eng.

26 Sekolah Tinggi Ilmu Statistik (STIS) Serializability In serializability, ordering of read and write is important: a.If two transactions only read a data item, they do not conflict and order is not important (Nonconflicting)  e.g., read1(x);read2(x) = read2(x);read1(x) b.If two transactions either read or write completely separate data items, they do not conflict and order is not important (nonconflicting).  e.g., read1(x);write2(y) = write2(y);read1(x) c.If one transaction writes a data item and another reads or writes same data item, order of execution is important. (conflicting)  read1(x);write2(x)  write1(x);read2(x)  write1(x);write2(x) 26 Dr. Said Mirza Pahlevi, M.Eng.

27 Sekolah Tinggi Ilmu Statistik (STIS) Conflicting Operations Two operations conflict if they satisfy all three conditions:  They belong to different transactions and  They access the same item and  At least one is a write operation Example:  S: r 1 (X); r 2 (X); w 1 (X); r 1 (Y); w 2 (X); w 1 (Y); conflicts 27 Dr. Said Mirza Pahlevi, M.Eng.

28 Sekolah Tinggi Ilmu Statistik (STIS) Conflict Equivalent S1, S2 are conflict equivalent schedules if S1 can be transformed into S2 by a series of swaps on non- conflicting operations 28 Dr. Said Mirza Pahlevi, M.Eng.

29 Sekolah Tinggi Ilmu Statistik (STIS) Conflict Serializable A schedule is conflict serializable if it is conflict equivalent to some serial schedule. It is the condition that the schedulers in commercial systems generally use when they need to guarantee serializability 29 Dr. Said Mirza Pahlevi, M.Eng.

30 Sekolah Tinggi Ilmu Statistik (STIS) Example of Conflict Serializability conflicting 30 Dr. Said Mirza Pahlevi, M.Eng. The order of conflicting operations are unchanged The order of conflicting operations are unchanged

31 Sekolah Tinggi Ilmu Statistik (STIS) Precedence Graph Use precedence graph to test for serializability Create:  Node for each transaction;  A directed edge T i  T j, if T j reads the value of an item written by T i ;  A directed edge T i  T j, if T j writes a value into an item after it has been read by T i.  A directed edge T i  T j, if T j writes a value into an item after it has been written by T i. If precedence graph contains cycle, schedule is NOT conflict serializable. 31 Dr. Said Mirza Pahlevi, M.Eng. i j i j i j

32 Sekolah Tinggi Ilmu Statistik (STIS) Example: Non-conflict serializable schedule T9 is transferring £100 from one account with balance bal x to another account with balance bal y. T10 is increasing balance of these two accounts by 10%. Precedence graph has a cycle and so is not serializable. T 9  T 10 T 9  T 10 32 Dr. Said Mirza Pahlevi, M.Eng.

33 Sekolah Tinggi Ilmu Statistik (STIS) Exercise Schedule S1: r 1 (A); w 1 (A); r 2 (A); w 2 (A); r 1 (B); w 1 (B); r 2 (B); w 2 (B)  S1 is a conflict-serializable with T 1  T 2 Schedule S2: r 2 (A); r 1 (B); w 2 (A); r 3 (A); w 1 (B); w 3 (A); r 2 (B); w 2 (B)  S2 is a conflict-serializable with T 1  T 2  T 3 33 Dr. Said Mirza Pahlevi, M.Eng.


Download ppt "Sekolah Tinggi Ilmu Statistik (STIS) 1 Dr. Said Mirza Pahlevi, M.Eng."

Similar presentations


Ads by Google