pub(crate) fn process_scan_payload(
payload: &[u8],
channel: u8,
asset: u32,
parquet_root: &Path,
active_calibration: &CalibrationSpec,
rotate_secs: u64,
logger: &mut Option<ParquetLogger>,
file_index: &mut usize,
last_sequence: &mut Option<u64>,
) -> CloseOutcomeExpand description
Decodes one FlatBuffer scan payload and writes its samples to Parquet.
The payload contains the first sample timestamp plus a fixed interval, so this function reconstructs each sample timestamp and rotates files at aligned source-time windows and UTC date changes. The returned outcome tells the caller which buffered JetStream messages are now safe to ack.
Before each sample, the open file is closed and a new one opened (with the next
free part index) when there is no open file, when the sample’s UTC date differs
from the file’s, or when ParquetLogger::should_rotate_before says so. A single
payload can therefore close a file part way through. The check is made once per run
of samples rather than once per sample: ParquetLogger::write_run buffers, in one
go, as many of the following samples as the open file accepts. The files and row
groups are the same as with a check per sample.
Sequence gaps and resets are logged but do not stop the write. A payload that is
not a valid FlatBuffer Scan is logged and writes nothing. If a sample timestamp
overflows, the rest of that payload is dropped. If closing a file or writing a row
group fails, the failure is counted in the outcome and the rest of the payload is
skipped, since the message will be redelivered.
§Arguments
payload- FlatBufferScanbytes from one JetStream message.channel- LabJack channel the payload belongs to.asset- Asset number for output paths.parquet_root- Root output directory.active_calibration- Calibration stored in any file opened here.rotate_secs- Rotation window length in seconds.logger- Open file of the channel, if any; replaced when the file rotates.file_index- Part index of the open file; updated when a new file is opened.last_sequence- Sequence number of the previous scan, for gap detection; updated to this scan’s sequence.
§Returns
How many files were closed and how many closes failed while writing this payload.
§Panics
Panics if a new file cannot be created (see ParquetLogger::new and
next_file_index).