Skip to main content

linkrs_storage/client/
traits_schema.rs

1//! Schema evolution, context and recovery operations.
2
3use linkrs_core::metadata::{IndexMetadataManager, SchemaManager};
4use linkrs_core::types::{EdgeTypeInfo, Index, LabelId, PropertyDef, SpaceInfo, TagInfo};
5use linkrs_core::{StorageError, StorageResult};
6use linkrs_transaction::wal::recovery::{RecoveryConfig, RecoveryStats};
7use std::sync::Arc;
8
9/// Schema/space/tag/edge-type/index DDL operations.
10pub trait StorageSchemaOps: Send + Sync + std::fmt::Debug {
11    fn create_space(&mut self, space: &mut SpaceInfo) -> Result<bool, StorageError>;
12    fn drop_space(&mut self, space: &str) -> Result<bool, StorageError>;
13    fn clear_space(&mut self, space: &str) -> Result<bool, StorageError>;
14
15    fn create_tag(&mut self, space: &str, tag: &TagInfo) -> Result<u32, StorageError>;
16    fn create_tag_with_estimate(
17        &mut self,
18        space: &str,
19        tag: &TagInfo,
20        estimated_rows: Option<u64>,
21    ) -> Result<u32, StorageError> {
22        let _ = estimated_rows;
23        self.create_tag(space, tag)
24    }
25    fn alter_tag(
26        &mut self,
27        space: &str,
28        tag: &str,
29        additions: Vec<PropertyDef>,
30        deletions: Vec<String>,
31        new_comment: Option<String>,
32    ) -> Result<bool, StorageError>;
33    fn rename_vertex_property(
34        &mut self,
35        label: LabelId,
36        old_name: &str,
37        new_name: &str,
38    ) -> Result<(), StorageError>;
39    fn rename_tag_property(
40        &mut self,
41        space: &str,
42        tag: &str,
43        old_name: &str,
44        new_name: &str,
45    ) -> Result<bool, StorageError>;
46    fn rename_tag(
47        &mut self,
48        space: &str,
49        old_name: &str,
50        new_name: &str,
51    ) -> Result<bool, StorageError>;
52    fn drop_tag(&mut self, space: &str, tag: &str) -> Result<bool, StorageError>;
53
54    fn create_edge_type(&mut self, space: &str, edge: &EdgeTypeInfo) -> Result<u32, StorageError>;
55    fn alter_edge_type(
56        &mut self,
57        space: &str,
58        edge_type: &str,
59        additions: Vec<PropertyDef>,
60        deletions: Vec<String>,
61        new_comment: Option<String>,
62    ) -> Result<bool, StorageError>;
63    fn rename_edge_property(
64        &mut self,
65        space: &str,
66        edge_type: &str,
67        old_name: &str,
68        new_name: &str,
69    ) -> Result<bool, StorageError>;
70    fn rename_edge_type(
71        &mut self,
72        space: &str,
73        old_name: &str,
74        new_name: &str,
75    ) -> Result<bool, StorageError>;
76    fn update_edge_endpoints(
77        &mut self,
78        space: &str,
79        edge_type: &str,
80        src_tag_name: &str,
81        dst_tag_name: &str,
82    ) -> Result<bool, StorageError>;
83    fn drop_edge_type(&mut self, space: &str, edge_type: &str) -> Result<bool, StorageError>;
84
85    fn create_tag_index(&mut self, space: &str, info: &Index) -> Result<bool, StorageError>;
86    fn drop_tag_index(&mut self, space: &str, index: &str) -> Result<bool, StorageError>;
87    fn rebuild_tag_index(&mut self, space: &str, index: &str) -> Result<bool, StorageError>;
88
89    fn create_edge_index(&mut self, space: &str, info: &Index) -> Result<bool, StorageError>;
90    fn drop_edge_index(&mut self, space: &str, index: &str) -> Result<bool, StorageError>;
91    fn rebuild_edge_index(&mut self, space: &str, index: &str) -> Result<bool, StorageError>;
92}
93
94/// Access to persistent schema context shared with higher-level components.
95pub trait StorageSchemaContextOps: Send + Sync + std::fmt::Debug {
96    fn get_schema_manager(&self) -> Option<Arc<SchemaManager>>;
97    fn get_index_metadata_manager(&self) -> Option<Arc<dyn IndexMetadataManager>>;
98}
99
100/// WAL recovery operations.
101pub trait StorageRecoveryOps: Send + Sync + std::fmt::Debug {
102    fn needs_recovery(&self) -> bool;
103
104    fn recover_from_wal(&self) -> StorageResult<RecoveryStats>;
105
106    fn recover_from_wal_with_config(&self, config: RecoveryConfig) -> StorageResult<RecoveryStats>;
107
108    fn init_with_recovery(&self) -> StorageResult<Option<RecoveryStats>> {
109        if self.needs_recovery() {
110            let stats = self.recover_from_wal()?;
111            Ok(Some(stats))
112        } else {
113            Ok(None)
114        }
115    }
116}