Week 8 L1 Flashcards
What do we mean by transactions
A transaction is a logical unit of work.
A transaction consists of the execution of an application-specified sequence of operations.
e.g., SELECY, INSERT, UPDATE, DELETE
What do we mean by commit/roll protocol?
atomicity is implemented by the commit/rollback protocol.
User must define boundaries of a transaction.
Begin : START TRANSACTION
Make permanent changes: COMMIT
Undo transaction : ROLLBACK
What are log files?
Keep track of database transactions.
Contain information about all changes to a database.
These support the commit/rollback protocol.
What do log files contain ?
Before-image of a data item, i.e., value before change
After-image of a data item. i.e., value after change
Lots of other information- e.g. timestamps etc
How do commits and rollback use log files
ROLLBACK uses before image values backwards.
Commit uses after image values forward.
What do we mean by concurrency control?
The process of managing simultaneous transactions without on interfering with one another.
Concurrency allows much more efficient use of resources, resulting in improved database performance.
What are the problems with concurrency?
Concurrent access can cause interference and result in data inconsistencies.
Lost update- more than one transaction trying to update the same data.
Uncommitted dependency
Inconsistent analysis
What do we mean by serialisation?
If transactions were only allowed to execute in series, then these concurrency problems would not exist.
The serialisation principle:
When two transactions operate in a parallel interleaved manner, then their effects should be the same as if they operated in a purely serial manner.
How do we guarantee serialisability?
We use the two-phase locking protocol.
What is a transaction lock
A transaction lock on data can prevent access to other transactions to prevent incorrect results.
transaction lock two types?
Shared read lock (S-lock)- shared reading but not writing.
Exclusive write lock(X-lock)- exclusive access
A transaction may have to wait for a lock to be released until placing its own lock on the data item.
What Do COMMIT AND ROLLBACK do to locks?
They release them.
What do we mean by Two phase locking (and what are they)?
All locking operations must precede the first unlock operation in the transaction.
There are two phases:
Growing phase- acquires all locks.
Shrinking phase – releases all locks but acquires none.
What does the lost update solution cause?
A deadlock
How to solve deadlock ?
This is when two or more transactions are in a simultaneous wait state, each waiting for locks held by the other to be released.
Breaking the deadlock involves the lock manager, choosing one of the transactions and rolling it back – these releases its locks and allows the other transaction to proceed
Some systems will then re-execute the rolled back transaction.