Administration

Data directory layout

What the server keeps on disk, how big it gets, how it is protected and what must never be done to it.

The first overview of the files is in Where data lives. This page is about running a server on them.

Layout#

<dir>/
  admin.password, replicator.password
  control.state
  reports/  reports/pending/
  <database>/<table>/shard-N.log           memory engine
  <database>/<table>/lsm-N/ ...             lsm engine
  <database>/<table>/repl-N.log             lsm engine, replicating server

N runs from 0 to shards - 1. Every table of one server has the same number of shards; a replica adopts its primary's number, because the shard of a key depends on it.

Rules for the directory#

RuleWhy
One server per directory.There is no lock file yet. Two processes on one log would corrupt it.
Do not edit, move or delete files while the server runs.Threads hold the files open; Windows cannot delete or rename an open file. Use the HTTP API or SQL to drop and rename: they stop the table's threads first.
Do not change shards once a table has data.At open the server opens shard-0.log to shard-(N-1).log for the configured count N and the shard of a key follows from N. There is no resharding, and no check is documented that refuses a different count: logs beyond the new count would be ignored and keys would map to other shards. Keep the count you started with (a replica takes its primary's).
Do not edit control.state.It holds the fence (epoch, lease role, dirty flag, data epoch). Deleting it on a managed node makes the node forget the epochs it has seen.
Keep admin.password private.Anyone who can read it is an administrator. It is created readable by its owner only.
Keep it on a disk with an honest fsync.Acknowledged means flushed. A drive or controller that lies about flushes turns that into a promise nobody can keep.

Size#

  • A memory-engine shard log holds every write, overwrite and delete since the last rewrite. It only grows until a checkpoint. A table that is overwritten a lot can be several times the size of its live rows; at start the server rewrites a log that is at least checkpoint-min-mb (default 8 MiB) and more than twice its live data plus 64 KiB.
  • Plan for the live data plus its history between checkpoints. Check the watcher's disk check: it warns below disk_min_free_percent free (default 10%) and is critical below half of that.
  • An lsm table holds sorted files and log segments; compaction merges levels in the background. Disk use can briefly rise during a compaction. Level 1 is limited by lsm-level1-mb (default 256) and each deeper level is 10 times bigger.
  • A replicating server with lsm tables writes every row twice (the engine and repl-N.log).

Permissions#

The server needs read and write access to its directory and nothing else. install-service on Linux creates the user raftdb without a login and the folder /var/lib/raftdb with mode 750, and the unit runs with the file system read-only except that folder. Give the watcher's user no access to the data directory unless its disk_path check needs it (df needs none).

Free space exhausted#

If a write or sync fails, the WAL sets a failed flag and every later write returns an error until the process restarts (the process should stop and recover from the log, as PostgreSQL does). The watcher's write_probe notices a server that answers but cannot store data, and restarts it if restart_command is set. Free space first: a restart on a full disk fails again.

See also#