Persistence (AOF)
How Memorust persists data with an Append Only File.
Memorust persists data using an Append Only File (AOF): every write command is appended to a log on disk. On startup, the log is replayed to rebuild the in-memory state.
How it works
- Append on write: write commands (such as
SET,DEL,SETEX) are serialized and appended to the AOF. - Buffered writer: writes go through a buffered writer to avoid a syscall per command.
- Periodic
fsync: the buffer is flushed andfsync-ed roughly once per second, matching Redis'sappendfsync everysecpolicy. This trades at most ~1 second of writes for much higher throughput. - Replay on startup: when the server starts, it reads the AOF and replays the commands to restore the dataset.
AOF rewrite (compaction)
Over time the AOF accumulates redundant commands (for example, many SETs to
the same key, or keys that were later deleted). The AOFREWRITE command
compacts the log by rewriting it into the minimal set of commands needed to
reproduce the current state:
AOFREWRITEThis keeps the on-disk file small and makes startup replay faster.
Trade-offs
The everysec strategy means a crash can lose at most about one second of
writes. This is the same default Redis uses, and it is a deliberate balance
between durability and write performance. See Benchmarks
for the impact of the buffered writer.