Fall 2001Arthur Keller – CS 18012–1 Schedule Nov. 6 (T) Transactions, Authorization. u Read Sections 8.6-8.7. Nov. 8 (TH) Object-Oriented Database Design.

Slides:



Advertisements
Similar presentations
Database Systems (資料庫系統)
Advertisements

Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Transaction Management Overview Chapter 16.
1 Lecture 11: Transactions: Concurrency. 2 Overview Transactions Concurrency Control Locking Transactions in SQL.
1 Lecture 10: Transactions. 2 The Setting uDatabase systems are normally being accessed by many users or processes at the same time. wBoth queries and.
Transaction Management: Concurrency Control CS634 Class 17, Apr 7, 2014 Slides based on “Database Management Systems” 3 rd ed, Ramakrishnan and Gehrke.
TRANSACTION PROCESSING SYSTEM ROHIT KHOKHER. TRANSACTION RECOVERY TRANSACTION RECOVERY TRANSACTION STATES SERIALIZABILITY CONFLICT SERIALIZABILITY VIEW.
Concurrency Control Amol Deshpande CMSC424. Approach, Assumptions etc.. Approach  Guarantee conflict-serializability by allowing certain types of concurrency.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Concurrency Control Chapter 17 Sections
Lecture 11 Recoverability. 2 Serializability identifies schedules that maintain database consistency, assuming no transaction fails. Could also examine.
Transactions and Locking Rose-Hulman Institute of Technology Curt Clifton.
Quick Review of Apr 29 material
Concurrency Control and Recovery In real life: users access the database concurrently, and systems crash. Concurrent access to the database also improves.
CS 245Notes 101 CS 245: Database System Principles Notes 10: More TP Hector Garcia-Molina.
1 Transactions Serializability Isolation Levels Atomicity.
1 Transaction Management Overview Yanlei Diao UMass Amherst March 15, 2007 Slides Courtesy of R. Ramakrishnan and J. Gehrke.
Winter 2002Arthur Keller – CS 18013–1 Schedule Today: Feb. 21 (TH) u Transactions, Authorization. u Read Sections Project Part 5 due. Feb. 26.
Transaction Processing: Concurrency and Serializability 10/4/05.
Transaction Management
Dec 15, 2003Murali Mani Transactions and Security B term 2004: lecture 17.
Cs3431 Transactions, Logging and Security. cs3431 Transactions: What and Why? A set of operations on a database must appear as one “unit”. Example: Consider.
©Silberschatz, Korth and Sudarshan16.1Database System Concepts 3 rd Edition Chapter 16: Concurrency Control Lock-Based Protocols Timestamp-Based Protocols.
Transaction Management Chapter 9. What is a Transaction? A logical unit of work on a database A logical unit of work on a database An entire program An.
1 Transaction Management Overview Chapter Transactions  Concurrent execution of user programs is essential for good DBMS performance.  Because.
1 Transaction Management Overview Chapter Transactions  A transaction is the DBMS’s abstract view of a user program: a sequence of reads and writes.
Database Management Systems, 2 nd Edition. R. Ramakrishnan and J. Gehrke1 Transaction Management Overview Chapter 18.
08_Transactions_LECTURE2 DBMSs should guarantee ACID properties (Atomicity, Consistency, Isolation, Durability). This is typically done by guaranteeing.
Database Management Systems, 2 nd Edition. R. Ramakrishnan and J. Gehrke1 Transaction Management Overview Lecture 21 Ramakrishnan - Chapter 18.
CS 245Notes 101 CS 245: Database System Principles Notes 10: More TP Hector Garcia-Molina.
Databases Illuminated
Database Systems/COMP4910/Spring05/Melikyan1 Transaction Management Overview Unit 2 Chapter 16.
1 Transaction Management Overview Chapter Transactions  Concurrent execution of user programs is essential for good DBMS performance.  Because.
SCUJoAnne Holliday11–1 Schedule Today: u Transaction concepts. u Read Sections Next u Authorization and security.
Transactions CPSC 356 Database Ellen Walker Hiram College (Includes figures from Database Systems by Connolly & Begg, © Addison Wesley 2002)
Winter 2006Keller, Ullman, Cushing13–1 TRANSACTION MANAGEMENT Airline Reservationsmany updates Statistical Abstract of the USmany queries Atomicity – all.
TRANSACTION MANAGEMENT R.SARAVANAKUAMR. S.NAVEEN..
1 Transactions Chapter Transactions A transaction is: a logical unit of work a sequence of steps to accomplish a single task Can have multiple.
Transaction Management Overview. Transactions Concurrent execution of user programs is essential for good DBMS performance. – Because disk accesses are.
1 CSE232A: Database System Principles More Concurrency Control and Transaction Processing.
1 SQL Authorization (Chap. 8.7) Privileges Grant and Revoke Grant Diagrams.
1 Transactions Serializability Isolation Levels Atomicity.
Multidatabase Transaction Management COP5711. Multidatabase Transaction Management Outline Review - Transaction Processing Multidatabase Transaction Management.
1 Transaction Processing Case Study. 2 Interaksi Proses There is table Sells(shop,beverage,price), and suppose that Joe’s Shop sells only Juice for $2.50.
Jinze Liu. ACID Atomicity: TX’s are either completely done or not done at all Consistency: TX’s should leave the database in a consistent state Isolation:
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Transaction Management Overview Chapter 16.
TRANSACTION PROCESSING 1. 2 Why Transactions? uDatabase systems are normally being accessed by many users or processes at the same time. wBoth queries.
Transaction Management
Transaction Management Overview
CS422 Principles of Database Systems Concurrency Control
Concurrency Control.
Schedule Today Transactions, Authorization. Sections
Part- A Transaction Management
Transaction Management
Transaction Processing
Transactions.
Transaction Management Overview
Transactions Properties.
Transactions B.Ramamurthy Ch.13 11/22/2018 B.Ramamurthy.
Transaction Management
Transaction Management Overview
Chapter 10 Transaction Management and Concurrency Control
Lecture 21: Concurrency & Locking
Database Transactions
Chapter 15 : Concurrency Control
Transaction management
Transaction Management
Transaction Management Overview
Transactions, Views, Indexes
Transaction Management Overview
Presentation transcript:

Fall 2001Arthur Keller – CS 18012–1 Schedule Nov. 6 (T) Transactions, Authorization. u Read Sections Nov. 8 (TH) Object-Oriented Database Design. u Read Sections Project Part 5 due on Sunday night. Nov. 13 (T) Object-Relational, Object Queries (OQL). u Read Sections 4.5, 9.1. Assignment 6 due. (No office hours.) Nov. 15 (TH) More OQL. u Read Sections Project Part 6 due on Sunday night. Nov. 20 (T) Object-Relational Queries. u Read Sections Assignment 7 due (no late ones). Nov. 22 (TH) Thanksgiving - No class scheduled. Nov. 27 (T) Semistructured Data, XML. u Read Sections Assignment 8 due. Project Part 7 due.

Fall 2001Arthur Keller – CS 18012–2 TRANSACTION MANAGEMENT Airline Reservationsmany updates Statistical Abstract of the USmany queries Atomicity – all or nothing principle Serializability – the effect of transactions as if they occurred one at a time Items – units of data to be controlled fine-grained – small items course-grained – large items (granularity) Controlling access by locks Read – sharable with other readersshared Write – not sharable with anyone else exclusive Model – (item, locktype, transaction ID)

Fall 2001Arthur Keller – CS 18012–3 Transactions = units of work that must be: 1.Atomic = either all work is done, or none of it. 2.Consistent = relationships among values maintained. 3.Isolated = appear to have been executed when no other DB operations were being performed. u Often called serializable behavior. 4.Durable = effects are permanent even if system crashes.

Fall 2001Arthur Keller – CS 18012–4 Commit/Abort Decision Each transaction ends with either: 1. Commit = the work of the transaction is installed in the database; previously its changes may be invisible to other transactions. 2. Abort = no changes by the transaction appear in the database; it is as if the transaction never occurred.  ROLLBACK is the term used in SQL and the Oracle system. In the ad-hoc query interface (e.g., PostgreSQL psql interface), transactions are single queries or modification statements.  Oracle allows SET TRANSACTION READ ONLY to begin a multistatement transaction that doesn't change any data, but needs to see a consistent “snapshot” of the data. In program interfaces, transactions begin whenever the database is accessed, and end when either a COMMIT or ROLLBACK statement is executed.

Fall 2001Arthur Keller – CS 18012–5 Example Sells(bar, beer, price) Joe's Bar sells Bud for $2.50 and Miller for $3.00. Sally is querying the database for the highest and lowest price Joe charges: 1 SELECT MAX(price) FROM Sells WHERE bar = 'Joe''s Bar'; 2 SELECT MIN(price) FROM Sells WHERE bar = 'Joe''s Bar'; At the same time, Joe has decided to replace Miller and Bud by Heineken at $3.50: 3 DELETE FROM Sells WHERE bar = 'Joe''s Bar' AND (beer = 'Miller' OR beer = 'Bud'); 4 INSERT INTO Sells VALUES('Joe''s bar', 'Heineken', 3.50); If the order of statements is 1, 3, 4, 2, then it appears to Sally that Joe's minimum price is greater than his maximum price. Fix the problem by grouping Sally's two statements into one transaction, e.g., with one SQL statement.

Fall 2001Arthur Keller – CS 18012–6 Example: Problem With Rollback Suppose Joe executes statement 4 (insert Heineken), but then, during the transaction thinks better of it and issues a ROLLBACK statement. If Sally is allowed to execute her statement 1 (find max) just before the rollback, she gets the answer $3.50, even though Joe doesn't sell any beer for $3.50. Fix by making statement 4 a transaction, or part of a transaction, so its effects cannot be seen by Sally unless there is a COMMIT action.

Fall 2001Arthur Keller – CS 18012–7 SQL Isolation Levels Isolation levels determine what a transaction is allowed to see. The declaration, valid for one transaction, is: SET TRANSACTION ISOLATION LEVEL X ; where: X = SERIALIZABLE : this transaction must execute as if at a point in time, where all other transactions occurred either completely before or completely after.  Example: Suppose Sally's statements 1 and 2 are one transaction and Joe's statements 3 and 4 are another transaction. If Sally's transaction runs at isolation level SERIALIZABLE, she would see the Sells relation either before or after statements 3 and 4 ran, but not in the middle.

Fall 2001Arthur Keller – CS 18012–8 X = READ COMMITTED : this transaction can read only committed data.  Example: if transactions are as above, Sally could see the original Sells for statement 1 and the completely changed Sells for statement 2. X = REPEATABLE READ : if a transaction reads data twice, then what it saw the first time, it will see the second time (it may see more the second time). u Example: If 1 is executed before 3, then 2 must see the Bud and Miller tuples when it computes the min, even if it executes after 3. But if 1 executes between 3 and 4, then 2 may see the Heineken tuple.

Fall 2001Arthur Keller – CS 18012–9 X = READ UNCOMMITTED : essentially no constraint, even on reading data written and then removed by a rollback. u Example: 1 and 2 could see Heineken, even if Joe rolled back his transaction.

Fall 2001Arthur Keller – CS 18012–10 T1 T2 start with A = 5 Read A A on disk A in T1 A in T2 Read A A:= A + 1 A:= 2* A Write A

Fall 2001Arthur Keller – CS 18012–11 THEM RLOCK A NO R W WLOCK A NO OK OK OK UNLOCK A US R OK OK bad W OK bad bad RLOCK –> UNLOCK can enclose a read WLOCK –> UNLOCK can enclose a write or read

Fall 2001Arthur Keller – CS 18012–12 T1 T2 WLOCK A Read A WLOCK A A:= A+1 Write A waits UNLOCK A granted Read A A:=2*A Write A UNLOCK A

Fall 2001Arthur Keller – CS 18012–13 T1 T2 RLOCK A Read A RLOCK A Read A A:= A+1 A:= 2*A WLOCK A upgrade lock request wait waits Deadlock!

Fall 2001Arthur Keller – CS 18012–14 T1 T2 WLOCK A WLOCK B wait WLOCK A UNLOCK A wait deadlock UNLOCK B UNLOCK A

Fall 2001Arthur Keller – CS 18012–15 Deadlock AND 1. Wait and hold hold some locks while you wait for others 2. Circular chain of waiters T4 wait-for graph T1 T3 T2 3. No pre-emption We can avoid deadlock by doing at least ONE of: 1. Get all your locks at once 2. Apply an ordering to acquiring locks 3. Allow preemption (for example, use timeout on waits)

Fall 2001Arthur Keller – CS 18012–16 Serializability of schedules T1 Read (A) A:= A-50 Write (A) Read (B) B:= B+50 Write (B) Schedule is serializable if effect is the same as a serial schedule T1 –> T2 T2 –> T1 A= B= T2 Read (A) temp:= A * 0.1 A:= A + temp Write (A) Read (B) B:= B - temp Write (B) A B disk T1 T2 T1T2 ABAB

Fall 2001Arthur Keller – CS 18012–17 Ignore arithmetic. What is important is the same sequence of operations. Conflicts Read-write Write-read Write-write Two schedules S1, S2 are equivalent if 1. Set of transactions in S1 and S2 are the same 2. For each data item Q, if in S1, Ti executes Read (Q) and the value of Q read by Ti was written by Tj then the same is true in S2 3. For each data item Q, if in S1, transaction Ti executes last write (Q), then same is true in S2 A schedule is serializable if it is equivalent to a serial schedule.

Fall 2001Arthur Keller – CS 18012–18 Non-fatal errors Not recognizing that a schedule is serializable Fatal errors Thinking that a schedule is serializable when it is not

Fall 2001Arthur Keller – CS 18012–19 Algorithm: Testing serializability of a schedule Input: Schedule S for transactions T1,…, Tk Output: Determination of whether S is serializable, and if so, an equivalent serial schedule. Method: Create a directed graph G (called a serialization graph) Create a node for each transaction and label with transaction ID Create an edge for each Ti: UNLOCK Am followed by Tj: LOCK Am (where lock modes conflict). The edge Ti --> Tj labeled Am (the data item) If there is a cycle then schedule is non-serializable. If there is no cycle, then (it is a DAG) do a topological sort to get a serial schedule DAG implies some partial order. Any total order consistent with the partial order is an equivalent serial schedule.

Fall 2001Arthur Keller – CS 18012–20 T3 T6 T4 T5 A AB C T1 T2 T3 T4 T5 T6 T2 T1 D C

Fall 2001Arthur Keller – CS 18012–21 If no progress is possible, then there is a cycle T3 T6 T4 T5 A A B C T1 T2 T3 T4 T5 T6 T2 T1 D C D

Fall 2001Arthur Keller – CS 18012–22 T1T2 LOCK A UNLOCK A LOCK A UNLOCK A LOCK B UNLOCK B LOCK B UNLOCK B T1T2 A B

Fall 2001Arthur Keller – CS 18012–23 ABORT CAN CAUSE CASCADING ROLLBACK T1T2 LOCK A Read A change A Write A UNLOCK A LOCK A Read A change A Write A UNLOCK A LOCK B Read B Discover problem ABORT Need to undo the change to A CASCADED ABORT

Fall 2001Arthur Keller – CS 18012–24 How to avoid cascading rollback. Make decision early Defer commit of dependent transaction Hold locks until abort no longer possible

Fall 2001Arthur Keller – CS 18012–25 2PL 2-Phase Locking Phase I: All requesting of locks precedes Phase II: Any releasing of locks Theorem: Any schedule for 2-phase locked transaction is serializable

Fall 2001Arthur Keller – CS 18012–26 Time Data items T3 T1 T2 T4

Fall 2001Arthur Keller – CS 18012–27 commit

Fall 2001Arthur Keller – CS 18012–28 Commit or Abort occurs in between Phase I and Phase II Effects are permanent Effects are not visible Abort roll back

Fall 2001Arthur Keller – CS 18012–29 Read and write locks Edges: 1. Ti read locks or write locks Am Tj is next transaction to write lock A i ≠ j edge Ti --> Tj R-W, W-W conflict 2. Ti write locks A then  transactions Tk that readlock A after Ti but before another transaction write locks A edge Ti --> Tk's W-R conflict

Fall 2001Arthur Keller – CS 18012–30 Ti WLOCK A Tk1 RLOCK A Tk2 RLOCK A Tj WLOCK A

Fall 2001Arthur Keller – CS 18012–31 N R W I None OK OK OK OK Read OK OK bad bad Write OK bad bad bad Increment OK bad bad OK T1 INCR (A) READ (B) WRITE (B) T2 INCR (A) READ (B) WRITE (B)

Fall 2001Arthur Keller – CS 18012–32 T2 T1 B A B if increment locks if no increment locks

Fall 2001Arthur Keller – CS 18012–33 Authorization in SQL File systems identify certain access privileges on files, e.g., read, write, execute. In partial analogy, SQL identifies six access privileges on relations, of which the most important are: 1. SELECT = the right to query the relation. 2. INSERT = the right to insert tuples into the relation – may refer to one attribute, in which case the privilege is to specify only one column of the inserted tuple. 3. DELETE = the right to delete tuples from the relation. 4. UPDATE = the right to update tuples of the relation – may refer to one attribute.

Fall 2001Arthur Keller – CS 18012–34 Granting Privileges You have all possible privileges to the relations you create. You may grant privileges to any user if you have those privileges “with grant option.” u You have this option to your own relations. Example 1. Here, Sally can query Sells and can change prices, but cannot pass on this power: GRANT SELECT ON Sells, UPDATE(price) ON Sells TO sally; 2. Here, Sally can also pass these privileges to whom she chooses: GRANT SELECT ON Sells, UPDATE(price) ON Sells TO sally WITH GRANT OPTION;

Fall 2001Arthur Keller – CS 18012–35 Revoking Privileges Your privileges can be revoked. Syntax is like granting, but REVOKE... FROM instead of GRANT... TO. Determining whether or not you have a privilege is tricky, involving “grant diagrams” as in text. However, the basic principles are: a)If you have been given a privilege by several different people, then all of them have to revoke in order for you to lose the privilege. b)Revocation is transitive. if A granted P to B, who then granted P to C, and then A revokes P from B, it is as if B also revoked P from C.