Docsity

Transaction Management: Ensuring Atomicity and Concurrency Control in Databases, Slides of Database Management Systems (DBMS)

Partial preview of the text

Download Transaction Management: Ensuring Atomicity and Concurrency Control in Databases and more Slides Database Management Systems (DBMS) in PDF only on Docsity!

Query Processing and Query

Optmization

Transaction Management

Until now, our concept of database has been one in

which programs accessing the database are run one

at a time (serially). Often this is indeed the case.

However, there are also numerous applications in

which more than one program, or different

executions of the same program, run simultaneously

(concurrently). This is where TRANSACTION

MANAGEMENT comes in handy

Example #

Statistical database, such as census data, where

many people may be querying the database at

once. Here, as long as no one is changing the

data, we do not really care in what order the

processes read data. We can let the operating

system schedule simultaneous read requests.

Here we want to allow maximum concurrent

operations, so time can be saved

SPEED

Important Terms

Serializable schedule -- is a linear

arrangement of the database calls from several

transactions with the property: the final

database state obtained by executing the calls

in schedule order is the same as the obtained

by running the transactions in some

unspecified serial order

Important Terms (cont…)

Two-phase locking protocol -- is a discipline

that transactions can use to ensure serializability.

The first phase is characterized by the monotonic

acquisition of new locks or the strengthening of

existing locks. The second phase involves the

monotonic downgrade or release of existing locks.

This lock is the most important technique for

managing concurrency.

Important Terms (cont…)

Strict two-phase locking protocol --

each transaction holds all its locks until it

commits or rolls back. When the commit or

rollback is secure, it releases all the locks. In

other words, the shrinking phase occurs all at

once, immediately after the transaction

terminates.

Important Terms (cont…)

Transaction -- is simply a single execution of a

program. This program may be a simple query expressed in one of the query languages or an elaborate host language program with embedded calls to a query language. Several independent executions of the same program may be in progress simultaneously; each is a different transaction

Main Idea

To a large extent, transaction management can be seen as an attempt to make complex operations appear atomic. That is, they either occur in their entirety or do not occur at all, and if they occur, nothing else apparently went on during the time of their occurrence. The normal approach to ensuring atomicity of transactions is ‘serialization’, which forces transactions to run concurrently in a way that makes it appear that they ran one-at-a-time (serially).

Items

To manage concurrency, the database must be

partitioned into items, which are the units of

data to which access is controlled. The nature

and size of items are for the system designer

to choose. In the relational model of data, for

example, we could choose large items, like

relations, or small items like individual tuples

or even components of tuples.

Locks

The most common way in which access to items is controlled is by “locks.” Lock manager is the part of a DBMS that records, for each item I, whether one or more transactions are reading or writing any part of I. If so, the manager will forbid another transaction from gaining access to I, provided the type of access (read or write) could cause a conflict, such as the duplicate selling of an airline seat.

Example of locks

Lets consider two transaction T1 and T2. Each

accesses an item A, which we assume has an

integer value, and adds one to A.

Read A;A:=A+1;Write A;

T1: Read A A:=A+1 Write A

T2: Read A A:=A+1 Write A

Example of locks (cont…)

The most common solution to this problem is to provide a lock on A. Before reading A, a transaction T must lock A, which prevents another transaction from accessing A until T is finished with A. Furthermore, the need for T to set a lock on A prevents T from accessing A if some other transaction is already using A. T must wait until the other transaction unlocks A, which it should do only after finishing with A.