Wiki Operations
Startup, shutdown and recovery
The order in which a Mirexa node starts and stops, what a clean stop and a crash each leave on disk, what recovery replays, how corrupt state is handled, quarantine directories, and disk-space planning.
A Mirexa node acknowledges a write only once it is in the write-ahead log (WAL) on disk, and later moves it into compressed chunk files. Everything about starting and stopping follows from that: a clean stop moves what is still in memory into chunks, a crash leaves it in the WAL, and startup replays from the WAL whatever no chunk holds. This page gives the order of both sequences, what recovery does and refuses to do, where set-aside data goes, and how much disk to plan for.
Startup order
| Step | What happens | Fails the start? |
|---|---|---|
| 1 | Configuration: defaults → file → environment → -, then validation |
yes, naming every problem |
| 2 | Logger, metrics registry, health manager; from here on SIGHUP is caught and means reload, never stop |
yes |
| 3 | TLS configuration and its SIGHUP watcher (when security.) |
yes, if the certificate pair cannot be loaded |
| 4 | Create the data directory; consensus (clustered only): start Raft, be admitted to the control-plane group if joining (cluster.), then wait for the agreed cluster settings (cluster.) |
yes; a decommissioned node logs why and exits 0 |
| 5 | Storage layout with the agreed partition count | — |
| 6 | Dispatcher and WAL recovery (below), with the agreed codec | yes, on mid-log corruption or an unrecoverable index |
| 7 | Keyring, grant ceiling, partition routing, primary lease and replica-log gates | yes, on a bad key or permission name |
| 8 | Data-plane listener starts accepting | yes, on bind failure |
| 9 | Health checks registered | — |
| 10 | Control listener (control.) and, clustered, the leader-side loops |
yes, on bind failure or a refused address |
| 11 | Cluster planes (clustered): key-revocation sync, replication listener, registration with the cluster, replica supervisor | yes |
| 12 | Configuration-file watcher (SIGHUP also reloads it at once) |
yes |
| 13 | Observability server (/, /, /) |
no — a bind failure is logged and the node runs on without it |
| 14 | Readiness set to true; WAL checkpoint loop starts; mirexa started is logged |
— |
Two consequences for operators:
- Nothing answers on the observability port until step 13. A recovery that takes minutes shows as a refused connection, not as a 503. Size probe start delays for the worst-case recovery, not the typical one.
- A clustered node serves none of the partitions it is primary of until it holds a
lease (granted on its first acknowledged heartbeat, once its control-plane state has
caught up) and has replayed any replica log it kept as a copy. Requests meanwhile get
PartitionUnavailableor a retryable shed. See failover.
Shutdown order
SIGINT or SIGTERM starts a clean stop; so does the cluster telling a decommissioned node
it has left (exit status 0).
| Step | What happens | Bounded by |
|---|---|---|
| 1 | / turns false, so load balancers stop routing here |
— |
| 2 | Hand-off (clustered primaries): stop admitting writes for placed partitions (answered as retryable sheds), let admitted writes finish, then wait until every copy tailing this node has been sent everything it made durable | network. (30 s); on timeout an ERROR names how many copies were behind and the stop continues |
| 3 | Stop the WAL checkpoint loop | — |
| 4 | Stop the cluster planes (replica supervisor, heartbeats, replication listener) while the data path still works | — |
| 5 | Stop the data-plane listener: refuse new connections, wait for open ones, then force-close | network., plus up to the same again after force-closing |
| 6 | Stop the control listener | control. (10 s) |
| 7 | Stop Raft | — |
| 8 | Drain the dispatcher: every stream's hot cache is written to a final chunk | unbounded; the only step whose failure makes the exit non-zero |
| 9 | Stop the observability server, so the stop itself stays observable | observability. (15 s) |
Why a stop can be slow
Two known behaviours make a clean stop take much longer than an orchestrator's default grace period. Neither loses data: if the process is killed part way, everything acknowledged is in the WAL and is replayed at the next start, which is then slower.
- Idle connections hold step 5 for its whole timeout. The listener waits for every
connection to finish, and an idle one (a client blocked reading its next response, such
as an SDK's pooled connection, a dashboard, or a subscriber) does not, so a node with any
connected client typically spends the full
network.shutdown_timeouthere before force-closing. This is accepted behaviour, not scheduled to change. - The final drain is one stream at a time. Each stream's drain is its own chunk write, index update and fsyncs. Measured 2026-10-20 on a laptop NVMe disk with other work running: about 45 ms per stream, 45.4 s for a node holding 1,000 streams and 4.0 s for 100. A node with tens of thousands of streams takes minutes.
So the worst case is roughly 2 × network.shutdown_timeout (hand-off and listener) plus up
to another network.shutdown_timeout after force-closing, plus control.shutdown_timeout,
plus about 45 ms per stream. Give the process that long (for example Docker's
stop_grace_period or a Kubernetes terminationGracePeriodSeconds), or accept a slower
next start.
What a crash leaves, and what recovery replays
Recovery runs inside the dispatcher's construction, before the data listener exists, so no request is served from partially recovered state.[1]
- The shared WAL and every tick shard directory on disk (
wal/,wal/shard_<n>/— all of them, whateverwal.shard_countsays now) are scanned. Recovery streams the records rather than holding the log in memory, so startup memory does not grow with the WAL.[2] - Candle records are replayed into each stream's hot cache unless a base chunk's time range already covers them. Tick records are replayed unless a tick chunk already holds them, identified by WAL position (two trades with the same timestamp are both kept).
- Records belonging to a partition that was quarantined are skipped, up to the position its
log had reached (
wal/quarantine.floors). - Once replay finishes, the streams' flushers start, and the next checkpoint moves the replayed data into chunks and reclaims the segments.
Corruption policy
| Found at startup | Action |
|---|---|
| Torn record at the end of the last WAL segment, nothing valid after it | Truncated; recovery succeeds. This is the normal result of a crash mid-write; the torn record was never acknowledged. |
| Damage in the last WAL segment with a valid record after it | Refused with ErrCorruptMidLog, nothing truncated (since 2026-10-30): that is rot, not a torn write, and truncating would delete acknowledged records. A whole zeroed 512-byte sector before the valid record still counts as a tear. |
| Corruption in any earlier position | Refuses to start (ErrCorruptMidLog) and truncates nothing. |
| A segment with a wrong header (not a Mirexa WAL segment) | Refuses to start. |
| A missing header on the last segment | Treated as a torn create. On an earlier segment: refuse. |
A stream's stream. that does not parse, single node |
Refuses to start. |
A stream's stream. that does not parse, clustered, and another node holds an in-sync copy |
The whole partition is moved to quarantine/, its WAL records are floored, the node starts, and it re-seeds the partition as a copy. If this node is still the partition's primary, it waits (up to four liveness timeouts plus 10 s) for the cluster to fail the partition over first; with no other holder it refuses to start. Counted in mirexa_.[3] |
An unreadable wal/ |
Refuses to start. |
A refusal to start is deliberate: carrying on past corruption in the middle of the log would silently drop acknowledged writes. There is no automatic repair tool for a single node; the options are restoring the data directory from a backup or, with care, moving the damaged file aside by hand and accepting what it held.
A stream whose index is damaged but not touched during startup (it had no WAL records to replay) is found only when something reads it, and that request fails.
What a crash can lose
- Single node,
wal.sync_policy: always(default): nothing acknowledged.[4] sync_policy: intervalordisabled: writes acknowledged since the last fsync.- A clustered primary that crashes: writes it acknowledged that its copies had not yet pulled, if a copy is then promoted in its place — measured 2026-10-20 as milliseconds of writes in practice, bounded at a few seconds. A clean stop's hand-off avoids this. See durability and replication.
Quarantine directories
<data_dir>/quarantine/ holds whole partition directories that a node set aside instead of
deleting. Nothing in Mirexa ever deletes them; they are evidence, kept until an operator
removes them.
| Name | Why it was moved |
|---|---|
partition_ |
this node's copy diverged from the cluster's history after a failover |
partition_ |
this node no longer holds any role for the partition (it moved away, or a copy was dropped) |
partition_ |
a copy's history below its sync point did not match its primary's |
partition_ |
a stream index was corrupt at startup (above) |
Quarantine only occurs on clustered nodes. A quarantined partition takes disk space until removed; a node that releases many partitions (repeated rebalancing, for example) can accumulate a lot. Before deleting one, make sure the partition is served and in sync elsewhere (reconciliation). See the on-disk layout for the full tree.
Disk space
Plan for these, measured from the data directory:
- Chunks and indexes — the stored data.
mirexa_storage_bytesreports chunk bytes; candles compress to roughly 12 bytes each in the default codec's typical case (see chunks and compression). - The WAL — every write lands here first and stays until a checkpoint reclaims it
(
wal.checkpoint_interval, 15 minutes). Budget at least one interval of peak ingest, plus segments a checkpoint cannot reclaim because a stream failed to persist. Withcheckpoint_interval: 0the WAL grows without bound. - Quarantine — never reclaimed automatically (above).
- Released partitions on a cluster node are moved to quarantine, not freed, so moving a partition away does not return its disk space.
- Retention is on by default and deletes data.
Once a stream's index holds more than
storage.compaction_entry_thresholdentries (50,000), the oldest entries and their chunk files are deleted down to half that. With the default 15-minute checkpoint a stream written live cuts about 96 chunks a day, so deletion starts after roughly 520 days and leaves roughly 260 days (an estimate from the code, not a measurement). Set the threshold to0to keep everything. It is count-based; there is no time-based retention setting. See configuration.
If the disk fills, a WAL flush that fails with ENOSPC poisons the WAL writer: every
later write fails rather than being acknowledged without being stored. Free space and
restart the node; recovery replays what was durable. The node's /health does not measure
free space, so monitor it from the host (for example with node_exporter).
Backups
There is no online backup command. A consistent copy of a single node's data directory needs the node stopped (after a clean stop the hot caches are in chunks). A copy taken while it runs is a crash image: restoring it runs crash recovery as above, which is designed for exactly that state but has not been validated as a backup procedure (unverified). In a cluster, copies of each partition on other nodes are the first line of defence; see replication.
References
Source
run,shutdown,startCheckpointLoop— the two sequences.startupCorruptionPolicy— when a corrupt index is set aside.ingestion.NewDispatcher— recovery and the final drain.- /internal/wal/recovery.go — the corruption policy.
Listener.Stop— the connection wait and force-close.Layout.QuarantinePartition.- /docs/dev-overview.md §8 — the boot and shutdown walkthrough.
Tests
TestShutdown_TheClusterPlanesStopWhileTheDataPathStillServes(/cmd/server/drain_test.go).TestShutdownDrain_PersistsEverythingToChunks(/tests/shutdown_drain_test.go).TestServerBinary_ASigtermedPrimaryUnderLoadLosesNoAckedWrite(/tests/server_binary_sigterm_test.go).TestCrash_KillDashNine,TestCrash_TicksSurviveKillDashNine(/tests/recovery_test.go).TestRecovery_TicksInShardedWALsSurviveACrash(/internal/ingestion/tick_recovery_test.go).TestRecover_MidLogCorruptionRefused(/internal/wal/recovery_test.go).TestRecovery_StartupMemoryDoesNotGrowWithTheWAL(/internal/ingestion/recovery_memory_test.go).TestServerBinary_ANodeWithACorruptStreamIndexStartsAndItsPartitionIsReplicated(/tests/server_binary_corrupt_index_test.go).TestCheckpoint_ReclaimsSegmentsAndKeepsEveryCandle(/internal/ingestion/checkpoint_test.go),TestCheckpoint_DoesNotAdvancePastAFailedPersist(/internal/ingestion/checkpoint_persist_failure_test.go).TestServerBinary_ADecommissionedNodeExitsOnItsOwn(/tests/server_binary_decommission_test.go).
Further reading
ingestion.NewDispatcherin /internal/ingestion/dispatcher.go;docs/dev-overview.md§9.1. ↩︎TestRecovery_StartupMemoryDoesNotGrowWithTheWAL. ↩︎startupCorruptionPolicyin /cmd/server/startup_quarantine.go;TestServerBinary_ANodeWithACorruptStreamIndexStartsAndItsPartitionIsReplicated. ↩︎TestCrash_KillDashNineandTestServer_AckedCandleIngestIsInWALBeforeAck(/tests/ack_durability_test.go). ↩︎