Skip to main content

Module counting

Module counting 

Source
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’s output counted: true when it has an epoch within wait. 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 in fs: the store by identity, so two stores’ zones of one name stay apart.
run_once
Run work on a thread of its own unless a flight for key is already running, and wait up to wait for it. True when the flight ended in that time.