Skip to main content

waratah/
temporal.rs

1//! Offline temporal index maintenance (`waratah temporal rebuild-index`).
2//!
3//! The rebuild itself is a PARTITION-side walk ([`waratah_partition::
4//! rebuild_temporal_index_storage`]) — the same routine the O partition
5//! executes over RPC for compute startup's auto-rebuild. This CLI opens
6//! `{data_dir}/main/o` in-process (no gRPC), runs the walk under the given
7//! covering config, and reports the posting count and stamped epoch. The
8//! histogram cut is refreshed in memory and lands in SSTs on the next
9//! flush/compaction of the stats collector.
10
11use std::path::Path;
12
13use crate::DevError;
14
15/// Run the rebuild over an offline data-dir's O store (partition-side walk,
16/// in-process; no gRPC).
17pub fn rebuild_offline(data_dir: &Path) -> Result<(), DevError> {
18    let o_path = waratah_storage::hexastore_data_dir(
19        data_dir,
20        waratah_storage::MAIN_REPOSITORY_ID,
21        waratah_storage::PartitionAxis::O,
22    );
23    if !o_path.exists() {
24        return Err(DevError::TemporalRebuild(format!(
25            "no O store at {}",
26            o_path.display()
27        )));
28    }
29    let storage =
30        waratah_storage::Storage::open_rocksdb(&o_path, waratah_storage::PartitionAxis::O)?;
31    let stats = std::sync::Mutex::new(waratah_stats::ShardStats::memory());
32    let posted = waratah_partition::rebuild_temporal_index_storage(
33        &storage,
34        &stats,
35        waratah_temporal::ingest_coverer_config(),
36    )
37    .map_err(|error| DevError::TemporalRebuild(error.to_string()))?;
38    let epoch = storage.temporal_index_epoch()?.unwrap_or(0);
39    println!("temporal rebuild-index: {posted} postings, epoch {epoch}");
40    Ok(())
41}