180 likes | 383 Views
Transaction Processing. IS698 Min Song. What is a Transaction?. When an event in the real world changes the state of the enterprise, a transaction is executed to cause the corresponding change in the database state
E N D
Transaction Processing IS698 Min Song
What is a Transaction? • When an event in the real world changes the state of the enterprise, a transaction is executed to cause the corresponding change in the database state • With an on-line database, the event causes the transaction to be executed in real time • A transaction is an application program with special properties - discussed later - to guarantee it maintains database correctness
What is a Transaction Processing System? • Transaction execution is controlled by a TP monitor • Creates the abstraction of a transaction, analogous to the way an operating system creates the abstraction of a process • TP monitor and DBMS together guarantee the special properties of transactions • A Transaction Processing System consists of TP monitor, databases, and transactions
Transaction Processing System DBMS database transactions DBMS database TP Monitor
System Requirements • High Availability: on-line => must be operational while enterprise is functioning • High Reliability: correctly tracks state, does not lose data, controlled concurrency • High Throughput: many users => many transactions/sec • Low Response Time: on-line => users are waiting
System Requirements (con’t) • Long Lifetime: complex systems are not easily replaced • Must be designed so they can be easily extended as the needs of the enterprise change • Security: sensitive information must be carefully protected since system is accessible to many users • Authentication, authorization, encryption
Roles in Design, Implementation, and Maintenance of a TPS • System Analyst - specifies system using input from customer; provides complete description of functionality from customer’s and user’s point of view • Database Designer - specifies structure of data that will be stored in database • Application Programmer - implements application programs (transactions) that access data and support enterprise rules
Roles in Design, Implementation and Maintenance of a TPS (con’t) • Database Administrator - maintains database once system is operational: space allocation, performance optimization, database security • System Administrator - maintains transaction processing system: monitors interconnection of HW and SW modules, deals with failures and congestion
Transaction Concept • A transactionis a unit of program execution that accesses and possibly updates various data items. • E.g. transaction to transfer $50 from account A to account B: 1. read(A) 2. A := A – 50 3. write(A) 4. read(B) 5. B := B + 50 6. write(B) • Two main issues to deal with: • Failures of various kinds, such as hardware failures and system crashes • Concurrent execution of multiple transactions
Example of Fund Transfer • Transaction to transfer $50 from account A to account B: 1. read(A) 2. A := A – 50 3. write(A) 4. read(B) 5. B := B + 50 6. write(B) • Atomicity requirement • if the transaction fails after step 3 and before step 6, money will be “lost” leading to an inconsistent database state • Failure could be due to software or hardware • the system should ensure that updates of a partially executed transaction are not reflected in the database • Durability requirement — once the user has been notified that the transaction has completed (i.e., the transfer of the $50 has taken place), the updates to the database by the transaction must persist even if there are software or hardware failures.
Example of Fund Transfer (Cont.) • Transaction to transfer $50 from account A to account B: 1. read(A) 2. A := A – 50 3. write(A) 4. read(B) 5. B := B + 50 6. write(B) • Consistency requirement in above example: • the sum of A and B is unchanged by the execution of the transaction • In general, consistency requirements include • Explicitly specified integrity constraints such as primary keys and foreign keys • Implicit integrity constraints • e.g. sum of balances of all accounts, minus sum of loan amounts must equal value of cash-in-hand • A transaction must see a consistent database. • During transaction execution the database may be temporarily inconsistent. • When the transaction completes successfully the database must be consistent • Erroneous transaction logic can lead to inconsistency
Example of Fund Transfer (Cont.) • Isolation requirement — if between steps 3 and 6, another transaction T2 is allowed to access the partially updated database, it will see an inconsistent database (the sum A + B will be less than it should be).T1 T2 1. read(A) 2. A := A – 50 3. write(A) read(A), read(B), print(A+B) 4. read(B) 5. B := B + 50 6. write(B • Isolation can be ensured trivially by running transactions serially • that is, one after the other. • However, executing multiple transactions concurrently has significant benefits.
Transaction State • Active –the initial state; the transaction stays in this state while it is executing • Partially committed –after the final statement has been executed. • Failed -- after the discovery that normal execution can no longer proceed. • Aborted – after the transaction has been rolled back and the database restored to its state prior to the start of the transaction. Two options after it has been aborted: • restart the transaction • can be done only if no internal logical error • kill the transaction • Committed – after successful completion.
Implementation of Atomicity and Durability • The recovery-management component of a database system implements the support for atomicity and durability. • E.g. the shadow-database scheme: • all updates are made on a shadow copy of the database • db_pointer is made to point to the updated shadow copy after • the transaction reaches partial commit and • all updated pages have been flushed to disk.
Implementation of Atomicity and Durability (Cont.) • db_pointer always points to the current consistent copy of the database. • In case transaction fails, old consistent copy pointed to by db_pointer can be used, and the shadow copy can be deleted. • The shadow-database scheme: • Assumes that only one transaction is active at a time. • Assumes disks do not fail • Useful for text editors, but • extremely inefficient for large databases • Variant called shadow paging reduces copying of data, but is still not practical for large databases • Does not handle concurrent transactions
Concurrent Executions • Multiple transactions are allowed to run concurrently in the system. Advantages are: • increased processor and disk utilization, leading to better transaction throughput • E.g. one transaction can be using the CPU while another is reading from or writing to the disk • reduced average response time for transactions: short transactions need not wait behind long ones. • Concurrency control schemes– mechanisms to achieve isolation • that is, to control the interaction among the concurrent transactions in order to prevent them from destroying the consistency of the database