Download as pdf or txt
Download as pdf or txt
You are on page 1of 20

LOGO

HỆ QUẢN TRỊ CƠ SỞ DỮ LIỆU

BÀI TẬP CHƯƠNG 3

ĐIỀU KHIỂN ĐỒNG


THỜI

1
LOGO

KỸ THUẬT KHOÁ

2
BÀI TẬP 1.1 2

 (a) Consider the following two transactions and schedule


(time goes from top to bottom). Is this schedule conflict-
serializable? Explain why or why not.
– r0(A) w0(A) r1(A) r1(B) c1 r0(B) w0(B) c(0)
 (b) Show how 2PL can ensure a conflict-serializable
schedule for the same transactions above. Use the notation
Li[A] to indicate that transaction i acquires the lock on
element A and Ui[A] to indicate that transaction i releases
its lock on A.
 (c) Show how the use of locks without 2PL can lead to a
schedule that is NOT conflict serializable.

3
BÀI TẬP 1.2 2

 Consider a database with objects X and Y and assume that


there are two transactions T1 and T2. T1 first reads X and
Y and then writes X and Y. T2 reads and writes X then
reads and writes Y.
– (a) Give an example schedule that is not serializable. Explain why
your schedule is not serializable.
– (b) Show that strict 2PL disallows this schedule.
– (c) What are the differences between the four levels of isolation?

4
BÀI TẬP 1.3

 Lịch S sau đây có khả tuần tự xung đột hay không ?


– R1(X) W1(X) R2(X) R3(Y) W3(Y) W2(X) R4(Y) W1(Y)

 Nếu có hãy xác định lịch tuần tự tương đương ? Hãy viết lại
lịch sử dụng nghi thức khoá 2 giai đoạn và mô tả hoạt động
của các lệnh.

5
BÀI TẬP 1.4 6

 Consider the following two transactions:


T1 T2
------------ ------------
read(A) read(B)
A := 10*A+4 B := 2*B+3
write(A) write(B)
read(B) read(A)
B := 3*B A := 100-A
write(B) write(A)

– Write versions of the above two transactions that use two-phase


locking.
– Is there a non-serial schedule for T1 and T2 that is serializable?
Why?
– Can a schedule for T1 and T2 result in deadlock? If so, give an
example schedule. If not, explain why not. 6
BÀI TẬP 1.5 7

 For each one of the following schedules decide whether


– they are serializable
– they can be produced by a Two Phase Lock (2PL) scheduler
– they can be produced by a strict 2PL scheduler
 and check in the table below all entries that apply. Justify
your answers in a concrete way. For example, if a schedule
is 2PL show a series of lock/unlock operations that are
compatible with the 2PL rules (you can use the empty lines
of the schedules to place lock/unlock operations.) Answers
of the form “it is serializable because I can see that I can
swap the operations” will not get full credit. Assume that
shared locks can be used if in this way you can make a
schedule 2PL or strict 2PL.
7
BÀI TẬP 1.5 7
T1 T2 T3 T1 T2 T3 T1 T2 T3

R(D) W(A)
R(D)
W(A) R(B) W(A)

R(B) W(D) R(B)

W(D) W(B) W(B)

W(B) R(D)
R(D)
R(D) W(D)
W(D)
8
BÀI TẬP 1.6 11

 Exercise 9 For the following schedule assume that the


shared locks are requested immediately before each read
operation, and exclusive locks are requested immediately
before every write operation. Unlocks occur immediately
after the final actionthat a transaction executes.
 Describe the execution of the schedules below: what
actions are denied, whether a deadlock occurs, how the
waits-for graph evolves during the execution of the actions,
and what transaction aborts in the case of a deadlock?

9
BÀI TẬP 1.6 11

S1 T1 T2 T3 T4 S2 T1 T2 T3
1 R(A) 1 R(A)
2 R(B) 2 R(B)
3 W(C) 3 R(C)
4 R(D) 4 W(B)
5 R(E) 5 W(C)
6 W(B) 6 W(D)
7 W(C)
8 W(A)
9 W(D)

10
BÀI TẬP 1.7 2

 For each statement below, indicate if it is true or false.


– (a) Serializability is the property that a (possibly interleaved)
execution of a group of transactions has the same effect on the
database and produces the same output as some serial execution of
those transactions.
– (b) The following schedule is serializable:
r0[A]→w0[A]→r1[B]→w1[B]→r1[A]→w1[A]→r0[C]→w0[C]→c0 →c1
– (d) Strict two-phase locking (2PL) ensures that transactions never
deadlock.
– (e) Strict two-phase locking (2PL) ensures serializability. Note:
This question can be confusing. Be careful! To get serializability,
one needs both strict 2PL and predicate locking. Strict 2PL alone
guarantees only conflict serializability. Please see book and notes
for more details.
11
BÀI TẬP 1.8 13

 Với mỗi lịch sau:


– S1: r1(z) r1(y) w2(y) r2(v) r2(z) w3(z) w2(v) r1(x)
– S2: r1(z) w1(y) r2(y) r2(v) r2(z) w3(z) w2(v) r1(x)
 Hãy cho biết:
– Lịch có khả tuần tự hay không ?
– Có thể được phát sinh bởi nghi thức 2PL hay không ?
– Có thể được phát sinh bởi nghi thức strict 2PL hay không ?

12
BÀI TẬP 1.9 5

 Consider the following actions taken by transaction T1 on


databases X and Y: R(X), W(X), R(Y), W(Y)
– (1) Give an example of another transaction T2 that, if run
concurrently to transaction T without some form of concurrency
control, could interfere with T1.
– (2) Explain how the use of Strict 2PL would prevent interference
between the two transactions.
– (3) Strict 2PL is used in many database systems. Give two reasons
for its popularity.

13
LOGO

KỸ THUẬT NHÃN THỜI GIAN

14
BÀI TẬP 2.1 6

 Given the following sequence of events:


– st1; st2; r1(A); r2(B); w2(A); w1(B)

 Task: Tell what happens as each event occurs for a


timestamp based scheduler.

15
BÀI TẬP 2.2 6

 Given the following sequence of events:


– st1; st2; st3; r1(A); r3(B); w1(C); r2(B); r2(C); w3(B); w2(A)

 Task:
– Tell what happens as each event occurs for a timestamp based
scheduler.

16
BÀI TẬP 2.3 6

 Given the following sequence of events:


– st1; st2; st3; st4; w1(A); w2(A); w3(A); r2(A); r4(A);

 Tell what happens as each event occurs for (a) a


multiversion timestamp scheduler, and (b) a scheduler
that does not maintain multiple versions.

17
BÀI TẬP 2.4 2

 Consider a concurrency control manager by timestamps. Below are


several sequences of events, including start events, where sti means
that transaction Ti starts and coi means Ti commits. These sequences
represent real time, and the timestamp-based scheduler will allocate
timestamps to transactions in the order of their starts. In each case
below, say what happens with the last request.
 You have to choose between one of the following four possible
answers: (a) the request is accepted, (b) the request is ignored, (c) the
transaction is delayed, (d) the transaction is rolled back.
 (a) st1; st2; r1(A); r2(A); w1(B); w2(B);
 (b) st1; st2; r2(A); co2; r1(A); w1(A)
 (c) st1; st2; st3; r1(A); w3(A); co3; r2(B); w2(A)
 (d) st1; st2; st3; r1(A); w1(A); r2(A);
 (e) st1; st2; st3; r1(A); w2(A); w3(A); r2(A);
18
BÀI TẬP 2.5 4

 Show that there are schedules that are possible under the
two-phase locking protocol, but are not possible under the
timestamp protocol, and vice versa.

19
BÀI TẬP 2.6

 Tìm hiểu các thuật ngữ sau:


– rigorous schedule
– strict 2PL schedule
– strong strict two-phase locking (SS2PL) schedule
– cascading rollback
– recoverable schedule
 Mỗi thuật ngữ cần tìm hiểu định nghĩa, giải thích, cho ví dụ,
các đặc điểm, … và ghi nguồn tài liệu tham khảo (LINK) cho
những tài liệu tham khảo sử dụng.

20

You might also like