# The lake

The lake is a directory on your disk with plain Parquet files, the bare Git mirrors they were read from and a manifest of which files make up each table. Nothing is uploaded.

## Where it is

By default the lake is `~/.local/share/ahto/lake`. Use another with `--lake <dir>` or
`AHTO_LAKE_DIR`, or set `lake.dir` in the config.

A crawl writes each repository into one lake: the location that names the repository,
else the location with the longest organization that holds it, else `lake.dir`. `--lake`
given on the command line sends the whole crawl to that lake instead. Each location is a
whole lake of its own; read it with `--lake <dir>`.

```yaml
lake:
  dir: ~/.local/share/ahto/lake
  locations:               # other lakes for some repositories; the rest go to dir
    - dir: /Volumes/Disk0/ahto/lake
      repos: [github.com/torvalds/linux]   # these repositories
      orgs: [github.com/rust-lang]         # and every repository under these
```

## Looking after it

```sh
ahto storage status          # size of the tables, the mirrors and the index
ahto repo list               # the repositories in the lake
ahto repo show <repository>  # its remotes, refs and last crawls
ahto repo rm <repository>    # remove it (its shared objects stay until a later gc)
ahto storage gc              # delete what removed repositories left behind
ahto storage compact [table] # merge small files; with no table, those with more than --min-files files
ahto storage derive          # bring the read models (tree_files, path_changes) up to date
ahto storage verify          # check every file, row count and id index of the lake
```

Every crawl and sync compacts on its own the tables that have more than 64 files of under
1 MB each on average, such as crawl_runs, which gets a file on every sync. Run
`ahto storage compact` for the big tables.

## Reading it with other tools

The tables are plain Parquet files under `data/`, so DuckDB, Python or any other Parquet
reader can read them too. `ahto query tables` lists them with their files, rows and bytes.

## One writer at a time

Only one crawl, parse or sync writes to a lake at a time: a second one exits with code 75,
or first waits as long as `--lock-timeout` (`lake.lock_timeout`) says. Readers never wait. A
write that is stopped halfway leaves the lake as it was, since the manifest names the new
files only once they are all on disk.

## Keeping it in sync

`ahto serve` syncs each repository it serves every `lake.sync_interval` (5 minutes by
default; 0 turns it off). A crawl of a repository with nothing new reports `unchanged` and
writes nothing.