vdsl_sync/infra/topology_file_store.rs
1//! TopologyFileStore — TopologyFile永続化トレイト。
2//!
3//! TopologyFile(ファイル身元 / inode)のCRUD + ハッシュ検索。
4
5use async_trait::async_trait;
6
7use crate::domain::file_type::FileType;
8use crate::domain::topology_file::TopologyFile;
9use crate::infra::error::InfraError;
10
11/// TopologyFile永続化。
12///
13/// Topology上のファイル身元情報(canonical_hash, relative_path, file_type等)を管理する。
14/// LocationFile(各Locationでの実体情報)は [`LocationFileStore`] が管理する。
15#[async_trait]
16pub trait TopologyFileStore: Send + Sync {
17 /// TopologyFileを保存(新規 or 更新)。
18 ///
19 /// idが既存の場合はUPDATE、なければINSERT。
20 async fn upsert(&self, file: &TopologyFile) -> Result<(), InfraError>;
21
22 /// IDでTopologyFileを取得。
23 async fn get_by_id(&self, id: &str) -> Result<Option<TopologyFile>, InfraError>;
24
25 /// relative_pathでTopologyFileを取得(deleted除外)。
26 async fn get_by_path(&self, relative_path: &str) -> Result<Option<TopologyFile>, InfraError>;
27
28 /// canonical_hashでTopologyFileを検索(deleted除外)。
29 ///
30 /// rename検出で使用: スキャン結果のcontent_hashがTopologyFileのcanonical_hashに一致
31 /// すれば同一Entity。
32 async fn find_by_canonical_hash(&self, hash: &str) -> Result<Option<TopologyFile>, InfraError>;
33
34 /// 生存中(deleted_at IS NULL)のTopologyFile一覧。
35 async fn list_active(
36 &self,
37 file_type: Option<FileType>,
38 limit: Option<usize>,
39 ) -> Result<Vec<TopologyFile>, InfraError>;
40
41 /// 削除済み(deleted_at IS NOT NULL)のTopologyFile一覧。
42 ///
43 /// distribute_delete_actions()で使用: 削除済みファイルのLocationFileを掃除する。
44 async fn list_deleted(&self) -> Result<Vec<TopologyFile>, InfraError>;
45
46 /// 削除済みTFを物理削除。
47 ///
48 /// 全LocationFileのdelete transferが完了し、LFが0件になった後に呼ぶ。
49 /// B2 archived データは独立して残るため、restore_from_archiveで復元可能。
50 async fn hard_delete(&self, id: &str) -> Result<bool, InfraError>;
51
52 /// 生存中ファイル数。
53 async fn count_active(&self) -> Result<usize, InfraError>;
54
55 /// 全TopologyFileのrelative_path一覧(deleted除外)。
56 ///
57 /// スキャン結果との差分でVanished検出に使用。
58 async fn list_active_paths(&self) -> Result<Vec<String>, InfraError>;
59}