Transaction DBMS
Transaction DBMS
Definition of Transaction
A transaction is a sequence of one or more operations (such as read, write,
update, or delete) that are executed as a single unit of work on a database. It
represents a single, logical unit of processing in a database management system
(DBMS).
For example, transferring money from one bank account to another might involve
these steps:
1. Read the balance of the source account
2. Deduct the amount from the source account
3. Read the balance of the destination account
4. Add the amount to the destination account
5. Save both updated balances
ACID Properties
ACID is an acronym that stands for Atomicity, Consistency, Isolation, and
Durability. These properties ensure that database transactions are processed
reliably.
1. Atomicity- Atomicity guarantees that each transaction is treated as a single,
indivisible unit, which either succeeds completely or fails completely.
- If any part of the transaction fails, the entire transaction fails, and the database is
left unchanged.
- If the transaction succeeds, all changes are committed to the database at once.
Example: In a money transfer, if the deduction from the source account succeeds
but the addition to the destination account fails, the entire transaction is rolled
back, leaving both accounts unchanged.
Example: If two people try to book the last seat on a flight simultaneously,
isolation ensures that only one booking succeeds while the other fails, as if they
had occurred one after the other.
4. Durability- Durability guarantees that once a transaction has been committed,
it will remain committed even in the case of system failure (e.g., power outage or
crash).
- Committed data is saved by the system in a way that even if there's a system
failure and the database restarts, the changes made by committed transactions
will persist.
- This is typically implemented using transaction logs that allow the recreation of
the committed transactions.
Transaction-Processing
1. Transaction-Processing Monitors
These are software systems that manage transactions in distributed
environments. They coordinate communication between clients and servers,
manage resource allocation, and ensure transaction properties (ACID: Atomicity,
Consistency, Isolation, Durability) are maintained across multiple systems.
Transaction-processing (TP) monitors are middleware systems that manage
transactions across multiple resources in a distributed environment. They ensure
that transactions maintain ACID properties across different systems.
2. Transactional Workflows
These are sequences of tasks or activities that form a complete business process,
where each step is treated as a transaction. They ensure that complex, multi-step
processes maintain data integrity and consistency, even if interrupted.
Transactional workflows manage complex business processes as a series of
interconnected transactions, ensuring data consistency across multiple steps.
Each step is a separate transaction, but the workflow ensures that all steps are
completed successfully or the entire process is rolled back.
3. Main-Memory Databases
These are database management systems that primarily rely on main memory
(RAM) for data storage, as opposed to traditional disk-based systems. They offer
significantly faster data access and processing, making them suitable for
applications requiring high-speed transactions.
Main-memory databases (MMDBs) store data primarily in RAM for faster access
and processing.
MMDBs like Redis or MemSQL are often used for caching, session management,
and real-time analytics where speed is crucial.
5. Long-Duration Transactions
These are transactions that run for extended periods, sometimes hours or days.
They pose challenges to traditional transaction management techniques and often
require special handling to maintain system performance and data consistency.
These are transactions that run for extended periods, challenging traditional
transaction management techniques.
Challenges:
- Maintaining locks for extended periods is impractical
- Higher risk of conflicts with other transactions
- Need for compensating transactions if a long-running transaction fails
Challenges:
1. Maintaining global consistency
2. Handling different transaction protocols
3. Dealing with autonomy of individual databases
Concurrency Control
Concurrency control is the process of managing and coordinating multiple
concurrent transactions to prevent data corruption and ensure the ACID
properties of transactions.
Types of locks:
-Shared (Read) Lock: Allows multiple transactions to read the same data item.
Exclusive (Write) Lock: Allows only one transaction to read and write a data item.
Locking protocols:
- **Two-Phase Locking (2PL)**: Transactions first obtain all necessary locks
(growing phase) and then release them (shrinking phase).
- **Strict Two-Phase Locking (Strict 2PL)**: Locks are held until the end of the
transaction.