Concurrency Control Flashcards

1
Q

What are the 3 parts to Concurrency Control?

A

Transactions, Locks, Concurrent processing

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

What are transactions?

A
  • Definition: A logical unit of work that must be completed in its entirety or be aborted - A transaction is created every time you read from and/or write to a database - Many transactions consist of two or more database requests - A transaction that changes the contents of the database must alter the database from one consistent state to another - A consistent database state is one in which all integrity constraints are satisfied
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the transaction Properties?

A

All transactions must adhere to the ACID rules: - Atomicity - Consistency - Isolation - Durability

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

What is atomicity?

A

Either the effects of all or none of its operations remain when a transaction is completed (committed or aborted respectively) - In other words, to the outside world a committed transaction appears to be indivisible, atomic - A transaction is a unit of work that appears as if it is either performed in its entirety, or not performed at all (“all or nothing” semantics)

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

What is consistency?

A

Every transaction must leave the database in a consistent state, i.e., maintain the predetermined integrity rules of the database –All constraints (Entity, Domain and Referential Integrity) must be satisfied with each update - A transaction must transform a database from one consistent state to another consistent state

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

What is isolation?

A

Transactions cannot interfere with each other - The effects of an incomplete transaction are not visible to another transaction –A lock guarantees exclusive use of a data item to a current transaction - Providing isolation is the main goal of concurrency control

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

What is durability?

A

Effects of successful (committed) transactions must persist through crashes or system failure - Typically by recording the transaction’s effects and its commit event in a non-volatile memory (disk)

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

What is Concurrent Processing?

A

The co-ordination of simultaneous execution of transactions in a multi-processing database system - To ensure serializability of transactions–Execution of transactions in the correct sequence

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

What is concurrency control?

A

Need to avoid data integrity and consistency problems – Lost update •one record simultaneously updated by two different users –Uncommitted data •Two concurrent transactions, the first is rolled back after the second has accessed the uncommitted data, violating isolation property –Inconsistent retrievals •One transaction is executing calculations on a set of data while a second transaction is updating the same data

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

What are Locks?

A
  • Guarantee exclusive use of a data item to a current transaction • Released when transaction is committed • Managed by a lock manager • Lock levels: –Database –Table –Page –Row –Field
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the Two Phase Locking Protocol (2PL)

A
  • Defines how transactions acquire and release locks • Guarantees serializability • Does not prevent deadlocks • Two phases –Growing phase: a transaction acquires all required locks, without unlocking any data, until lock point –Shrinking phase: a transaction releases all locks and cannot obtain any new lock
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are the 2PL Protocol Rules?

A
  • Two transactions cannot have conflicting locks
  • No unlock operation can precede a lock operation in the same transaction
  • No data are affected until all locks have been obtained
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What are the different Lock modes?

A

Shared lock

–One user asks to read a record

– Other users may read it

– No user can update it

Update lock

– Temporary state before Exclusive lock

Exclusive lock

– One user asks to modify a record

– No other user can read it or modify

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

What is a Deadlock?

A

A DeadLock - AKA “The Deadly Embrace”

• Occurs when two transactions wait for each other to unlock data

– T1 obtains a lock on X

– T2 obtains a lock on Y

– T1 requests a lock on Y

– T2 requests a lock on X

• Only exists with exclusive lock

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

How can you control posisble deadlocks?

A

• Prevention

– Transaction is aborted and rescheduled if possibility of deadlock exists

• Detection

– If a deadlock is found, one transaction is aborted (rolled back) and rescheduled while the other continues

• Avoidance

– Obtain all locks, in succession, before executing

– increase action response times

• Recommendations:

– Low probability: detection

– High probability: prevention

– Use avoidance where response time is a low priority

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

How does recovery work in SQL?

A
  • As each modification to the database, it goes to the transaction log first, it will be written to the database at a later time
  • Log records for data modifications record either the logical operation performed or they record the before and after images of the modified data

– The before image is a copy of the data before the operation is performed; the after image is a copy of the data after the operation has been performed

• In the event of a crash, the Database Administrator restores the database from the latest backup and then applies the transaction log