1use std::path::PathBuf;
4
5use waratah_stats::{attach_catalog_stats_collector, attach_stats_collector};
6use waratah_storage::{
7 MAIN_REPOSITORY_ID, PartitionAxis, RocksDbOptionsHooks, SnapshotId, Storage, hexastore_data_dir,
8};
9
10use crate::error::DevError;
11
12pub fn rebuild(data_dir: PathBuf) -> Result<(), DevError> {
17 let s_dir = hexastore_data_dir(&data_dir, MAIN_REPOSITORY_ID, PartitionAxis::S);
18 let store = Storage::open_rocksdb_with_hooks(
19 &s_dir,
20 PartitionAxis::S,
21 RocksDbOptionsHooks {
22 configure_cf: Some(&attach_stats_collector),
23 configure_catalog_cf: Some(&attach_catalog_stats_collector),
24 ..Default::default()
25 },
26 )?;
27 let stats = store.rebuild_named_graph_catalog()?;
28 store.flush_memtables()?;
29 store.compact_range();
30 let present = store.list_named_graphs(SnapshotId::latest())?.len();
31 println!(
32 "named-graph catalog rebuild: inserted {} graph(s), skipped {} already present, {} present",
33 stats.graphs_inserted, stats.graphs_skipped, present
34 );
35 Ok(())
36}