8 Introduction To Transaction Processing Concepts And Theory

Database Management System ยท Unit 8 ยท 4 hrs

Introduction to Transaction Processing Concepts and Theory

Exam-focused notes for Introduction to Transaction Processing Concepts and Theory (Database Management System, CSC265): what the TU syllabus asks and how it has actually been tested, with 7 solved past questions from this unit.

Introduction to Transaction Processing Concepts and Theory in short

This unit introduces transaction processing theory: what a transaction is at the level of individual reads and writes, the properties every transaction should have, and the two formal lenses, recoverability and serializability, used to judge whether an interleaved schedule of several transactions is safe to run at all.

Introduction to Transaction Processing Concepts and Theory: notes

Introduction to Transaction Processing

A single-user system allows only one user to access the database at a time, and is comparatively simple to build (desktop operating systems such as Windows or macOS are single-user in this sense). A multi-user system allows many users to access the database concurrently, which is considerably more complex, since the DBMS must now coordinate simultaneous, potentially conflicting requests (UNIX and Linux are multi-user in this sense).

Concurrency control is the machinery that manages simultaneous execution of transactions so they do not corrupt each other's work. It is needed to enforce isolation between conflicting transactions through mutual exclusion on shared data, to resolve read-write and write-write conflicts correctly, to keep the database consistent despite many transactions executing at once, and, ultimately, to guarantee serializability (defined below), the property that lets a multi-user system be reasoned about as if transactions ran one at a time. Recovery is needed because, like any computer system, a database system is subject to failures, hardware crashes, software errors, or external events, yet the data it holds must survive them; a recovery-capable DBMS must be able to restore the database to a consistent state quickly, guaranteeing atomicity, either a transaction's effects are fully applied and committed, or the database behaves as though it never ran at all.

Transaction and System Concepts

A transaction is an executing program, or a logical unit of it, that performs one or more database access operations: retrieval, insertion, deletion or modification. A transaction is called read-only if it never updates the database, and read-write otherwise. Every access is expressed through two basic operations. read_item(X) locates the disk block holding data item $X$, copies that block into a main-memory buffer if it is not already cached, and copies $X$ from the buffer into a program variable. write_item(X) locates and buffers the block holding $X$, copies the program variable's value into the buffer's copy of $X$, and eventually flushes the updated block back to disk. The DBMS cache is the pool of in-memory buffers, each the size of one disk block, that the DBMS maintains for exactly this purpose; when every buffer is occupied and a new block must be brought in, a buffer replacement policy such as LRU (least recently used) decides which cached block to evict.

Because recovery must be able to reconstruct what happened, every transaction is tracked through a fixed sequence of states and operations: BEGIN_TRANSACTION marks the start; READ/WRITE record data access; END_TRANSACTION marks that no further reads or writes will occur; COMMIT_TRANSACTION signals a successful end, after which the transaction's updates are permanent; and ROLLBACK (or ABORT) signals an unsuccessful end, undoing every effect the transaction has had so far. Two further recovery-specific operators complete the picture: UNDO, which reverses a single operation (rather than an entire transaction, as rollback does), and REDO, which reapplies an already-committed transaction's operations to guarantee they are reflected in the database after a failure.

A transaction moves through a small set of states: it becomes active immediately on starting, executing reads and writes; on reaching its last operation it becomes partially committed; once the necessary recovery bookkeeping (writing to the log) is confirmed, it reaches its commit point and becomes committed, its effects now permanent even across a subsequent failure; alternatively, from active or partially committed, it can be aborted and rolled back, after which it is terminated.

The system log is an append-only file, kept on disk so it survives anything short of a disk crash, recording every significant event: [start_transaction, T], [read_item, T, X], [write_item, T, X, old_value, new_value], [commit, T] and [abort, T]. A transaction $T$ reaches its commit point once every one of its database operations has executed successfully and every effect has been recorded in the log; beyond that point $T$ is considered permanently committed. After a failure, the recovery process scans the log for every transaction that wrote [start_transaction, T] but never wrote a matching [commit, T]; such transactions must be rolled back (undone), while transactions that did commit can have their effects redone from the log if necessary, which is exactly why the log, not just the in-memory buffers, must survive the crash.

What this unit covers

  • Introduction to Transaction Processing
  • Transaction and System Concepts
  • Desirable Properties of Transactions
  • Characterizing Schedules Based on Recoverability
  • Characterizing Schedules Based on Serializability

Desirable Properties of Transactions

2080 ยท 5 marks

Define transaction. What are different desirable properties of transaction. [5]

A transaction is a logical unit of database processing that includes one or more database access operations (read, write, insert, delete, or update). It is a sequence of operations performed as a single logical unit of work that must either be completed entirely or not executed at all. A transact...

Open this answer on its own page โ†’

Characterizing Schedules Based on Serializability

2079 ยท 5 marks

What is conflict schedule? Explain with example. [5]

Show solved answer

Conflict Schedule

Definition

A conflict schedule (more precisely, a schedule with conflicting operations) refers to a schedule in which two or more transactions contain conflicting operations. Two operations in a schedule are said to conflict if they satisfy all three of the following conditions:

  1. They belong to different transactions.
  2. They access the same data item X.
  3. At least one of them is a write operation.

The possible conflicting pairs are:

Operation PairConflict?
Read(X) and Read(X)No
Read(X) and Write(X)Yes
Write(X) and Read(X)Yes
Write(X) and Write(X)Yes

Conflict Serializability

A schedule is called conflict serializable if it can be transformed into a serial schedule by swapping non-conflicting operations. To test this, a precedence graph (serialization graph) is constructed.

Algorithm (from notes):

  1. Look at only read_Item(X) and write_Item(X) operations.
  2. Construct a precedence graph with directed edges.
  3. Draw an edge from Ti โ†’ Tj if an operation in Ti appears before a conflicting operation in Tj.
  4. The schedule is conflict serializable if and only if the precedence graph has no cycles.

Example

Consider two transactions:

  • T1: read(X), write(X), read(Y), write(Y)
  • T2: read(X), write(X), read(Y), write(Y)

Schedule S:

StepOperation
1T1: read(X)
2T2: read(X)
3T1: write(X)
4T2: write(X)
5T1: read(Y)
6T2: read(Y)
7T1: write(Y)
8T2: write(Y)

Identifying Conflicts:

Every pair below is on the same data item, from different transactions, with at least one write, so each pair contributes an edge in the direction of the operation that comes first in the schedule.

ConflictReason
T1:read(X) at step 1 and T2:write(X) at step 4T1 reads X before T2 writes it โ†’ T1 โ†’ T2
T2:read(X) at step 2 and T1:write(X) at step 3T2 reads X before T1 writes it โ†’ T2 โ†’ T1
T1:write(X) at step 3 and T2:write(X) at step 4Both write X, T1 first โ†’ T1 โ†’ T2
T1:read(Y) at step 5 and T2:write(Y) at step 8T1 reads Y before T2 writes it โ†’ T1 โ†’ T2
T2:read(Y) at step 6 and T1:write(Y) at step 7T2 reads Y before T1 writes it โ†’ T2 โ†’ T1
T1:write(Y) at step 7 and T2:write(Y) at step 8Both write Y, T1 first โ†’ T1 โ†’ T2

Precedence Graph:

T1 ---------> T2
 ^            |
 |____________|
  • Edges run in both directions, so the graph contains a cycle (T1 โ†’ T2 โ†’ T1).
  • Therefore, Schedule S is NOT conflict serializable. Neither serial order works: T2 reads X before T1 writes it, which would put T2 first, while T1 writes X before T2 writes it, which would put T1 first.

A Conflict Serializable Schedule S1:

Interleaving the same two transactions differently gives a schedule that is conflict serializable.

StepOperation
1T1: read(X)
2T1: write(X)
3T2: read(X)
4T1: read(Y)
5T2: write(X)
6T1: write(Y)
7T2: read(Y)
8T2: write(Y)

Here every conflicting pair has the T1 operation first: read(X) of T1 before write(X) of T2, write(X) of T1 before both read(X) and write(X) of T2, read(Y) of T1 before write(Y) of T2, and write(Y) of T1 before both read(Y) and write(Y) of T2.

Precedence Graph:

T1 ---------> T2
  • There is no cycle in this precedence graph.
  • Therefore, Schedule S1 is conflict serializable, equivalent to the serial schedule T1 โ†’ T2, even though its operations are interleaved.

Example of a NON-Conflict Serializable Schedule

Schedule S2:

StepOperation
1T1: read(X)
2T2: write(X)
3T1: write(X)
4T2: read(Y)
5T1: write(Y)
6T2: write(Y)

Conflicts:

  • T2:write(X) before T1:write(X) โ†’ T2 โ†’ T1
  • T1:write(Y) before T2:write(Y) โ†’ T1 โ†’ T2

Precedence Graph:

T1 ---------> T2
 ^            |
 |____________|
  • There is a cycle (T1 โ†’ T2 โ†’ T1).
  • Therefore, Schedule S2 is NOT conflict serializable.

Summary

A conflict schedule contains conflicting operations (same data item, different transactions, at least one write). It is conflict serializable if its precedence graph contains no cycle, meaning it is equivalent to some serial execution of the transactions.

Open this answer on its own page โ†’

2078 ยท 5 marks

Define schedule and serializability. How can you test the serializability? [5]

Show solved answer

Schedule and Serializability

Schedule

A schedule (also called a history) is an ordering of the operations from a set of concurrent transactions, where the operations of each individual transaction appear in the same order as they do in that transaction. A schedule defines the interleaved execution sequence of operations (read, write, commit, abort) from multiple transactions.

Types of Schedules:

  • Serial Schedule: Transactions execute one after another with no interleaving. If there are n transactions, there are n! possible serial schedules.
  • Non-Serial (Concurrent) Schedule: Operations from multiple transactions are interleaved.

Serializability

A concurrent schedule is said to be serializable if its final result (effect on the database) is totally the same as the final result produced by some serial schedule of the same transactions. In other words, even though transactions execute concurrently with interleaved operations, the outcome must be equivalent to some sequential (serial) execution.

Serializability ensures correctness of concurrent execution while maximizing resource utilization and efficiency.

Types of Serializability

  1. Conflict Serializability: A schedule is conflict serializable if it can be transformed into a serial schedule by swapping non-conflicting operations.

  2. View Serializability: A schedule is view serializable if its view equals that of a serial schedule (no overlapping transactions). Every conflict serializable schedule is view serializable, but if a schedule contains blind writes, it may be view serializable without being conflict serializable.


Testing for Serializability (Precedence Graph Method)

The standard method to test conflict serializability uses a Precedence Graph (also called a Serialization Graph):

Algorithm:

  1. Consider only read_Item(X) and write_Item(X) operations from the schedule.

  2. Construct a Precedence Graph:

    • Nodes represent each transaction T1, T2, ..., Tn.
    • A directed edge is drawn from Ti โ†’ Tj if an operation in Ti appears before a conflicting operation in Tj.
  3. Conflicting operations occur when:

    • Two transactions access the same data item X, AND
    • At least one of them is a write operation.
    • Cases: read(X) then write(X), write(X) then read(X), write(X) then write(X).
  4. Check for cycles:

    • If the precedence graph has no cycle โ†’ the schedule is conflict serializable.
    • If the precedence graph has a cycle โ†’ the schedule is NOT serializable.

Example:

StepT1T2
1read(X)
2read(X)
3write(X)
4write(X)
  • T1 writes X before T2 writes X โ†’ edge T1 โ†’ T2
  • T1 reads X before T2 writes X โ†’ edge T1 โ†’ T2
  • T2 reads X before T1 writes X โ†’ edge T2 โ†’ T1

This creates a cycle (T1 โ†’ T2 โ†’ T1), so the schedule is NOT serializable.


Summary: Serializability is the key correctness criterion for concurrent transaction execution in DBMS. The precedence graph (no cycle = serializable) is the standard test for conflict serializability.

Open this answer on its own page โ†’

2076 ยท 5 marks

Define schedule and serializability. How can you test the serializability? [5]

Show solved answer

Schedule and Serializability

Schedule

A schedule (also called a history) is an ordering of the operations from a set of concurrent transactions, where the operations of each individual transaction appear in the same order as they do in that transaction. A schedule defines the sequence in which operations (read, write, commit, abort) from multiple transactions are interleaved and executed by the DBMS.

Example: If T1 and T2 are two transactions, a possible schedule S could be:

S: R1(X) โ†’ R2(X) โ†’ W1(X) โ†’ W2(X)

Serializability

A concurrent schedule is said to be serializable if its final result (effect on the database) is totally the same as the final result produced by some serial schedule (where transactions execute one after another without interleaving).

Since serial schedules are always considered correct (no concurrency issues), any serializable schedule is also considered correct.

There are two types of serializable schedules:

1. Conflict Serializable

A schedule is conflict serializable if it can be transformed into a serial schedule by swapping non-conflicting operations.

2. View Serializable

A schedule is called view serializable if its view equals that of a serial schedule (no overlapping transactions). A conflict serializable schedule is always view serializable, but if the schedule contains blind writes, it may be view serializable without being conflict serializable.


Testing for Serializability (Precedence Graph Method)

The most common method to test conflict serializability uses a Precedence Graph (also called a serialization graph).

Algorithm:

  1. Look at only read_Item(X) and write_Item(X) operations in the schedule.
  2. Construct a precedence graph -- a directed graph where each transaction Ti is a node.
  3. Draw a directed edge from Ti to Tj if one of the operations in Ti appears before a conflicting operation in Tj. Two operations conflict if:
    • They belong to different transactions
    • They access the same data item X
    • At least one of them is a write
  4. The schedule is conflict serializable if and only if the precedence graph has NO cycles.

Example:

Consider Schedule S with transactions T1 and T2:

S: R1(X) โ†’ W2(X) โ†’ W1(X) โ†’ R2(Y) โ†’ W2(Y)
Conflict DetectedEdge
R1(X) before W2(X)T1 โ†’ T2
W2(X) before W1(X)T2 โ†’ T1

Precedence Graph:

T1 -----> T2
T2 -----> T1   (CYCLE EXISTS)

Since a cycle exists, this schedule is NOT conflict serializable.


Summary Table

PropertyMeaning
Serial ScheduleTransactions execute one after another (always correct)
Serializable ScheduleEquivalent in result to some serial schedule
Test MethodPrecedence graph -- no cycle = serializable
Open this answer on its own page โ†’

Transaction and System Concepts

2079 ยท 5 marks

What is transaction? Draw states of transaction and explain. [5]

A transaction is an executing program or process that includes one or more database accesses such as reading or updating of database records. It is an atomic unit of work that should either be completed in its entirety or not done at all. Example: A bank transfer that debits one account and credi...

Open this answer on its own page โ†’

Characterizing Schedules Based on Recoverability

2080.1 ยท 5 marks

Explain schedule based on recoverability and serializability. [5]

A serializable schedule is a concurrent schedule whose final result is exactly the same as the result produced by some serial schedule (where transactions execute one after another without interleaving). Serializability is the standard criterion used to identify correct concurrent schedules. A se...

Open this answer on its own page โ†’

Introduction to Transaction Processing

2080.1 ยท 5 marks

Write short notes on: a. Transaction processing b. Weak entity [5]

Definition: A transaction is an executing program or process that includes one or more database access operations such as reading or updating of database records. Key Concepts: - Applications that manage transactions are generally called Online Transaction Processing (OLTP) applications. - The DB...

Open this answer on its own page โ†’