Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Cleaning the cache

The cache is cleaned by garbage collection, on the model of Nix generations: every run writes a GC root, roots keep cache entries alive, and a collection deletes every entry no root reaches.

doris gc roots                      # the roots: one per run, with its age, size, revision and job count
doris gc --dry-run                  # what a collection would drop and free
doris gc                            # drop roots older than 30 days, then delete what no root reaches
doris gc --older-than 7d --max-size 100G   # a shorter age limit, then oldest roots go until the cache fits
doris gc --older-than 3d -f         # by age alone: the newest root of a job or branch goes too
doris gc pin latest --name signoff  # keep a run's entries whatever its age
doris gc unpin signoff              # let it age out again

The doris gc commands need no repo. The cache is per user, so they work from any directory.

Roots

Every doris run writes a root, even a run of one job. A root records:

  • an ID, made from the run’s start time in UTC and its process ID;
  • the repo path, git branch and commit, and whether the tree was dirty;
  • the command line and the job IDs it ran;
  • every cache entry its jobs used or stored;
  • each job’s result file;
  • the run’s metrics file.

Each cache entry also records the entries it was built from. A collection keeps everything reachable from a root, upstream entries included, so a small change to the sources still reruns only what changed.

A root keeps the result files, so doris report view can show a past run after the scratch directory has moved on. A job that fails or is cut short with --until still has a root, which keeps what it got through.

Naming a root. Commands that take a root accept its ID, a prefix of the ID only one root has, its pin name, or latest.

What a collection does

A collection has two phases. First it drops roots, by the rules below. Then it sweeps: it marks everything the remaining roots reach, and deletes every entry left unmarked.

doris gc applies the age rules and then, if gc.max_size is set, collects by size.

SettingDefaultMeaning
gc.keep_age30dDrop unpinned roots older than this. never turns the rule off
gc.keep_latestjob-branchKeep the newest root whatever its age: for each job on each branch (job-branch), for each branch (branch), or none
gc.keep_branches0With keep_latest, protect only the N most recently run branches. 0 means all
gc.drop_missing_repotrueDrop roots whose repo path no longer exists, which cleans up after deleted worktrees
gc.max_sizenoneThe cache size to collect down to. none means no limit
gc.autooffWhen to collect after a run: off, size (by size, if over max_size), or age+size (the age rules, then by size)

Because of keep_latest, a branch left for a month still has a warm cache. doris gc lists each root it kept only because of keep_latest, with the jobs it is the newest run of. A job that has been renamed or removed keeps its last root this way forever, so -f (--force, short for --set gc.keep_latest=none) drops roots by age alone. Pinned roots are still kept.

Set them in a settings file, or change one for one command with --set:

doris gc --set gc.keep_latest=branch
doris run lint --set gc.auto=age+size --set gc.max_size=100G    # collect after the run

--older-than AGE and --max-size SIZE are short for --set gc.keep_age=AGE and --set gc.max_size=SIZE. They and -f are applied after every --set, so they win over one.

Collecting by size drops the oldest root, sweeps, and measures again, one root at a time, until the cache is within max_size. It never drops a pinned root, a root keep_latest protects, or the root of the run that triggered it. If the cache is still too big when only those are left, doris stops and warns. Sizes are the sum of file sizes, not disk blocks.

A root whose repo is missing protects nothing under keep_latest while drop_missing_repo is on, which drops it even if it is the newest of its branch. With drop_missing_repo off, it is treated like any other root.

Pinning

doris gc pin ROOT [--name NAME] protects a root from every rule, for example a sign-off run you may need to reproduce or whose report must stay available. doris gc unpin ROOT removes the protection, and the root then ages out like any other.

Collecting while runs are going

A run holds a shared lock on the cache from its start to its end. A sweep takes the lock exclusively, so it never deletes an entry a live run has just used or written:

  • doris gc waits for running runs before it sweeps.
  • A run’s own collection (gc.auto) is skipped if other runs are using the cache.
  • --dry-run and doris gc roots take no lock.

The locks are flock locks, so the cache directory must be on a filesystem that supports them.

A root left by a run that crashed stays, and ages out like any other.

What is in the cache directory

entries/<kk>/<key>/  an entry; <kk> is the first two characters of the key
  entry.json         the step's name, its verdict and message, the hash of each output,
                     whether a debug run stored it, and the keys of its upstream entries
  out/<n>            a copy of the step's nth declared output, a file or a directory
roots/<id>.json      a run's root
roots/<id>.pin       present if the root is pinned; holds the pin's name, if it has one
tmp/                 entries being written; each is moved into entries/ when complete
lock                 held shared by runs, exclusive by a sweep

An entry file’s schema is doris/cache-entry/1 and a root’s is doris/gc-root/1. An entry with another schema is not used, so its step runs again. A sweep removes a root with another schema along with root files it can’t read, and whatever interrupted runs left in tmp/. Until the first release, a cache written by another version of doris is not kept (see Upgrading the cache’s files).

Working directories are separate. Nothing under scratch/doris/ is in the cache or needs a root, and doris gc does not touch it. A step that passed leaves only its outputs there. The directories kept whole, for a failure or a debug run, are removed by doris clean or after dirs.work_max_age.

Measurements are removed by age. doris gc also removes the measurement store’s files of runs older than measurements.max_age, 365 days by default. --dry-run says which it would remove. The store is not part of the cache, and no root keeps a measurement.