This document discusses transaction management and concurrency control in database systems. It defines transactions and their key properties including atomicity, consistency, isolation, and durability. It describes concurrency control and problems that can arise from concurrent transactions like lost updates, uncommitted data, and inconsistent retrievals. It presents different concurrency control techniques including locking methods, timestamping methods, and optimistic methods. It also discusses transaction recovery management and concepts that affect transaction recovery.
Download as PPTX, PDF, TXT or read online on Scribd
100%(1)100% found this document useful (1 vote)
183 views
Advanced Database Technology: Ambo University
This document discusses transaction management and concurrency control in database systems. It defines transactions and their key properties including atomicity, consistency, isolation, and durability. It describes concurrency control and problems that can arise from concurrent transactions like lost updates, uncommitted data, and inconsistent retrievals. It presents different concurrency control techniques including locking methods, timestamping methods, and optimistic methods. It also discusses transaction recovery management and concepts that affect transaction recovery.
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 28
Ambo University
Hachalu Hundessa Technology Campus
Department of IT (MSc Program)
Advanced Database Technology
Prepared by: Mikeyas Meseret &
Kenna Seboka Transaction Management & Concurrency Control Outline About database transactions and their properties What concurrency control is what role it plays What locking method are and how they work How stamping method are used for concurrency control How optimistic method are used for concurrency control How database recovery management is used to maintain data integrity What is Transaction? • Transactions reflect real-world transactions that are triggered by events. • Transaction use to prevent data integrity problems. • In database terms, a transaction is any action that reads from or writes to a database. • It is a logical unit of work that must be entirely completed or entirely aborted. Transaction … • Most real-world database transactions are formed by two or more database requests. • A database request is the equivalent of a single SQL statement in an application program or transaction. • A transaction in SQL may consist of a: SELECT statement UPDATE statements INSERT statements & Combination of these statements Transaction Properties Atomicity: All operations (SQL requests) of a transaction be completed or aborted. Consistency: It indicates the permanence of the database’s consistent state . Isolation: Data used during transaction cannot be used by second transaction until the first is completed. Transaction Properties … Durability: Ensures that once transactions are committed, they cannot be undone or lost. Serializability: It ensures that the schedule for
the concurrent execution of the
transactions yields consistent results. Transaction Management with SQL • ANSI has defined standards that govern SQL database transactions. • Transaction support is provided by two SQL statements: COMMIT - automatically ends the SQL transaction. ROLLBACK - database is rolled back to its previous consistent state. Transaction Mng’t … Transaction sequence must continue until: COMMIT statement is reached. ROLLBACK statement is reached. End of program is reached. Program is abnormally terminated. Transaction Log • Keeps track of all transactions that update the database. • DBMS uses the information stored in a log for: Recovery requirement triggered by a ROLLBACK statement. The ending (COMMIT) of the transaction. The type of operation being performed. A system failure. Concurrency Control • When many transactions take place at the same time, they are called concurrent transactions. • Managing the execution of such transactions is called concurrency control. • The objective is to ensures Serializability of transactions in a multiuser database environment Problems in Concurrency Control The three main problems are: lost updates: • it occurs when two concurrent transactions, are updating the same data element and one of the updates is lost. uncommitted data: • occurs when two transactions, two transaction are executed concurrently. • first transaction is rolled back after the second transaction has already accessed the uncommitted data. Problems in Concurrency … Inconsistent retrievals: • Occurs when a transaction accesses data before and after one or more other transactions finish working with such data. The Scheduler Special DBMS program • Purpose is to establish order of operations within which concurrent transactions are executed. Interleaves execution of database operations: • Ensures Serializability • Ensures isolation Serializable schedule • Interleaved execution of transactions yields same results as serial execution. Concurrency Control with Locking Methods
• It Facilitates isolation of data items used in
concurrently executing transactions. Lock: Guarantees exclusive use of a data item to a current transaction. Pessimistic locking: Use of locks based on the assumption that conflict between transactions is likely to occur. Locking Methods … Lock manager: Responsible for assigning and policing the locks used by the transactions. Lock Granularity: indicates the level of lock use. Levels of locking: Locking can take place at the following levels. Database-level lock: transactions T1 and T2
cannot access the same database concurrently
even when they use different tables. Locking Methods … Table-level lock: • The two transactions can access the same database as long as they access different tables. Page-level lock: • A diskpage, or page, is the equivalent of a diskblock, which can be described as a directly addressable section of a disk. Locking Methods … Row-level lock: • This approach improves the availability of data, its management requires high overhead. Field-level lock: • It allows concurrent transactions to access the same row as long as they require the use of different fields within that row. Lock Types The DBMS may use different lock types: Binary lock: • Has two states, locked (1) and unlocked (0) Exclusive lock: • Access is specifically reserved for transaction that locked object • Must be used when potential for conflict exists Shared lock: • Concurrent transactions are granted read access on basis of a common lock Two major problems with Locking • The resulting transaction schedule might not be serializable. • The schedule might create deadlocks. Two-Phase Locking (2PL) • Defines how transactions acquire and relinquish locks. The two phases are: Growing phase: • Transaction acquires all required locks without unlocking any data Shrinking phase: • Transaction releases all locks and cannot obtain any new lock Deadlocks • Condition that occurs when two transactions wait for each other to unlock data • Possible only if one of the transactions wants to obtain an exclusive lock on a data item No deadlock condition can exist among shared locks • Three techniques to control deadlock: Prevention Detection Avoidance Time Stamping Methods • Assigns global unique time stamp to each transaction • Produces explicit order in which transactions are submitted to DBMS • Time stamps must have two properties: Uniqueness: Ensures that no equal time stamp values can exist Monotonicity: Ensures that time stamp values always increase Wait/Die and Wound/Wait Schemes Wait/die • Older transaction waits and younger is rolled back and rescheduled. Wound/wait • Older transaction rolls back younger transaction and reschedules it. Younger transaction waits for the older. Optimistic Methods Optimistic approach: • Based on the assumption that the majority of database operations do not conflict • Does not require locking or time stamping techniques • Transaction is executed without restrictions until it is committed Phases of Optimistic Approach Read: Transaction: Reads the database & Executes the needed computations Makes the updates to a private copy of the database values Validation: Transaction is validated to ensure that the changes made will not affect the integrity and consistency of the database. Write: Changes are permanently applied to the database Database Recovery Management • Restores database from a given state to a previously consistent state • Recovery transactions are based on the atomic transaction property • Atomic transaction property: All portions of a transaction must be treated as a single logical unit of work Concepts that Affect Transaction Recovery
Deferred-write technique or deferred update:
• Ensures that transaction logs are always written before the data are updated Redundant transaction logs: • Ensure that a physical disk failure will not impair the DBMS’s ability to recover data Buffers: Temporary storage areas in a primary memory Checkpoints: • Allows DBMS to write all its updated buffers in memory to disk Thank you for Listening!!!