Database Chapter 11 Jobs - Concurrency Control

The last chapter is over, and the 13-week database course is over, which means it's time to study hard for the exam and go home!
The assignments in this chapter are questions 9, 10, and 14 of the after-school exercises, and some answers are referenced, just to learn the standard of answering questions. It's still the old model, let's review the key points of this chapter first.
1. Basic block type
Exclusive lock: Abbreviated as X lock, also known as write lock.

If transaction T adds an X lock to data object A, only T is allowed to read and modify A, and no other transaction can add any type of lock to A until T releases the lock on A to ensure that other transactions release A in
T A can no longer be read and modified until the lock on

Shared lock: Abbreviated as S lock, also known as read lock.

If transaction T adds an S lock to data object A, transaction T can read A but cannot modify A, and other transactions can only add S lock to A, but cannot add X lock until T releases the S lock on A to ensure
other A transaction can read A, but cannot make any changes to A until T releases the S lock on A

lock compatibility matrix

insert image description here

Second and third level blockade agreement
  • The first-level blocking protocol
        transaction T must first add X lock to the data R before modifying it, and it will not be released until the end of the transaction.
            The normal end (COMMIT)
            abnormal end (ROLLBACK)
        level one blocking protocol can preventlost modification
  • The second-level blocking protocol
        and the first-level blocking protocol plus the transaction T must add an S lock to the data R before reading it, and the S lock can be released after reading.
        Secondary blocking protocols preventlost modificationandread "dirty" data
  • In the three-level blocking protocol,
        the first-level blocking protocol plus the transaction T must first add an S lock to the data R before reading it, and it will not be released until the end of the transaction.
        Three-level blocking protocol preventslost modificationread dirty dataandnon-repeatable read
Main Differences in Level 3 Agreements

insert image description here

3. Livelock and deadlock
livelock:

Transaction T1 blocks data R.
Transaction T2 requests to block R again, so T2 waits.
T3 also requests to block R. After T1 releases the block on R, the system first approves T3's request, and T2 is still waiting.
T4 requests to block R again, and when T3 releases the block on R, the system approves T4's request...
T2 may wait forever

Deadlock:

Two or more transactions have blocked some data objects, and then both request locks on data objects that have been blocked by other transactions, resulting in a dead wait.

4. Serializable scheduling and conflict serializable scheduling

Serializable scheduling: Concurrent execution of multiple transactions is correct if and only if the result is the same as if the transactions were executed serially in some order

Conflict-serializable scheduling: A scheduling Sc obtains another scheduling Sc' by exchanging the order of non-conflicting operations of two transactions while ensuring that the order of conflicting operations remains unchanged. If Sc' is serial, it is called scheduling Sc is a conflict serializable schedule

If a schedule is conflict serializable, it must be a serializable schedule. This method can be used to determine whether a schedule is conflict serializable. Conflicting serializable scheduling is a sufficient condition for serializable scheduling, but not a necessary condition. There are also serializable schedules that do not satisfy the conflicting serializable conditions.

Five, two-stage lock protocol

It means that all transactions must lock and unlock data items in two phases.
Meaning: the transaction is divided into two phases.
    The first phase is to obtain the lock, also known as the expansion phase.
        Transactions can apply for any type of lock on any data item, but No locks can be released
    The second phase is to release the lock, also known as the contraction phase
        The transaction can release any type of lock on any data item, but can no longer apply for any locks

6. Homework

insert image description here

insert image description here
insert image description here
insert image description here

Guess you like

Origin blog.csdn.net/weixin_45845039/article/details/117263994