A snapshot is a read, so it skips the dead
A snapshot goes through the same check as every other read. Expired records are still in your dict, because nothing deleted them.
Time left or end time: the spec picks
A record saved with an end time has to come back with one. There are two honest designs, and the spec picks:
- Time keeps flowing. Store absolute end times and restore them unchanged. Redis works this way: it stores each key's expiry as an absolute Unix timestamp, so time flows on even while the server isn't running.
- The clock stops while saved. Store the time left,
end - saved_at, and restore it asrestored_at + left.
Take a timer that ends at 130, saved at 110 and restored at 500:
| What the snapshot stored | End after the restore | At 500 |
|---|---|---|
| the time left, 130 - 110 = 20 | 500 + 20 = 520 | 20 to go |
| the end time, 130, used as is | 130 | already over |
| the end time, 130, added to the restore time | 500 + 130 = 630 | 130 to go |
Read the spec for words like remaining, left, as of or recalculated. They tell you which design it wants. Then the snapshot should store what the restore needs.
Restore the latest snapshot at or before the time asked for
When there are several snapshots, the restore wants the latest one at or before the time it names. That's the latest-entry query above, with its trap: a forward loop that returns the first match restores the oldest snapshot.
Now your database's level 4. In the editor, fill in the loop in backup.