TRANSACTIONS Flashcards

1
Q

What is a transaction? Give Examples

A

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)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are read_items and write_items?

A
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.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the possible outcomes of a transaction?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the most important requirement of a transaction?

A

A transaction should always transform the database from one consistent state to another.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What happens when a transaction is aborted?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What happens in a committed transaction is considered to be a mistake

A

If we decide that the committed transaction was a mistake, we must perform another compensating transaction to reverse its effects

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What operations does the recovery manager of the DBMS track?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Describe the state transition diagram of a transaction

A

*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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are the benefits of grouping user actions into transactions?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What properties should all transactions posses?

A
Atomicity
Consistency
Isolation
Durability
ACID
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Describe Atomicity

A

-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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Describe Consistency

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Describe Isolation

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Describe durability

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Give four examples of a transaction processing system

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is a transaction anomaly?

A

When multiple transactions execute concurrently in an uncontrolled or unrestricted manner, then it might lead to several problems. These problems are commonly referred to as concurrency problems in a database environment.