انتقل إلى المحتوى
أمين أبوزيد
درس مخطط لهMID-040-L02

سباقات الإبطال

  • الدرس 2 من 5
  • Mid-level
في هذا الدرس 4 موضوعات

هذا الدرس مخطط له. يعرض المخطط أدناه الموضوعات التي سيغطيها، ولم يُنشر الدرس الكامل بعد.

نص الدروس والتمارين باللغة الإنجليزية، بينما تبقى واجهة الموقع وعناوين الدروس بالعربية.

في هذا الدرس

find a race that leaves stale data and fix it.

الموضوعات المخطط لها

  • Race: reader A misses and reads the old row; writer B updates the row and deletes the key; A then writes the old value to the cache. Stale until TTL.
  • Fix 1: delete after write (database first), plus a short TTL.
  • Fix 2: versioning: store the row version with the value; only overwrite if the version is newer.
  • Fix 3: delayed double delete: delete again after a short pause (reduces but does not eliminate the race).
  • "It is rare" is not an argument: at scale rare happens daily.
تفاصيل المخطط المبدئي

عرض عملي

StepReader AWriter B
1cache miss, reads price 10
2updates to 12, deletes key
3writes 10 to cache

Fix: A writes only if its version (1) is newer than what is cached; the cache stores version 2 or nothing.

اختبر فهمك

Why does a plain delete not prevent this race?

أظهر الإجابة

The late reader refills the cache with the old value after the delete.

التطبيق

طبّق هذا الدرس بمختبر الوحدة وتمارينها واختبارها.

المختبر والتمارين الاختبار

تعليم الدرس كمكتمل اختياري ويمكنك التراجع عنه في أي وقت. يبقى تقدمك محفوظًا في هذا المتصفح.

اكتب للبحث في المستويات والمراحل والوحدات والدروس.