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:
- stops taking requests and sessions (
/readyzanswers503), and tells its peers it is draining, so none hands it a partition; - commits what is pending and releases each partition's lease, so another process takes it at once;
- closes its sessions
unavailable(clients reopen elsewhere from where they were), lets HTTP requests in progress finish, and answers what peers forwarded to it; - 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 asprocess_unseenfor 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-eu1A 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
GOMEMLIMITa little below the container's limit.resident-memory(half ofGOMEMLIMITby 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 tobackup.merge-segmentssegments open, about 1.8 MiB each (256 by default: about 460 MiB); lower it on a small host, keeping it abovebackup_chain_segments+ 1. Watchmimic_worker_memory_bytes,mimic_process_memory_resident_bytesandmimic_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 everylease-ttl/ 5: a pool held by slow work pastlease-ttlcosts the process its partitions, which another takes. Watchmimic_store_connectionsandmimic_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, keptbackup_daily_retention, each about the database's state compressed, and the increments ofbackup_retention, each about what was written in its interval. Chains share nothing, so a destination holds aboutbackup_daily_retention / backup_full_intervalfulls of each database (30 with the defaults).
Signals and exit codes
| Signal | What the process does |
|---|---|
SIGTERM, SIGINT | Stops taking requests, hands its partitions over within drain-timeout, exits |
SIGHUP | Reads its options again and applies what a reload may change |
| Code | Meaning |
|---|---|
| 0 | Stopped after handing its partitions over, or a command succeeded |
| 1 | A failure a retry may cure: a store not reached, a listener not bound, a command or its operation failed or was cancelled |
| 2 | The command line or the configuration is invalid |
| 4 | backup expire refused by a guard, which it names; ask again later |
| 5 | Refused as incompatible: the store's settings lose acknowledged writes, PostgreSQL older than 16, a later schema, or another deployment's store |
| 6 | A cutover wrote a document and the target holds another state: running it again does not help |
| 7 | A 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.