6.1 Store Layout

The store is the directory store/ under the cache directory, shared by every workspace and every pekit process on the machine (Store). It holds:

PathHolds
cas/<xx>/Blobs by their SHA-256 digests, in directories named by a digest's first two hexadecimal digits, with their executable and numbered copies.
records/<xx>/Step records, program records, manifests, and the records of fetches, unpacks, and git commits, by their keys.
trees/Materialized trees, made once as directories of links to blobs.
complete/A mark for each tree found to have everything it names, at any depth.
seen/For each workspace root, the stamps of the files a build read, and the root's path.
git/Bare clones of the repositories fetch_git fetched from.
scratch/The scratch directories of steps marked #[scratch], with their lock and size files.
claims/A lock file for each step a build claimed. See Claims.
usage/One journal for each build of what it used, for eviction.
eviction.jsonEach record's eviction priority, and what eviction removed.
orphanedWhat workspaces' output directories held of evicted steps, when an eviction last looked.
size, size.lockThe blobs' total size as last measured and added to, and its lock.
tmp/What is being written.
lockThe store's lock.

6.1.1 Writing #

A blob, a tree, or a record is written in full into tmp/, under a name holding the writing process's token, then renamed into place. A rename is atomic, so a reader, or another process, sees a file whole or not at all. A process that loses a race to write the same blob finds it there, and drops its own.

A file put into the store is hashed as it is copied into tmp/, flushed to the disk unless PEKIT_NO_SYNC is set, and renamed to its digest's name (Store::put_file). A blob is read-only. A blob under its digest's name is therefore whole even after a power loss, and is trusted as it's found.

A file that is pekit's own to discard is adopted instead (Store::adopting): a step's results, which its staging directory holds until it is removed, an unpacked archive, and a checked-out commit. Such a file with one link is hashed where it is. If the store holds its contents, nothing is written. Otherwise the file is linked into tmp/, flushed, and renamed into place, so it becomes the blob without being copied. A workspace's files are never adopted, since someone might change them later.

A tree is put at once (Store::put_tree_mounted, Store::put_tree_seen_at). Each new blob it holds, and each of its trees' encodings, is written whole into tmp/ as the tree is walked. Then 16 threads flush them all together, so that one commit of the file system's journal serves many files. Only then is each renamed into place, in the order it was written, so a tree's entries come before the tree. Flushing files one by one cost a journal commit each: storing 20,000 small files took 43 seconds, and takes 7 at once. A put that fails removes everything it wrote.

6.1.2 The lock #

Every process holds lock shared, with flock, while it has the store open, and an eviction or a sweep of stale files takes it exclusively, without waiting. So an eviction or a sweep runs only while no other process has the store, and a process that opens the store waits for one that is running.

Edit this page