1. Trang chủ
  2. » Giáo án - Bài giảng

cơ sở dữ liệu lê thị bảo thu chương ter c4 transaction processing sinhvienzone com

65 47 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 65
Dung lượng 1,16 MB

Nội dung

Chapter Introduction to Transaction Processing Concepts and Theory Adapted from the slides of “Fundamentals of Database Systems” (Elmasri et al., 2006) CuuDuongThanCong.com https://fb.com/tailieudientucntt Chapter Outline  Introduction to Transaction Processing  Transaction and System Concepts  Desirable Properties of Transactions  Characterizing Schedules based on Recoverability  Characterizing Schedules based on Serializability  Transaction Support in SQL CuuDuongThanCong.com https://fb.com/tailieudientucntt Introduction to Transaction Processing (1)  Single-User System: At most one user at a time can use the system  Multiuser System: Many users can access the system concurrently  Concurrency   Interleaved processing: concurrent execution of processes is interleaved in a single CPU Parallel processing: processes are concurrently executed in multiple CPUs CuuDuongThanCong.com https://fb.com/tailieudientucntt Introduction to Transaction Processing (2)  A Transaction: logical unit of database processing that includes one or more access operations (read -retrieval, write - insert or update, delete)  A transaction (set of operations) may be standalone specified in a high level language like SQL submitted interactively, or may be embedded within a program   Transaction boundaries: Begin and End transaction An application program may contain several transactions separated by the Begin and End transaction boundaries CuuDuongThanCong.com https://fb.com/tailieudientucntt Introduction to Transaction Processing (3) SIMPLE MODEL OF A DATABASE (for purposes of discussing transactions):   A database - collection of named data items Granularity of data - a field, a record , or a whole disk block (Concepts are independent of granularity)  Basic operations are read and write   read_item(X): Reads a database item named X into a program variable To simplify our notation, we assume that the program variable is also named X write_item(X): Writes the value of program variable X into the database item named X CuuDuongThanCong.com https://fb.com/tailieudientucntt Introduction to Transaction Processing (4) READ AND WRITE OPERATIONS: Basic unit of data transfer from the disk to the computer main memory is one block Data item (what is read or written):     the field of some record in the database, a larger unit such as a record or even a whole block read_item(X) command includes the following steps:  Find the address of the disk block that contains item X Copy that disk block into a buffer in main memory (if that disk block is not already in some main memory buffer) Copy item X from the buffer to the program variable named X CuuDuongThanCong.com https://fb.com/tailieudientucntt Introduction to Transaction Processing (5) READ AND WRITE OPERATIONS (cont.):  write_item(X) command includes the following steps: Find the address of the disk block that contains item X Copy that disk block into a buffer in main memory (if that disk block is not already in some main memory buffer) Copy item X from the program variable named X into its correct location in the buffer Store the updated block from the buffer back to disk (either immediately or at some later point in time) CuuDuongThanCong.com https://fb.com/tailieudientucntt Two sample transactions (a) Transaction T1 (b) Transaction T2 CuuDuongThanCong.com https://fb.com/tailieudientucntt Introduction to Transaction Processing (7) Why Concurrency Control is needed:   The Lost Update Problem This occurs when two transactions that access the same database items have their operations interleaved in a way that makes the value of some database item incorrect The Temporary Update (or Dirty Read) Problem This occurs when one transaction updates a database item and then the transaction fails for some reason The updated item is accessed by another transaction before it is changed back to its original value CuuDuongThanCong.com https://fb.com/tailieudientucntt Some problems that occur when concurrent execution is uncontrolled (a) The lost update problem CuuDuongThanCong.com https://fb.com/tailieudientucntt 10 Example of Serializability Testing (1) Serializable schedule CuuDuongThanCong.com https://fb.com/tailieudientucntt Example of Serializability Testing (2) Serializable schedule CuuDuongThanCong.com https://fb.com/tailieudientucntt Example of Serializability Testing (3) Not Serializable schedule CuuDuongThanCong.com https://fb.com/tailieudientucntt Example of Serializability Testing (4) Serializable schedule CuuDuongThanCong.com https://fb.com/tailieudientucntt Another example of serializability testing (a) The READ and WRITE operations of three transactions T1, T2, and T3 CuuDuongThanCong.com https://fb.com/tailieudientucntt 55 Another example of serializability testing (b) Schedule E CuuDuongThanCong.com https://fb.com/tailieudientucntt 56 Another example of serializability testing (c) Schedule F CuuDuongThanCong.com https://fb.com/tailieudientucntt 57 CuuDuongThanCong.com https://fb.com/tailieudientucntt 58 Transaction Support in SQL2 (1)    A single SQL statement is always considered to be atomic Either the statement completes execution without error or it fails and leaves the database unchanged With SQL, there is no explicit Begin Transaction statement Transaction initiation is done implicitly when particular SQL statements are encountered Every transaction must have an explicit end statement, which is either a COMMIT or ROLLBACK CuuDuongThanCong.com https://fb.com/tailieudientucntt 59 Transaction Support in SQL2 (2) Characteristics specified by a SET TRANSACTION statement in SQL2:   Access mode: READ ONLY or READ WRITE The default is READ WRITE unless the isolation level of READ UNCOMITTED is specified, in which case READ ONLY is assumed Diagnostic size n, specifies an integer value n, indicating the number of conditions that can be held simultaneously in the diagnostic area (Supply user feedback information) CuuDuongThanCong.com https://fb.com/tailieudientucntt 60 Transaction Support in SQL2 (3) Characteristics specified by a SET TRANSACTION statement in SQL2 (cont.):  Isolation level , where can be READ UNCOMMITTED, READ COMMITTED, REPEATABLE READ or SERIALIZABLE The default is SERIALIZABLE With SERIALIZABLE: the interleaved execution of transactions will adhere to our notion of serializability However, if any transaction executes at a lower level, then serializability may be violated CuuDuongThanCong.com https://fb.com/tailieudientucntt 61 Transaction Support in SQL2 (4) Potential problem with lower isolation levels:   Dirty Read: Reading a value that was written by a transaction which failed Nonrepeatable Read: Allowing another transaction to write a new value between multiple reads of one transaction A transaction T1 may read a given value from a table If another transaction T2 later updates that value and T1 reads that value again, T1 will see a different value Consider that T1 reads the employee salary for Smith Next, T2 updates the salary for Smith If T1 reads Smith's salary again, then it will see a different value for Smith's salary CuuDuongThanCong.com https://fb.com/tailieudientucntt 62 Transaction Support in SQL2(5) Potential problem with lower isolation levels (cont.): Phantoms: New rows being read using the same read with a condition     A transaction T1 may read a set of rows from a table, perhaps based on some condition specified in the SQL WHERE clause A transaction T2 inserts a new row that also satisfies the WHERE clause condition of T1, into the table used by T1 If T1 is repeated, then T1 will see a row that previously did not exist, called a phantom CuuDuongThanCong.com https://fb.com/tailieudientucntt 63 Transaction Support in SQL2 (6) Sample SQL transaction: EXEC SQL whenever sqlerror go to UNDO; EXEC SQL SET TRANSACTION READ WRITE DIAGNOSTICS SIZE ISOLATION LEVEL SERIALIZABLE; EXEC SQL INSERT INTO EMPLOYEE (FNAME, LNAME, SSN, DNO, SALARY) VALUES ('Robert','Smith','991004321',2,35000); EXEC SQL UPDATE EMPLOYEE SET SALARY = SALARY * 1.1 WHERE DNO = 2; EXEC SQL COMMIT; GOTO THE_END; UNDO: EXEC SQL ROLLBACK; THE_END: CuuDuongThanCong.com https://fb.com/tailieudientucntt 64 Transaction Support in SQL2 (7) Possible violation of serializabilty: CuuDuongThanCong.com https://fb.com/tailieudientucntt 65 ... or at some later point in time) CuuDuongThanCong .com https://fb .com/ tailieudientucntt Two sample transactions (a) Transaction T1 (b) Transaction T2 CuuDuongThanCong .com https://fb .com/ tailieudientucntt... the computer system during transaction execution If the hardware crashes, the contents of the computer’s internal memory may be lost A transaction or system error : Some operation in the transaction. .. the transaction starts, terminates, and commits or aborts  Transaction states:      Active state Partially committed state Committed state Failed state Terminated State CuuDuongThanCong.com

Ngày đăng: 29/01/2020, 14:40