Expand description
mira proxy: one read and write surface in front of N storage nodes.
§Why this can hold no state
The thing that usually forces a coordinator on a fan-out query is paging: N
nodes each answer “the newest 100” and the merger has to remember, for every
reader, how far into each node’s stream it had got. Mira does not need that,
and the reason is Cursor. A cursor is (ts, node, seq, row) where node
is mira_core::block::node_id — so it is already a global total order
over every row on every replica, with no coordination anywhere, and it was
that before this file existed.
So the whole protocol is: send the same after cursor to every replica, ask
each for the newest limit rows behind it, merge the answers on that same
order, drop repeated cursors, cut to limit, and hand back the cursor of
the last row emitted. Every row not emitted sorts strictly after that cursor
on every replica, so the next page is exact — no duplicates, no gaps — and
the proxy has forgotten the reader by the time the response is written.
Principle 4 is satisfied by construction rather than by care.
The repeats are not a paging failure but a placement one, and they are
expected rather than exceptional. node in a cursor names the writer, so
one block reachable from two replicas is answered for twice with the same
cursor: that is the steady state of shared-volume mode (section 12.5), where
every replica’s scan sees every writer’s blocks, and the transient state of
a block being re-homed (section 6.1). Equal cursors are the same row and
never a collision, so merge keeps one and the promise above holds.
§What it refuses
/api/v1/query and the three OTLP endpoints, and nothing else. correlate,
map, metrics/query, metrics/names and entities all answer with
something built by walking one node’s blocks — a trace assembled from the spans that are local,
a service map from the edges that are local. Merging those is not “sort and
cut”: two nodes each holding half a trace produce two partial frames, and
there is no cursor to interleave them on. So this proxy answers 501 and says
which endpoint to call directly. A plausible subset is the failure mode
identity.rs refuses a hash for, and it would be worse here, because
nothing in the response would say it was partial.
§Where the reads are not merged, the writes are placed
Ingest routes on resource_key, the same 64-bit entity identity the
storage layer already joins on, so one entity’s records land on one replica.
That is not for the query path above — that one fans out regardless — it is
so each replica’s blocks stay entity-local: the _entity block filter keeps
its selectivity, and “everything this pod emitted” remains a question one
node can answer completely, which is what the 501 above is holding the door
open for.
Macros§
- ingest 🔒
- The three OTLP endpoints differ only in which types they name.
Structs§
- Proxy
- The replica list, resolved once at startup and never revisited.
Constants§
- PROTOBUF 🔒
- REPLICA_
TIMEOUT 🔒 - How long a replica has to answer.
- TEXT 🔒
Functions§
- accepted 🔒
- client 🔒
- One pooled client for the process, keep-alive included: a fresh TCP handshake per replica per query is most of the latency of a small one.
- count 🔒
- fail 🔒
- The same JSON error body a node returns, under a status this file picks.
- fanout 🔒
- The same body to every replica, concurrently.
- field 🔒
- field_
of 🔒 - One
"key": valuepiece of an object. - json_ok 🔒
- logs_
handler 🔒 - merge 🔒
- Interleave the replicas’ pages on the cursor order and cut to
limit. - metrics_
handler 🔒 - object 🔒
- Split a JSON object into its keys and the raw text of their values.
- pieces 🔒
- The comma-separated pieces inside one
[...]or{...}, as slices. - query_
handler 🔒 - Fan a record search out to every replica and merge the pages.
- retryable 🔒
- A replica’s status, mapped to what this proxy should tell the exporter.
- router
- scatter 🔒
- Send each sub-export to its replica and answer once they all have.
- send 🔒
- slot 🔒
- Which replica a resource’s records belong on.
- text 🔒
- A replica’s error body, for quoting back inside this proxy’s own.
- traces_
handler 🔒 - unmergeable 🔒
- unquote 🔒
- up 🔒
- Liveness and readiness, which for a stateless fan-out are the same answer.
- with_
cursors 🔒 - The caller’s document with
cursorsadded.