DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI

Similar documents
Chapter 15: Transactions

Transactions. Lecture 8. Transactions. ACID Properties. Transaction Concept. Example of Fund Transfer. Example of Fund Transfer (Cont.

Database System Concepts

Transactions. Prepared By: Neeraj Mangla

Chapter 13: Transactions

BİL 354 Veritabanı Sistemleri. Transaction (Hareket)

Intro to DB CHAPTER 15 TRANSACTION MNGMNT

Advanced Databases (SE487) Prince Sultan University College of Computer and Information Sciences. Dr. Anis Koubaa. Spring 2014

Transactions These slides are a modified version of the slides of the book Database System Concepts (Chapter 15), 5th Ed

Transactions. Chapter 15. New Chapter. CS 2550 / Spring 2006 Principles of Database Systems. Roadmap. Concept of Transaction.

ICOM 5016 Database Systems. Chapter 15: Transactions. Transaction Concept. Chapter 15: Transactions. Transactions

Database Management Systems 2010/11

Database System Concepts

Database System Concepts

DATABASE DESIGN I - 1DL300

Chapter 15: Transactions

Transaction Concept. Two main issues to deal with:

References. Transaction Management. Database Administration and Tuning 2012/2013. Chpt 14 Silberchatz Chpt 16 Raghu

UNIT 4 TRANSACTIONS. Objective

CHAPTER: TRANSACTIONS

Chapter 14: Transactions

TRANSACTION PROCESSING PROPERTIES OF A TRANSACTION TRANSACTION PROCESSING PROPERTIES OF A TRANSACTION 4/3/2014

Chapter 9: Transactions

Transactions and Concurrency Control. Dr. Philip Cannata

CS322: Database Systems Transactions

Transaction Concept. Chapter 15: Transactions. Example of Fund Transfer. ACID Properties. Example of Fund Transfer (Cont.)

Roadmap of This Lecture

Lecture 20 Transactions

Chapter 22. Transaction Management

Advanced Databases. Transactions. Nikolaus Augsten. FB Computerwissenschaften Universität Salzburg

Chapter 14: Transactions

UNIT IV TRANSACTION MANAGEMENT

Transactions. Kathleen Durant PhD Northeastern University CS3200 Lesson 9

Transactions. Silberschatz, Korth and Sudarshan

Database Management Systems

Transaction Management

Weak Levels of Consistency

CHAPTER 3 RECOVERY & CONCURRENCY ADVANCED DATABASE SYSTEMS. Assist. Prof. Dr. Volkan TUNALI

Transaction Management. Pearson Education Limited 1995, 2005

TRANSACTION PROPERTIES

Transactions. ACID Properties of Transactions. Atomicity - all or nothing property - Fully performed or not at all

Chapter 7 (Cont.) Transaction Management and Concurrency Control

CSIT5300: Advanced Database Systems

Transaction Management & Concurrency Control. CS 377: Database Systems

T ransaction Management 4/23/2018 1

CS352 Lecture - The Transaction Concept


Database Principles: Fundamentals of Design, Implementation, and Management Tenth Edition. Chapter 13 Managing Transactions and Concurrency

Lecture 21 Concurrency Control Part 1

) Intel)(TX)memory):) Transac'onal) Synchroniza'on) Extensions)(TSX))) Transac'ons)

Foundation of Database Transaction Processing. Copyright 2012 Pearson Education, Inc.

Transaction Management

Intro to Transactions

Introduction to Transaction Management

) Intel)(TX)memory):) Transac'onal) Synchroniza'on) Extensions)(TSX))) Transac'ons)

CS352 Lecture - Concurrency

CS352 Lecture - Concurrency

UNIT-IV TRANSACTION PROCESSING CONCEPTS

Recovery System These slides are a modified version of the slides of the book Database System Concepts (Chapter 17), 5th Ed McGraw-Hill by

CPS352 Lecture - The Transaction Concept

Transaction Management

Concurrency Control & Recovery

) Intel)(TX)memory):) Transac'onal) Synchroniza'on) Extensions)(TSX))) Transac'ons)

) Intel)(TX)memory):) Transac'onal) Synchroniza'on) Extensions)(TSX))) Transac'ons)

Transaction Management. Chapter 14

XI. Transactions CS Computer App in Business: Databases. Lecture Topics

Recoverability. Kathleen Durant PhD CS3200

TRANSACTION PROCESSING CONCEPTS

Chapter 20 Introduction to Transaction Processing Concepts and Theory

Transaction Management: Concurrency Control

What are Transactions? Transaction Management: Introduction (Chap. 16) Major Example: the web app. Concurrent Execution. Web app in execution (CS636)

Lock-based Concurrency Control

Database Tuning and Physical Design: Execution of Transactions

CS122 Lecture 15 Winter Term,

Transaction Management: Introduction (Chap. 16)

Chapter 13 : Concurrency Control

Introduction to Transaction Processing Concepts and Theory

Copyright 2007 Ramez Elmasri and Shamkant B. Navathe. Slide 17-1

Concurrency Control & Recovery

Databases - Transactions

Security Mechanisms I. Key Slide. Key Slide. Security Mechanisms III. Security Mechanisms II

Introduction. Storage Failure Recovery Logging Undo Logging Redo Logging ARIES

Lecture 13 Concurrency Control

Intro to Transaction Management

Overview of Transaction Management

Chapter 15 : Concurrency Control

Concurrency Control. Transaction Management. Lost Update Problem. Need for Concurrency Control. Concurrency control

In This Lecture. Transactions and Recovery. Transactions. Transactions. Isolation and Durability. Atomicity and Consistency. Transactions Recovery

Overview. Introduction to Transaction Management ACID. Transactions

Transaction Processing Concepts and Theory. Truong Tuan Anh CSE-HCMUT

Problems Caused by Failures

Transaction Processing: Basics - Transactions

UNIT 5. Failure Classification. Recovery Techniques. UNIT V Crash Recovery

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe

DB2 Lecture 10 Concurrency Control

CSE 444: Database Internals. Lectures Transactions

Advances in Data Management Transaction Management A.Poulovassilis

Transaction Processing. Introduction to Databases CompSci 316 Fall 2018

Schedule. Today: Feb. 21 (TH) Feb. 28 (TH) Feb. 26 (T) Mar. 5 (T) Read Sections , Project Part 6 due.

CSE 444: Database Internals. Lectures 13 Transaction Schedules

Transcription:

DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI Department of Computer Science and Engineering CS6302- DATABASE MANAGEMENT SYSTEMS Anna University 2 & 16 Mark Questions & Answers Year / Semester: II / III Regulation: 2013 Academic year: 2017-2018

UNIT-III TRANSACTION PROCESSING AND CONCURRENCY CONTROL Part - A 1. What is transaction? (A/M 10) Transaction is a collection of operations that form a single logical unit of work. During the transaction in execution, the database may be inconsistent. When the transaction is committed, the database must be consistent. 2. List out the SQL statements used for transaction control. (N/D 11) The SQL standard specifies that a transaction begin implicitly. Transactions are ended by one of these SQL statements: a. Commit work commits the current transaction and begins a new one b. Rollback work causes the current transaction to abort 3. What is a transaction rolled back? Any changes that the aborted transaction made to the database must be undone. Once the changes caused by an aborted transaction have been undone, then the transaction has been rolled back. 4. What are the states of a transaction? The states of transaction are: a. active b. partially committed c. failed d aborted e committed f terminated 5. Define ACID Properties (A/M 10) ACID properties can be defined to ensure integrity of the data in the database system that maintains the following properties of the transactions: a. Atomicity: Either all operations of the transaction are reflected properly in the database, or none. b. Consistency: Execution of a transaction in isolation [that is, with no other transaction executing concurrently] preserves the consistency of the database. c. Isolation: Even though multiple transactions may execute concurrently, the system guarantees that, for every pair of transactions Ti and Tj, it appears to Ti that either Tj finished execution before Ti started, or Tjstarted execution after Ti finished. d. Durability: After a transaction completes successfully, the changes it has made to the database persist, even if there are system failures. 6. What are the properties of transaction? The properties of transactions are a. Atomicity b. Consistency c. Isolation

d. Durability 7. Write the two commonly used concurrency control techniques. (N/D 11) Commonly used concurrency control techniques are: a. Two-Phase locking b. Concurrency control based on Timestamp ordering c. Multi-version Concurrency Control techniques d. Lock Compatibility Matrix e. Lock Granularity 8. Give the reasons for allowing concurrency. The reasons for allowing concurrency are that if the transactions run serially, a short transaction may have to wait for a preceding long transaction to complete, which can lead to unpredictable delays in running a transaction. So the concurrent execution reduces the unpredictable delays in running transactions. 9. What are the three kinds of intent locks? (N/D 10) The three kinds of intent locks are: a. Intent share b. Intent exclusive c. Share with intent exclusive 10. What are two pitfalls of lock-based protocols? (M/J 11) The two pitfalls of lock-based protocols are: a. Deadlock b. Starvation 11. Define Lock Lock is a variable associated with a data item that describes the status of the item with respect to possible operations that can applied to it. One lock with each data item. The lock is used to synchronize the access to the data item. 12. What are the different modes of lock? The different modes of lock are: a. shared b. exclusive Read_locked (shared lock): the item is locked for read purpose and can be shared for reading by another transaction. Write_locked (exclusive lock): the item is locked for write purpose and cannot be accessed by another transaction. 13. What are the advantages of two phase locking protocol? (M/J 12) The advantages of two phase locking protocol are: produces only cascade less schedules Recovery is very easy

14. What are the phases of two Phase locking protocol? The phases of two phase locking protocol are, Growing phase: A transaction may obtain locks but not release any lock and Shrinking phase: A transaction may release locks but may not obtain any new locks 15. What are the two types of serializability? The two types of serializability is conflict serializability view serializability 16. Define Deadlock Neither of the transaction can ever proceed with its normal execution. This situation is called deadlock. 17. What are the two methods for dealing deadlock problem? The two methods for dealing deadlock problem are, a. Deadlock detection b. Deadlock recovery

PART B(16Marks) 1. How can you implement atomicity in transactions? Explain. (A/M 10) (8 Marks) The recovery-management component of a database system implements the support for atomicity and durability. The shadow-database scheme: 1.Assume that only one transaction is active at a time.a pointer called db pointer always points to the current consistent copy of the database. 2.All updates are made on a shadow copy of the database, and db pointer is made to point to the updated shadow copy only after the transaction reaches partial commit and all updated pages have been flushed to disk. 3.In case transaction fails, old consistent copy pointed to by db pointer can be used, and the shadow copy can be deleted. Assumes disks do not fail Useful for text editors, but extremely inefficient for large databases: Executing a single transaction requires copying the entire database. 2. Describe the concept of serilalizability with suitable example. (A/M 10, M/J 11) (8 Marks) The concept of serilalizability: 1. Each transaction preserves database consistency. 2. Thus serial execution of a set of transactions preserves database consistency 3.A (possibly concurrent) schedule is serializable if it is equivalent to a serial schedule. Different forms of schedule equivalence give rise to the notions of: 1. Conflict Serializability 2.View Serializability Test for Conflict Serializability A schedule is conflict serializable if and only if its precedence graph is acyclic. Cycle-detection algorithms exist which take order n2 time, where n is the number of vertices in the graph. If precedence graph is acyclic, the serializability order can be obtained by a

topological sorting of the graph. This is a linear order consistent with the partial order of the graph. For example, a Serializability order for Schedule A would be T5->T1->T3->T2->T4. 3. How concurrency is performed? Explain the protocol that is used to maintain the concurrency concept. (A/M 10) (16 Marks) They are multiple transactions that are allowed to run currently in the system Advantages of concurrent executions 1.Increased processor and disk utilization, leading to better transaction throughput: one transaction can be using the CPU while another is reading from or writing to the disk. 2.Reduced average response time for transactions: short transactions need not wait behind long ones. Concurrency control schemes: They are mechanisms to control the interaction among the concurrent transactions in order to prevent them from destroying the consistency of the database. Schedules Schedules are sequences that indicate the chronological order in which instructions of concurrent transactions are executed. 1.A schedule for a set of transactions must consist of all instructions of those Transactions 2.Must preserve the order in which the instructions appear in each individual transaction. Example Schedules Let T1 transfer $50 from A to B, and T2 transfer 10% of the Balance from A to B. The following is a Serial Schedule in which T1 is followed by T2.

Let T1 and T2 be the transactions defined previously. The schedule 2 is not a serial schedule,but it is equivalent to Schedule 1.In both Schedules 1 and 3, the sum A+ B is preserved. In both Schedules 1 and 3, the sum A+ B is preserved. The Schedule in Fig-3 does not preserve the value of the sum A+ B. Recoverability Recoverable schedule if a transaction Tj reads a data items previously written by a transaction Ti, the commit operation of Ti appears before the commit operation of Tj. The following schedule (Schedule 11) is not recoverable

1.If T9 commits immediately after the read 2.If T8 should abort, T9 would have read (and possibly shown to the user) an inconsistent database state. Hence database must ensure that schedules are recoverable. Cascading rollback: Definition: If a single transaction failure leads to a series of transaction rollbacks, It is called as cascaded rollback. Consider the following schedule where none of the transactions has yet committed 1. If T10 fails, T11 and T12 must also be rolled back. 2. Can lead to the undoing of a significant amount of work Cascade less schedules: The cascading rollbacks cannot occur; for each pair of transactions Ti and Tj such that Tj reads a data item previously written by Ti, the commit operation of Ti appears before the read operation of Tj. 1. Every cascade less schedule is also recoverable 2. It is desirable to restrict the schedules to those that are cascade less. 4. Explain Two-phase locking protocol with an example. (M/J 11, N/D 11) (8 Marks) The Two-Phase Locking Protocol Introduction This is a protocol, which ensures conflict-serializable schedules. Phase 1: Growing Phase Transaction may obtain locks. Transaction may not release locks. Phase 2: Shrinking Phase Transaction may release locks. Transaction may not obtain locks. The protocol assures serializability. It can be proved that the transactions can be serialized in the order of their lock points. Lock points: It is the point where a transaction acquired its final lock. Two-phase locking does not ensure freedom from deadlocks Cascading rollback is possible under two-phase locking. There can be conflict serializable schedules that cannot be obtained if

two-phase locking is used. Given a transaction Ti that does not follow two-phase locking, we can find a transaction Tj that uses two-phase locking, and a schedule for Ti and Tj that is not conflict serializable. Lock Conversions Two-phase locking with lock conversions: First Phase: _ can acquire a lock-s on item _ can acquire a lock-x on item _ can convert a lock-s to a lock-x (upgrade) Second Phase: _ can release a lock-s _ can release a lock-x _ can convert a lock-x to a lock-s (downgrade) This protocol assures serializability. But still relies on the programmer to insert the various locking instructions. Automatic Acquisition of Lock A transaction Ti issues the standard read/write instruction, without explicit locking calls. The operation read( D) is processed as if Ti has a lock on D then read( D) else begin if necessary wait until no other transaction has a lock-x on D grant Ti a lock-s on D; read( D) end; write( D) is processed as: if Ti has a lock-x on D then write( D) else begin if necessary wait until no other trans. has any lock on D, if Ti has a lock-s on D then upgrade lock on Dto lock-x

else grant Ti a lock-x on D write( D) end;all locks are released after commit or abort. 5. Briefly explain transaction recovery with primitive operations. (N/D 10) (6 Marks) Recoverability Recoverable schedule if a transaction Tj reads a data items previously written by a transaction Ti, the commit operation of Ti appears before the commit operation of Tj. The following schedule (Schedule 11) is not recoverable 1.If T9 commits immediately after the read 2.If T8 should abort, T9 would have read (and possibly shown to the user) an inconsistent database state. Hence database must ensure that schedules are recoverable. Cascading rollback: Definition: If a single transaction failure leads to a series of transaction rollbacks, It is called as cascaded rollback. Consider the following schedule where none of the transactions has yet committed 1.If T10 fails, T11 and T12 must also be rolled back. 2. Can lead to the undoing of a significant amount of work Cascade less schedules: The cascading rollbacks cannot occur; for each pair of transactions Ti and Tj such that Tj reads a data item previously written by Ti, the commit operation of Ti appears before the read operation of Tj. 1.Every cascade less schedule is also recoverable 2.It is desirable to restrict the schedules to those that are cascade less. 6. Discuss the ACID properties of a transaction. Give relevant example. (N/D 11) (8 Marks) ACID Properties To preserve the integrity of data, the database system must ensure: Atomicity. Either all operations of the transaction are properly reflected in the database or none are.

Consistency. Execution of a transaction in isolation preserves the consistency of the database. Isolation. Although multiple transactions may execute concurrently, each transaction must be unaware of other concurrently executing transactions. Intermediate transaction results must be hidden from other concurrently executed transactions. That is, for every pair of transactions Ti and Tj, it appears to Ti that either Tj finished execution before Ti started, or Tj started execution after Ti finished. Durability. After a transaction completes successfully, the changes it has made to the database persist, even if there are system failures. 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) Consistency requirement the sum of A and B is unchanged by the execution of the transaction. Atomicity requirement if the transaction fails after step 3 and before step 6, the system should ensure that its updates are not reflected in the database, else an inconsistency will result. 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 despite failures. Isolation requirement if between steps 3 and 6, another transaction 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). Example of Supplier Number Transaction : logical unit of work e.g change supplier number for Sx to Sy; The following transaction code must be written: TransX: Proc Options (main); /* declarations omitted */ EXEC SQL WHEREVER SQL-ERROR ROLLBACK; GET LIST (SX, SY); EXEC SQL UPDATE S SET S# =: SY WHERE S# = SX;

EXEC SQL UPDATE SP SET S# =: SY WHERE S# = SX; EXEC SQL COMMIT RETURN (); ACID properties 1.Atomicity - all or nothing, transaction is an indivisible unit that is either performed in its entirety or not at all 2. Consistency - a transaction must transform the database from one consistent state to another. 3. Isolation - transactions execute independently of one another. partial effects of incomplete transactions should not be visible to other transactions 4. Durability - effects of a successfully completed (committed) transaction are stored in DB and not lost because of failure. 7. Discuss in detail about transaction recovery, system recovery and media recovery. (M/J 12) (16 Marks) Instance Recovery 1.Oracle physically updates data using LRU algorithm 2. State of database at failure time is complex. 3. Results of committed tx. stored on disc 4. Results of committed tx. stored in memory buffers 5. Results of UNcommitted tx. stored on disc 6. Results of UNcommitted tx. stored in memory buffers System Recovery 1.Failures can leave database in a corrupted or inconsistent state weakening Consistency and Durability features of transaction processing. 2.Oracle level of failures: statement: causes relevant tx. to be rolled back - database returns to previous state releasing resources process: abnormal disconnection form session, rolled back...etc. instance: crash in DBMS software, operating system, or hardware - DBA issues a SHUTDOWN ABORT command which triggers off instance recover procedures. media failure: disk head crash, worst case = destroyed database and log files. Previous backup version must be restored from another disk. Data Replication. Consequently: 1.SHUTDOWN trashes the memory buffers - recovery used disk data and:

2. ROLLS FORWARD: re-apply committed tx. on log which holds before/after images of updated rec. 3. ROLLBACK uncommitted tx. already written to database using rollback segments. Media Recovery 1. Disk failure - recover from backup tape using Oracle EXPORT/IMPORT 2. Necessary to also backup log files and control files to tape 3. DBA decide to keep complete log archives which are costly in terms of: 1.Time 2. Space 3. Administrative overheads OR 1. Cost of manual re-entry 2. Log archiving provides the power to do on-line backups without shutting down the system, and full automatic recovery. It is obviously a necessary option for operationally critical database applications. 8. Explain about immediate update and deferred update recovery techniques. (M/J 2011) (8 Marks) Deferred Update 1. No physical updates to db until after a transaction commits. 2. During the commit, log records are made then changes are made permanent on disk. 3. What if a Transaction fails? 4.No UNDO required 5.REDO may be necessary if the changes have not yet been made permanent before the failure. Immediate Update 1.Physical updates to db may happen before a transaction commits. 2. All changes are written to the permanent log (on disk) before changes are made to the DB. 3. What if a Transaction fails? 4.After changes are made but before commit need to UNDO the changes

5.REDO may be necessary if the changes have not yet been made permanent before the failure.