Expand description
Counting a transcript’s lines once, off the request path.
A transcript with no line epoch (filestore/counter.rs) cannot open: agent:open_tail has no line
positions to give, and output.idx cannot be labelled with a generation, so the index is rebuilt
from byte 0 on every read and, while the file grows under it, never serves one. On a gigabyte
transcript each rebuild is seconds, and the read is then refused. An epoch is lost when bytes inside
the file are rewritten (a fork’s copy is signed in place) or an older build appends past the
catch-up window.
Starting the epoch is one scan of the file (FileStore::init_line_counter), which takes the
connection lock one window at a time. This module makes sure it runs once per file at a time:
readers that find no epoch start the count if none is running, then wait for it a little (or answer
“counting” and let the pane ask again), instead of each starting their own scan or rebuilding the
index.
Functions§
- ensure_
counted zone’soutputcounted: true when it has an epoch withinwait. Cheap when it already has one (or only needs catching up); otherwise the count starts if none is running and is waited for. False means it is still being counted, or could not be (the file moved under the scan): ask again later.- flight_
key - The key of
zone‘s count infs: the store by identity, so two stores’ zones of one name stay apart. - run_
once - Run
workon a thread of its own unless a flight forkeyis already running, and wait up towaitfor it. True when the flight ended in that time.