Store internals and repair
Everything Interlinked stores is in the home folder, and many processes can use it at the same time with nothing running in the background to coordinate them. This page describes how, and what happens after a crash. This page gives the ideas.
What is on disk
<home>/store/
├── FORMAT the format marker ("il-store 1")
├── keys/ identities
├── rooms/<room id>/ one folder per room: its segments, a checkpoint, indexes and cursors
├── blobs/ files and large messages, by the hash of their content
├── pending-erasures/ markers for message bodies waiting to be erased
├── tombstones/ markers for deleted rooms
└── changes an optional journal that tells readers something changed
Folders are readable only by your user and files likewise, whatever the umask. Unknown files are ignored, so a newer version can add files without breaking an older one.
Segments
A room is a sequence of segments: append-only files of records. Each record is a length, a checksum of the body, and the body. A record exists only when all of its bytes are there and its checksum matches, so a reader that meets an incomplete record simply stops and tries again later, because a writer may be in the middle of writing it.
Locks, and how several processes share one store
A writer takes an exclusive lock on the room's lock file while it appends. The lock goes away if the process dies, so a crashed writer never leaves a room locked. Inside one process, threads take their own lock first, because file locks do not exclude threads that share a file descriptor. Readers take no room lock: they read what is complete.
After a crash
If a writer died in the middle of a record, the room ends with bytes that are not a complete record. The next writer, which holds the lock and so knows the earlier writer is gone, cuts the segment back to the end of the last good record before it appends. That is the only repair, and it is safe because the bad bytes were never visible to a reader.
A bad record followed by more data is different: it is corruption, not a half-written tail. Interlinked refuses with an error and never cuts it, because that could throw away good entries. The relay reports rooms it sets aside after damage on its error output, which is why the relay guide says to capture it (Back up, restore and upgrade). The remedy for corruption is a backup.
Room creation, segment rollover and file commits also flush their directory unless durability is
none, so a created room is not lost to a power cut after the command has returned.
Compaction and erasure
Deleting a message hides it at once and erases its body later, at the next idle moment. A home that has
not been used for a while (runner.compaction_idle_s, 30 seconds by default) rewrites the room without
the deleted bodies, in the same order and at the same positions, and swaps the new room in. The swap is
safe against a crash: before the last step the old room is restored when the store is next opened, and
after it the old copy is removed. il status shows how many erasures are waiting and how old the oldest
is. A busy home defers the rewrite without blocking anything.
An entry written by an older version signs its body directly, so its body cannot be removed without breaking the signature. Current entries sign a hash of the body, so the body can go and the chain still verifies.
Next
MLS design describes how encrypted rooms work.