سباقات الإبطال
في هذا الدرس 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.
تفاصيل المخطط المبدئي
عرض عملي
| Step | Reader A | Writer B |
|---|---|---|
| 1 | cache miss, reads price 10 | |
| 2 | updates to 12, deletes key | |
| 3 | writes 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.
التطبيق
طبّق هذا الدرس بمختبر الوحدة وتمارينها واختبارها.
تعليم الدرس كمكتمل اختياري ويمكنك التراجع عنه في أي وقت. يبقى تقدمك محفوظًا في هذا المتصفح.