Скачать презентацию Transactions Transaction Processing q q q Most Скачать презентацию Transactions Transaction Processing q q q Most

f012d55668866505b70211423f0db6bc.ppt

  • Количество слайдов: 20

Transactions Transactions

Transaction Processing q q q Most of the information systems in businesses are transaction Transaction Processing q q q Most of the information systems in businesses are transaction based (databases or TP-Monitors). The market for transaction processing is many tens of billions of dollars per year Past: transaction processing was used mostly in large companies Now: WWW, small TP-Monitors, CORBA, Internet provider, J 2 EE have a need for transactions Transactions are now no more just a database technology, they started to be a core distributed information systems technology. 421 B: Database Systems - Transactions 2

Business transactions q Business transaction: involves exchange between two or more entities (selling, buying, Business transactions q Business transaction: involves exchange between two or more entities (selling, buying, renting, booking …. ). q In computers: business transactions become electronic transactions (same ideas) Seller Buyer State Book-keeping 421 B: Database Systems - Transactions 3

Money Transfer 1. Transfer(id 1, id 2, value) SELECT balance into : balance FROM Money Transfer 1. Transfer(id 1, id 2, value) SELECT balance into : balance FROM accounts WHERE accountid = : id 1 balance += value UPDATE accounts SET balance = : balance WHERE accountid = : id 1 1. 2. 3. 4. 5. 6. read(A) A : = A + 50 write(A) read(B) B : = B - 50 write(B) SELECT balance into : balance FROM accounts WHERE accountid = : id 2 balance -= value UPDATE accounts SET balance = : balance WHERE accountid = : id 2 421 B: Database Systems - Transactions 4

Electronic transaction q. A txn encapsulate operations that belong logically together I Operations within Electronic transaction q. A txn encapsulate operations that belong logically together I Operations within the DBS increase account of seller, decrease account of buyer I Operations outside the DBS: the good is given to the buyer I Electronic txn: programming and DB part I Consider transaction as a sphere of control in which to encapsulate certain behavior of particular pieces of code I A transaction is basically a set of service invocations, usually from a program (or a interactive user interface) 421 B: Database Systems - Transactions 5

Some issues q An electronic transaction is not simply a sequence of DB operations Some issues q An electronic transaction is not simply a sequence of DB operations but a complex idea: I Specify of what operations build a transaction I Transactions must be correct even if many of them are running concurrently (at the same time over the same data). I Transactions must be atomic. Partially executed transactions are almost always incorrect I Legally, most business transactions require a written record. So do electronic transactions I The system must handle a high volume (high throughput), must provide fast response time, and must be available all the time (mission critical). 421 B: Database Systems - Transactions 6

Automated Teller Machine q Tables: I Account. Balance(Acct#, balance) I Hot. Card-List(Accct#): stolen/canceled/suspended cards Automated Teller Machine q Tables: I Account. Balance(Acct#, balance) I Hot. Card-List(Accct#): stolen/canceled/suspended cards I Account. Velocity(Acct#, sum. Withdrawals): stores the latest transaction and accumulated amount I Posting. Log(Acct#, ATMid, Amount): a record of each operation q Operations for withdrawal: I I I I I Get. Input(Acct#, ATMid, type, PIN, Txn-id, Amount) Write request to Posting. Log Check PIN Check Acct# with Hot. Card-List table Check Acct# with Account. Velocity table Update balance in Account. Balance Write withdrawal record to Posting. Log Commit transaction and dispense money. 421 B: Database Systems - Transactions 7

Stock Exchange q Tables I Users: list of traders and market watchers I Stocks Stock Exchange q Tables I Users: list of traders and market watchers I Stocks I Buy. Orders/Sell. Orders: orders entered during the day I Trades: all trades executed during the day I Price: buy and sell total volume, and number of orders for each stock and price I Log: all users’ requests and system replies I notification. Msg: all messages sent to the users 421 B: Database Systems - Transactions 8

Stock Exchange q Operation execute trade: I Read information about stock from stock table Stock Exchange q Operation execute trade: I Read information about stock from stock table I Get timestamp I Read scheduled trading periods for the stock I Check validity of operation (time, value, price) I If valid, find a matching trade operation, update trades, notif, orders, prices, stocks, … I Write the system’s response to the log I Commit transaction I Broadcast the new situation q Volumes bank/stock: 250000 transactions per day 421 B: Database Systems - Transactions 9

Application vs. DBS A user’s program may carry out many operations on the data Application vs. DBS A user’s program may carry out many operations on the data retrieved from the database, but the DBMS is only concerned about what data is read/written from/to the database. q A transaction is the DBMS’s abstract view of a user program: a sequence of read operations r(X) and write operations w(X) on objects (X) (tuple, relation, …) of the DB q I Read: bring object into main memory from disk, send value to application (same as copy value into program variable) I Write: bring object into main memory from disk and modify it. Write it back to disk (might be done sometime later) q Need for concurrency: I There might be considerable time between the submission of two consecutive SQL statements within one transaction I While the DBS is reading a tuple from the disk, the CPU can be used to parse and compile the SQL statements of other transactions. 421 B: Database Systems - Transactions 10

ACID Properties q The success of transactions was due to well-defined properties that are ACID Properties q The success of transactions was due to well-defined properties that are provided by transactional systems: I ATOMICITY: A transaction is atomic if it is executed in its entirety or not at all I CONSISTENCY: a transaction must preserve the consistency of the data I ISOLATION: in case that transactions are executed concurrently: The effect must be the same as if each transaction were the only one in the system. I DURABILITY: The changes made by a transaction must be permanent (= they must not be lost in case of failures) 421 B: Database Systems - Transactions 11

Atomicity q ALL or NOTHING principle I In Money transfer: if transaction fails after Atomicity q ALL or NOTHING principle I In Money transfer: if transaction fails after step 3 partial results should be undone I A transaction T might commit after completing all its actions. If the user is informed about the commit he/she can be sure that all changes performed by T are installed in the DB. I A transaction might abort (or be aborted by the DBMS) after executing some actions. In this case the DBMS undoes all modifications so far. After the abort the DB state is as if the transaction had never started. After notification of abort the user knows that none of the transaction’s modifications is reflected in the database. l Local recovery: eliminating partial results 421 B: Database Systems - Transactions 12

Atomicity consistent database Txn Recovery Manager 421 B: Database Systems - Transactions abort inconsistent Atomicity consistent database Txn Recovery Manager 421 B: Database Systems - Transactions abort inconsistent database Database log 13

Consistency q Each transaction must leave the database in a consistent state if the Consistency q Each transaction must leave the database in a consistent state if the DB is consistent when the transaction begins. I In Money transfer: sum of balances of two accounts the same before I and after transaction execution This is the responsibility of the application! In practice, transactions make mistakes (introduce negative salaries, empty social security numbers, different names for the same person …). These mistakes violate database consistency. q Limited forms of data consistency can be enforced by the system through integrity constraints: Null constraints, foreign keys, check constraints… q Integrity constraints acts as filters determining whether a transaction is acceptable or not. q consistent database 421 B: Database Systems - Transactions Txn consistent database 14

Isolation: Users submit transactions, and can think of each transaction as executing by itself. Isolation: Users submit transactions, and can think of each transaction as executing by itself. q The DBMS, however, allows many transactions being executed concurrently over the same data. q I By allowing several transactions to execute concurrently we can keep the CPU busy and process more transactions per time unit. q Isolation is enforced by a concurrency control protocol, which aims at guaranteeing serializability. I Net effect of transactions executing concurrently is identical to executing all transactions one after the other in some serial order I In Money transfer: disallow that concurrent transaction reads balance of both accounts after step 3 and before step 6 421 B: Database Systems - Transactions 15

Isolation consistent database Txn 1 Txn 2 inconsistent database Txn 1 Txn 2 … Isolation consistent database Txn 1 Txn 2 inconsistent database Txn 1 Txn 2 … consistent database Concurrency Control 421 B: Database Systems - Transactions 16

Durability q Durability: There must be a guarantee that the changes introduced by a Durability q Durability: There must be a guarantee that the changes introduced by a transaction will last, i. e. , survive failures • In Money transfer: once user has confirmation the change must persist in database despite possible crash • In case of failures, I Server Crash: l restart server and perform global recovery: s bringing the database back into an consistent state s At the time of the crash, some transactions might have been in the middle of execution: their modifications performed so far must be undone (abort of these transactions) s At the time of the crash, not all changes of committed transactions might have been reflected in the database: redo these modifications. In order to be able to perform recovery: logging of additional information during normal processing I Disk Crash: use replication: database backups, mirrored disks. l 421 B: Database Systems - Transactions 17

Global Recovery consistent Txn db db inconsistent db System crash Recovery Manager 421 B: Global Recovery consistent Txn db db inconsistent db System crash Recovery Manager 421 B: Database Systems - Transactions Database log 18

Architecture Txn (r, w, c, a) Transaction Manager Scheduler (concurrency control) Recovery Manager Buffer Architecture Txn (r, w, c, a) Transaction Manager Scheduler (concurrency control) Recovery Manager Buffer 421 B: Database Systems - Transactions Stable DB Log 19

Architecture q Each of the modules is a complex component I Highly optimized; many Architecture q Each of the modules is a complex component I Highly optimized; many engineering optimizations q Components highly interconnected I Modularity only partially given I Complex calling strategies I One module relies heavily on the semantics of other modules 421 B: Database Systems - Transactions 20