Maintenance

Stopping, restarting, adding and removing processes, moving partitions between stores, sizing, and signals and exit codes.

A process keeps nothing of its own, so most maintenance is starting and stopping processes. What a deployment keeps is in PostgreSQL, and moves between stores by store operations.

Stopping and restarting a process

On SIGTERM (or SIGINT) a process:

  1. stops taking requests and sessions (/readyz answers 503), and tells its peers it is draining, so none hands it a partition;
  2. commits what is pending and releases each partition's lease, so another process takes it at once;
  3. closes its sessions unavailable (clients reopen elsewhere from where they were), lets HTTP requests in progress finish, and answers what peers forwarded to it;
  4. exits 0.

All of it within drain-timeout (20 seconds by default); after that it exits anyway. Give the supervisor more time than that before it kills the process. A rolling restart needs no command: restart the processes one at a time, each after the one before is ready again.

Adding and removing processes

  • Adding. Start a process on the same home store, with every other store, the same deployment-name, an internal listener and the deployment's internal authentication. It registers in the home and takes partitions as requests need them and as leases are balanced: a process holding more than its share hands the excess over, a few at a time.
  • Removing. Stop it. Nothing records a process beyond its registry row, which lapses.
  • A lost process (killed, its host gone) hands nothing over: its leases lapse after lease-ttl (5 seconds by default) and other processes take its partitions then. A write it had in flight is either committed, and answered from its outcome when its client retries, or not. The deployment's status lists it as process_unseen for a day.

A process without an internal listener runs alone, and refuses to start while processes with one are live: to grow from one process, restart it with an internal listener first.

Stores and partitions

Partitions move between stores while they serve: one partition, a whole database, or every partition of a store being drained. See PostgreSQL stores.

mimicd admin database move --database DB --to eu2 --key move-db-1
mimicd admin store drain eu1 --key drain-eu1
mimicd admin moves show --key drain-eu1

A database's partition count is fixed for its life. To spread a database over more partitions, move its data into a new database, through an archive (see Backups and restores).

Sizing

The figures here are for planning. Measure your workload before you size a production deployment.

  • Memory. Set GOMEMLIMIT a little below the container's limit. resident-memory (half of GOMEMLIMIT by default, else half of the host's memory) bounds what resident documents and their buffers hold: past four fifths of it, quiet documents leave memory, down to seven tenths. Documents also leave memory after 10 minutes idle. Backups' read-backs and restores hold up to backup.merge-segments segments open, about 1.8 MiB each (256 by default: about 460 MiB); lower it on a small host, keeping it above backup_chain_segments + 1. Watch mimic_worker_memory_bytes, mimic_process_memory_resident_bytes and mimic_worker_dematerialized.
  • CPU. Mostly the document core's evaluation, TLS and password hashing. Add processes.
  • Connections. Each process holds up to postgres.pool-size + 1 (65 by default) to each store. A process's lease renewals take a connection from the same pool every lease-ttl / 5: a pool held by slow work past lease-ttl costs the process its partitions, which another takes. Watch mimic_store_connections and mimic_lease_renewal_duration_seconds.
  • Store disk. About the retained bytes of the partitions a store holds, times PostgreSQL's overhead, plus its WAL (see Requirements). Write throughput is bounded by the store's commit latency: spread write-heavy databases over more stores.
  • The home store also holds the deployment's records and its audit trail (one row per change, kept audit_retention). It is small beside the data.
  • Backup destinations. Per database, one full per backup_full_interval, kept backup_daily_retention, each about the database's state compressed, and the increments of backup_retention, each about what was written in its interval. Chains share nothing, so a destination holds about backup_daily_retention / backup_full_interval fulls of each database (30 with the defaults).

Signals and exit codes

SignalWhat the process does
SIGTERM, SIGINTStops taking requests, hands its partitions over within drain-timeout, exits
SIGHUPReads its options again and applies what a reload may change
CodeMeaning
0Stopped after handing its partitions over, or a command succeeded
1A failure a retry may cure: a store not reached, a listener not bound, a command or its operation failed or was cancelled
2The command line or the configuration is invalid
4backup expire refused by a guard, which it names; ask again later
5Refused as incompatible: the store's settings lose acknowledged writes, PostgreSQL older than 16, a later schema, or another deployment's store
6A cutover wrote a document and the target holds another state: running it again does not help
7A cutover's archive is not of the length stated

Restart a process after exit code 1, but not after 2 and 5, which wait for an operator.