32/37
Part 6 of 6 · Follow-upsLearn and do

Survive a crash: log every use, and replay the log

The rest of the second practice problem asks for this, so here are the ideas, not the code. Keep an append-only log: one line per operation, written before the call returns. On restart, replay the lines in order through a fresh cache. Four things decide whether that works.

Log the hits. Replay has to rebuild the order, not only the contents:

Predict

The log holds put a, put b, get a. Replay it into a capacity-2 cache. Which key goes at the next eviction?

Pick an answer above to see the rest
Predict

The crash cut line 2 short. You append the next record without cutting line 2 off first. How many records are lost?

Pick an answer above to see the rest