Académique Documents
Professionnel Documents
Culture Documents
4)
605.741 David Silberberg
Introduction
Up until now, we have concentrated on query management
Planning Optimization Execution
We want consistent execution and reliable computation Transactions provides both consistency and reliability
D. Silberberg Distributed Database Systems Introduction to Transaction Mgmt. 2
Database is usually inconsistent during an operation, but consistent before and after
Transaction consistency
Allow multiple queries to update database, yet maintain consistency When the database is distributed
We want mutual consistency to ensure all copied data is identical Referred to as one-copy equivalence
D. Silberberg
More Definitions
Reliability
Resiliency to failures Ability to recover from failures
Transaction management
Deals with the problem of keeping database(s) in a consistent state Consistency must be maintained even with failures
D. Silberberg
PART
ORDER
STORE
D. Silberberg
Sample Transaction
{ Connection conn = DriverManager.getConnection("URL", properites); conn.setAutoCommit(false); // begin transaction Statement stmt = conn.createStatement(); stmt.executeUpdate("UPDATE PART SET parts_sold = parts_sold + 1 WHERE pno = 153"); stmt = conn.createStatement(); stmt.executeUpdate("INSERT INTO ORDER VALUES(153, 11, "deliver"); conn.commit(); // end transaction System.out.println("Order processed!"); }
Both updates or neither must be executed In this example, we assume that the transaction completes
D. Silberberg
D. Silberberg
D. Silberberg
Characterizing Transactions
Fortunately, we really have to worry about only two primary operations to characterize transactions
Read - R(x) Write - W (x)
D. Silberberg
11
D. Silberberg
12
The specific operations and ordering are application dependent There must be ordering between conflicts
Read Write conflicts Write Write conflicts
D. Silberberg
13
Simple Example
Transaction 1. Read(x) 2. Read(y) 3. x <- x+y 4. Write(x) 5. Commit Directed Acyclic Graph (DAG) representation of the operations and partial ordering of the transaction:
R(x) W(x) R(y) C
D. Silberberg
14
Since we understand the partial ordering rules, we can just use relative ordering notation:
T = {R(x), R(y), W(x), C} We understand from this this the partial ordering rules above
D. Silberberg
15
Commit notation
= { R(parts_sold), R(total_parts), W(parts_sold), W(pno), W(sno), W(special), C } p = { (R(parts_sold), W(parts_sold)), (R(total_parts), W(parts_sold)), (R(parts_sold), W(pno)), (R(parts_sold), W(sno)), (R(parts_sold), W(special)), (R(total_parts), W(pno)), (R(total_parts), W(sno)), (R(total_parts), W(special)), (R(parts_sold), C), (R(total_parts), C), (W(parts_sold), C), (W(sno), C), (W(special),C) }
D. Silberberg
16
Concurrency Control implements Consistency and Isolation Recovery Management implements Atomicity and Durability
D. Silberberg
17
Atomicity
Transaction is a unit of operation
All transactions either complete or not "All-or-nothing" property
If failure occurs, DBMS must either undo parts of transactions or complete them at a later time Two types of failures
Logic errors
Data errors Deadlocks Consistency -> Transaction aborts itself or DBMS aborts Media errors System crashes Network problems -> In these cases, we need crash recovery
System crashes
D. Silberberg
18
Consistency
Consistency = correctness A transaction maps one consistent database state to another Verifying transaction consistency is the job of the semantic data controller Ensuring transaction consistency is the job of the concurrency controller
D. Silberberg
19
Isolation
Each transaction must see a consistent database at all times The transaction effects cannot be seen by other transactions before the transaction is complete Concurrent transactions must be executed with the appearance that they were done in some linear order. Problems encountered
Dirty Read Non-Repeatable Read Phantom Read Overwriting Uncommitted Data
Distributed Database Systems Introduction to Transaction Mgmt. 20
D. Silberberg
read(x) x = 1.06* x write(x) read(y) y = 1.06* y write(y) commit read(y) x = x+100 write(y) commit
D. Silberberg
21
In our scenario
D. Silberberg
D. Silberberg
23
Phantom Reads
Read-Write conflicts T2:
write(new deposit) commit read(deposit list) write(deposit list) Commit Transaction 1 does not have what is indicated on the deposit slip!
D. Silberberg Distributed Database Systems Introduction to Transaction Mgmt. 24
T2:
D. Silberberg
25
Durability
Once transaction commits, it is permanent Transaction will survive subsequent failures
D. Silberberg
26
D. Silberberg
27
TM
other SCs
other TMs
SC
data processors
D. Silberberg
28