Week 9 Flashcards
Single & Multi-user systems
- DBMS can be classified according to the number of users that can use a system concurrently
- Single-user systems are only accessible by one user at a time
- Typically used in PC apps
- Sqllite is a typical single user DBMS
- Single-user systems are only accessible by one user at a time
- Multi-user systems allow many users to connect and access data simultaneously
- Examples:
- Banking systems, Stock exchanges
- Web applications
- Online games
- Virtually all large systems will have a DB of some form behind the scenes
- Examples:
Transactions
- A transaction is a logical unit of database processing that includes one or more DB access operations
- Can include INSERT, DELETE, UPDATE, SELECT
- Transactions may be defined within an application program
- May also be specified interactively using SQL statements
- BEGIN TRANSACTION and END TRANSACTION statements specify transaction boundaries
- All DB operations between these statements are considered as being part of the same transaction
Transaction operations
- BEGIN transaction – marks the beginning of a transaction
- READ or WRITE – file reading/writing operations
- END transaction – marks the end of transaction execution, all read/write operations within the transaction have ended.
- At this point it may be necessary to check that changes can be permanently applied to the database or whether the changes need to be aborted.
- COMMIT transaction – Signals successful completion so that all changes can safely be permanently written to the DB
- ROLLBACK or ABORT – Signals unsuccessful completion so that all changes that have been made are undone
Transaction states
Desirable properties of transactions
- All transactions should exhibit the following properties, often called the ACID poperties
- Atomic – a transaction is an atomic unit of processing; it should be performed in it’s entirety or not at all
- Consistent - a transaction should preserve consistency, meaning if it is completely executed from beginning to end, without interference from other transaction it should take database from one consistent state to another
- Isolated – a transaction should appear as though it is being executed in isolation from other transactions, even though many transactions may be executing concurrently. No transaction should interfere with any other concurrent transactions
- Durable – The changes applied to the database by a committed transaction must persist in the database. These changers must not be lost because of any failure
ACID properties are enabled by concurrency control and recovery methods
- Concurrency control methods – provide mechanisms for ensuring that the database is kept in a consistent state throughout the execution of concurrent transactions
- Recovery methods – provide mechanisms to recover from from failed transactions and other failure states while ensuring data
consistency
Why do we need concurrency controls?
- Several problems can arise when concurrent transactions execute in an uncontrolled fashion
- The lost update problem
- The temporary update problem
- The incorrect summary problem
The lost update problem
- Two transactions that access the same database items have their operations interleaved in a way that makes the value of some database item incorrect
The temporary update problem
- One transaction updates a database item and then fails for some reason. The updated item is accessed by another transaction before it is changed back to it’s original value.
- Also known as the “dirty read” problem
The incorrect summary problem
- One transaction is calculating an aggregate summary function on a number of records while other transactions are updating some of these records
- The aggregate function may calculate some values before they are updated and others after they are updated
- A variant is the unrepeatable read problem where transaction T reads an item twice and the item is changed by another transaction T’ between the two reads
- T receives different values for two reads of the same item
Why do we need recovery?
- DBMS is responsible for ensuring that
- All operations in a transaction are completed successfully and there effect is recorded permanently in the database
- The transaction has no adverse effect on the database or any other transaction
- DBMS must not permit some operation of a transaction T to be applied to DB while other operations of T are not
- Even if transaction fails after executing some of it’s operations but not all of them
Atomicity of transactions
- Either
- A. Every instruction in transaction appears to occur
- B. None of them appear to occur
- DBMS must not allow some but not all to occur
- May happen if a failure occurs during a transaction
- Could allow inconsistencies in data
Types of failure
- System crash
- Hardware, software or network error occurs during transaction execution
- Transaction or system error
- Operation in the transaction may cause it to fail
- E.g. int overflow, division by zero
- Invalid parameter values or logical programming error
- Transaction may be interrupted by a user
- Operation in the transaction may cause it to fail
Types of failure: local errors or exceptions
- Certain conditions whose occurrence may necessitate cancellation
- E.g. data not found
- Concurrency control enforcement
- Currency control method may decide to abort transaction and restart it later because it might interfere with other transactions or because several transactions are deadlocked
- Disk failure
- Some disk blocks may lose their data because of read/write malfunction or physical disk issue, may happen during transaction operation
Types of failure: local errors or exceptions 2
- Physical problems, catastrophic failure
- Power failure
- Fire, theft, sabotage
- Human error
- System crashes, transaction errors, local errors, concurrency control enforcement are more common than disk failures or catastrophes
- For former the system must keep sufficient info to recover from failure
- For latter effective backup techniques must be in place
The system log
- Used to recover from failures
- Keeps track of all transaction operations that affect values of DB items
- This info may be needed during recovery
- Log is kept on disk
- Not affected by any type of failure except media or catastrophic failures
- Can be periodically backed up to archival storage to safeguard against catastrophic failures
- A smart DBA keeps system logs on separate disks from data and OS files (ideally
with redundant disk storage)
- Not affected by any type of failure except media or catastrophic failures
Log records – types of entries
The system log 2
- Recovery protocols mostly do not require read_item operations be written to system log
- If log is used for other purposes such as auditing such entries are included
- All permanent changes to DB occur within transactions
- Even if no explicit transaction declared by user/app
- Recovery from a transaction failure requires either undoing or redoing all transaction operations from the log
- This will return the DB to a consistent state after a failure
The system log
Aborted Transactions
- Aborted transactions
- Trace backwards through the log and reset (undo) all items changed by write_item operations in the transaction back to their old values
- Committed transactions: transactions whose updates are written in the log but a failure occurs before we can be sure all the updates have been applied to DB permanently
- Trace forward through log and set all items changed by write_item operations in transaction to their new values
The system log
If system crashes
- If system crashes, we can (for example) UNDO the effect of every write operation of a transaction T by tracing backwards through the log and resetting all items changed back to their old values
- We can also REDO by going forward in the log
Transaction states
System log
Commit point
- All instructions in a transaction have been successful and logged
- Beyond this point, the transaction is COMMITTED and all the changes made are permanently recorded in the DB
- DBMS then writes [commit, T] to the log
- On system failure, look for [start_transaction] markers which are not matched by a [commit] marker
- If we find one, we UNDO all actions associated with that transaction in the log
Transaction schedules
A schedule
- A schedule S of n transactions, T1 , T2
, T3…Tn is an ordering of the operations of the transactions- The ordering is subject to the constraint that for each transaction Ti that participates in S, the operations of Ti in S must appear in the same order as they appear in Ti
Transaction schedule
- Schedule is the ordering of the transactions
- You can see here they have been interleaved, this is an example of non serial schedule
Serial schedules
- A serial schedule with no interleaving
- We could have performed all buy transactions before sell transaction and still had consistent result
Non serial schedules
- Non serial schedule resulting in lost update