TRANSACTIONS Flashcards
What is a transaction? Give Examples
A sequence of one or more operations (reads or writes) which reflects a single real-world transition.
It is a logical unit of work in the database, that must be completed in its entirety to ensure correctness.
Transfer money between accounts
Purchase a group of products
Register for a class (either waitlist or allocated)
What are read_items and write_items?
A transaction includes read _item and write_ item operations to access and update the database. Read _item(X) Reads a database item named X into a program variable write_ item(X). Writes the value of program variable X into the database item named X.
What are the possible outcomes of a transaction?
If it completes successfully, the transaction is said to have committed and the database reaches a new consistent state.
On the other hand, if the transaction does not execute successfully, the transaction is aborted
What is the most important requirement of a transaction?
A transaction should always transform the database from one consistent state to another.
What happens when a transaction is aborted?
If a transaction is aborted, the database must be restored to the consistent state it was in before the transaction started. Such a transaction is rolled back or undone.
A committed transaction cannot be aborted
What happens in a committed transaction is considered to be a mistake
If we decide that the committed transaction was a mistake, we must perform another compensating transaction to reverse its effects
What operations does the recovery manager of the DBMS track?
BEGIN_TRANSACTION This marks the beginning of transaction execution.
READ or WRITE These specify read or write operations on the database items that are executed as part of a transaction
END_TRANSACTION. This specifies that READ and WRITE transaction operations have ended and marks the end of transaction execution.
COMMIT_ TRANSACTION. This signals a successful end of the transaction so that any changes (updates) executed by the transaction can be safely committed to the database and will not be undone.
ROLLBACK (or ABORT). This signals that the transaction has ended unsuccessfully, so that any changes or effects that the transaction may have applied to the database must be undone.
Describe the state transition diagram of a transaction
*See doc for pic
A transaction goes into an active state immediately after it starts execution, where it can execute its READ and WRITE operations.
When the transaction ends, it moves to the partially committed state. At this point, some recovery protocols need to ensure that a system failure will not result in an inability to record the changes of the transaction permanently ( by recording changes in the system log)
Once this check is successful, the transaction is said to have reached its commit point and enters the committed state.
When a transaction is committed, it has concluded its execution successfully and all its changes must be recorded permanently in the database, even if a system failure occurs
A transaction can go to the failed state if one of the checks fails or if the transaction is aborted during its active state.
The transaction may then have to be rolled back to undo the effect of its WRITE operations on the database.
Failed or aborted transactions may be restarted later—either automatically or after being resubmitted by the user—as brand new transactions
What are the benefits of grouping user actions into transactions?
Recovery & Durability: Keeping the DBMS data consistent and durable in the face of crashes, aborts, system shutdowns, etc. (Resilience to system failures)
Concurrency: Achieving better performance by parallelizing transactions without creating anomalies
What properties should all transactions posses?
Atomicity Consistency Isolation Durability ACID
Describe Atomicity
-All or nothing property
-A transaction is an indivisible unit that is either performed in its entirety or is not performed at all.
-It is the responsibility of the recovery subsystem of DBMS to ensure atomicity
-DBMS logs all actions so that it can undo the actions of an aborted transaction(logging mechanism)
An example of an atomic transaction is a monetary transfer from bank account A to account B. It consists of two operations, withdrawing the money from account A and saving it to account B. Performing these operations in an atomic transaction ensures that the database remains in a consistent state, that is, money is neither lost nor created if either of those two operations fail
Describe Consistency
A transaction must transform the database from one consistent state to another consistent state.
It moves from one consistent state of integrity to another.
It is the responsibility of both the DBMS and application developers to ensure consistency by enforcing all constraints
-Managing constraints ensures consistency
For example, a column in a database may only have the values for a coin flip as “heads” or “tails.” If a user were to attempt to put in “sideways,” consistency rules for the database would not allow it.
Describe Isolation
A transaction is isolated from the effects of other concurrent transactions.
Transactions execute independently of one another.
Effects of a transaction is the same as one running after another.
Partial effects of incomplete transactions should not be visible to other transactions.
-Isolation is ensured through serializability and locking
EG .If Joe issues a database transaction at the same time that Mary issues a different transaction, both transactions should operate on the database in an isolated manner. The database should either perform Joe’s entire transaction before executing Mary’s or vice-versa.
Describe durability
The effects of a successfully completed (committed) transaction are permanently recorded in the database and must not be lost because of subsequent failure.
Durability is ensured through logging mechanism
For example, if a flight booking reports that a seat has successfully been booked, then the seat will remain booked even if the system crashes.
Give four examples of a transaction processing system
A transaction processing system is a computerized system that performs and records the daily routine transactions necessary to conduct business. Examples are sales order entry, hotel reservation systems, payroll, employee record keeping, and shipping.