كل المقررات

الرئيسية / مقرر قاعدة البيانات / الفصل 10 الجزء 2

الفصل 10 (الجزء 2): Concurrency Control

Deadlock, timestamps and isolation levels

على طول: لما الـ transactions تستنى بعض في دايرة (deadlock)، وبدائل الـ locks، ومستويات العزل.

فيديو المحاضرة

فيديو المحاضرة

بعد الفيديو: الأمثلة والاختبار والتمارين والمشروع الصغير تحت.

رسوم متحركة

الانتظار والـ locks

أمثلة SQL

أمثلة قصيرة وبسيطة

الكود قصير والنتيجة اتجرّبت فعلاً. عدّل في المحرر واضغط شغّل.

المثال ١: wait-for graph كجدول

Sample output (press Run to produce your own):
t_a | t_b
----+----
T1  | T2 
(1 row)

المثال ٢: مفيش deadlock

Sample output (press Run to produce your own):
two_cycles
----------
0         
(1 row)

المثال ٣: الـ timestamp والعملية المتأخرة

Sample output (press Run to produce your own):
decision           
-------------------
abort and restart T
(1 row)

افتح الموضوع المقابل في صفحة LiU TDDD12

اختبار قصير

اختبر فهمك

1. A deadlock is:

2. The DBMS usually resolves a deadlock by:

3. Locking in a fixed order:

4. Timestamp ordering uses:

5. Which level allows dirty reads?

تمارين برمجة

جرّب بإيدك

التمرين 1

جدول waits فيه (T1,T2) و(T2,T3) و(T3,T1). اعرض كل الصفوف. هل فيه cycle؟ فكّر قبل ما تقرا النتيجة.

The waits table holds (T1,T2), (T2,T3), (T3,T1). Show all rows. Is there a cycle? Think before reading the result.

(output appears here)

التمرين 2

اختار ضحية: الـ transaction اللي معاها أقل عدد writes من جدول tx(name, writes).

Pick a victim: the transaction with the fewest writes from tx(name, writes).

(output appears here)

مشروع صغير في آخر المحاضرة

اكتشف deadlock واختار الضحية

الداتا: Wait-for data: 4 waits between 3 transactions. Written for this course (our own data, free to reuse).

License / source: Our own sample data; SQLite is in the public domain. Dataset page

الخطوات

  1. جدولين: waits وـ tx(name, writes).
  2. اكتشف أزواج الانتظار المتبادل (T_a تستنى T_b وT_b تستنى T_a). المتوقع: T1 وT2.
  3. اختار الضحية من الاتنين بأقل writes. المتوقع: T2.
  4. اعرض الضحية.
Expected output (press Run to produce your own):
t_a | t_b
----+----
T1  | T2 
(1 row)
victim
------
T2    
(1 row)

مشروع نهاية الفصل

ملف المشروع العملي للفصل 10

ملف PDF فيه مشروع صغير بأسئلة عملية تطبّق بيها كل اللي اتعلمته في الفصل، مع حل نموذجي في الآخر.

افتح ملف المشروع (PDF)

Credits: the topic order follows the lecture list of the course TDDD12 Database Technology at Linköping University (https://www.ida.liu.se/~TDDD12/fo/), whose reading guide is based on the textbook Fundamentals of Database Systems by Elmasri and Navathe. We found no reuse licence on that page, so we link to it and copy nothing from it: the explanations, diagrams, data and code in this lecture are our own. Reference: Elmasri and Navathe, Fundamentals of Database Systems, the chapters on concurrency control.