Presentation is loading. Please wait.

Presentation is loading. Please wait.

Transactions A process that reads or modifies the DB is called a transaction. It is a unit of execution of database operations. Basic JDBC transaction.

Similar presentations


Presentation on theme: "Transactions A process that reads or modifies the DB is called a transaction. It is a unit of execution of database operations. Basic JDBC transaction."— Presentation transcript:

1 Transactions A process that reads or modifies the DB is called a transaction. It is a unit of execution of database operations. Basic JDBC transaction pattern Connection conn =...; conn.setAutoCommit(false); try {... //JDBC statements } finally { conn.commit(); } ACID : Properties of a transaction: Atomicity, Consistency, Isolation, and Durability

2 Correctness Principle A transaction is atomic -- all or none property. If it executes partly, an invalid state is likely to result. A transaction, may change the DB from a consistent state to another consistent state. Otherwise it is rejected (aborted). Concurrent execution of transactions may lead to inconsistency – each transaction must appear to be executed in isolation The effect of a committed transaction is durable i.e. the effect on DB of a transaction must never be lost, once the transaction has completed. ACID: Properties of a transaction: Atomicity, Consistency, Isolation, and Durability

3 Primitive DB Op’s of Transactions INPUT(X) ≡ copy the disk block containing the database element X to a memory buffer READ(X,t) ≡ assign the value of buffer X to local variable t WRITE(X,t) ≡ copy the value of t to buffer X OUTPUT(X) ≡ copy the block containing X from its buffer (in main memory) to disk

4 Example: Consider the database elements A and B such that the constraint A=B must hold. – This captures the spirit of many more realistic constraints, e.g.: The sum of the loan balances at a bank must equal the total debt of the bank Suppose transaction T doubles A and B A := A*2; B := B*2; Execution of T involves: – reading A and B from disk, – performing arithmetic in main memory, and – writing the new values for A and B back to disk.

5 Example (Cont’d) ActiontBuff ABuff BA in HDB in HD Read(A,t)8 888 t:=t*216 888 Write(A,t)161688 Read(B,t)816888 t:=t*21616888 Write(B,t)16161688 Output(A)161616168 Output(B)1616161616 Problem: what happens if there is a system failure just before OUTPUT(B)?

6 Concurrent Transactions Even when there is no “failure,” several transactions can interact to turn a consistent state into an inconsistent state.


Download ppt "Transactions A process that reads or modifies the DB is called a transaction. It is a unit of execution of database operations. Basic JDBC transaction."

Similar presentations


Ads by Google