The project in four partsDört bölümde proje
01
ProblemProblem
An order system lost stock once. A worker had saved the stock change and died before telling the queue the job was done; the queue delivered the job again and the stock dropped a second time. No unit test fails like this: the crash has to land exactly between two writes.
Bir sipariş sistemi bir kez stok kaybetti. Bir çalışan stok değişikliğini kaydetmiş, kuyruğa işin bittiğini söyleyemeden çökmüştü; kuyruk işi yeniden teslim etti ve stok ikinci kez düştü. Hiçbir birim testi böyle başarısız olmaz: çökmenin tam iki yazma işleminin arasına denk gelmesi gerekir.
02
ConstraintsKısıtlar
- Real clocks and threads make every run different; the same inputs must give the same run.
- Faults must be planned: delays, duplicates, drops, partitions, a crash at a named point.
- "Nothing broke" and "everything finished" are different questions.
- A failure with 30 orders and 8 faults is too big to read.
- Gerçek saat ve iş parçacıkları her çalıştırmayı farklı kılar; aynı girdi aynı çalıştırmayı vermeli.
- Arızalar planlanmalı: gecikme, kopya, kayıp, bölünme, belirli bir noktada çökme.
- "Hiçbir şey bozulmadı" ile "her şey bitti" farklı sorulardır.
- 30 sipariş ve 8 arızalı bir hata okunamayacak kadar büyüktür.
03
DecisionKarar
Simulate the system instead of running it: a virtual clock, randomness keyed by message, an event queue with a stable order. Check the safety rules after every event and progress after the faults end. Shrink every failure automatically.
Sistemi çalıştırmak yerine simüle et: sanal saat, mesaja bağlı rastgelelik, sırası kararlı bir olay kuyruğu. Doğruluk kurallarını her olaydan sonra, ilerlemeyi arızalar bittikten sonra denetle. Her hatayı otomatik olarak küçült.
04
SolutionÇözüm
Orders, a queue with leases and at-least-once delivery, and a stock worker, written as state machines. Three workers: the buggy one, the fix, and a queue that never redelivers, which is safe but stuck. The fix saves the job id and its result in the same write as the stock change.
Sipariş servisi, kiralama süreli ve en az bir kez teslim eden bir kuyruk ve bir stok çalışanı; hepsi durum makinesi olarak yazıldı. Üç sürüm var: hatalı sürüm, düzeltme ve hiç yeniden teslim etmeyen kuyruk (doğru ama takılı). Düzeltme, iş kimliğini ve sonucunu stok değişikliğiyle aynı yazma işleminde saklar.