Skip to main content

linkrs_core/wal/
redo.rs

1//! WAL Redo Log Types
2//!
3//! Redo log entry types for WAL replay during recovery.
4//! All vertex references use unified VertexId (supports both int64 and string IDs).
5
6use serde::{Deserialize, Serialize};
7use std::sync::Arc;
8
9use crate::types::{LabelId, SpaceInfo, VertexId};
10use crate::Value;
11
12// ============================================================================
13// Data Operations
14// ============================================================================
15
16#[derive(Debug, Clone, Serialize, Deserialize)]
17pub struct InsertVertexRedo {
18    pub label: LabelId,
19    pub vid: VertexId,
20    pub properties: Vec<(Arc<str>, Value)>,
21}
22
23#[derive(Debug, Clone, Serialize, Deserialize)]
24pub struct InsertEdgeRedo {
25    pub src_label: LabelId,
26    pub src_vid: VertexId,
27    pub dst_label: LabelId,
28    pub dst_vid: VertexId,
29    pub edge_label: LabelId,
30    pub rank: i64,
31    pub properties: Vec<(Arc<str>, Value)>,
32}
33
34#[derive(Debug, Clone, Serialize, Deserialize)]
35pub struct UpdateVertexPropRedo {
36    pub label: LabelId,
37    pub vid: VertexId,
38    pub prop_name: std::sync::Arc<str>,
39    pub value: Value,
40}
41
42#[derive(Debug, Clone, Serialize, Deserialize)]
43pub struct UpdateEdgePropRedo {
44    pub src_label: LabelId,
45    pub src_vid: VertexId,
46    pub dst_label: LabelId,
47    pub dst_vid: VertexId,
48    pub edge_label: LabelId,
49    pub rank: i64,
50    pub prop_name: std::sync::Arc<str>,
51    pub value: Value,
52}
53
54#[derive(Debug, Clone, Serialize, Deserialize)]
55pub struct DeleteVertexRedo {
56    pub label: LabelId,
57    pub vid: VertexId,
58}
59
60#[derive(Debug, Clone, Serialize, Deserialize)]
61pub struct DeleteEdgeRedo {
62    pub src_label: LabelId,
63    pub src_vid: VertexId,
64    pub dst_label: LabelId,
65    pub dst_vid: VertexId,
66    pub edge_label: LabelId,
67    pub rank: i64,
68}
69
70// ============================================================================
71// Schema Operations
72// ============================================================================
73
74#[derive(Debug, Clone, Serialize, Deserialize)]
75pub struct CreateSpaceRedo {
76    pub space: SpaceInfo,
77}
78
79#[derive(Debug, Clone, Serialize, Deserialize)]
80pub struct DropSpaceRedo {
81    pub space_name: String,
82}
83
84#[derive(Debug, Clone, Serialize, Deserialize)]
85pub struct ClearSpaceRedo {
86    pub space_name: String,
87}
88
89#[derive(Debug, Clone, Serialize, Deserialize)]
90pub struct CreateVertexTypeRedo {
91    pub space_name: String,
92    pub label_id: Option<LabelId>,
93    pub label_name: String,
94    /// (property name, type name, is_serial) triples.
95    pub schema: Vec<(String, String, bool)>,
96}
97
98#[derive(Debug, Clone, Serialize, Deserialize)]
99pub struct CreateEdgeTypeRedo {
100    pub space_name: String,
101    pub label_id: Option<LabelId>,
102    pub src_label: String,
103    pub dst_label: String,
104    pub edge_label: String,
105    /// (property name, type name, is_serial) triples.
106    pub schema: Vec<(String, String, bool)>,
107}
108
109#[derive(Debug, Clone, Serialize, Deserialize)]
110pub struct DeleteVertexTypeRedo {
111    pub space_name: Option<String>,
112    pub label_name: String,
113}
114
115#[derive(Debug, Clone, Serialize, Deserialize)]
116pub struct DeleteEdgeTypeRedo {
117    pub space_name: Option<String>,
118    pub src_label: String,
119    pub dst_label: String,
120    pub edge_label: String,
121}
122
123#[derive(Debug, Clone, Serialize, Deserialize)]
124pub struct AddVertexPropRedo {
125    pub label: LabelId,
126    /// (property name, type name, is_serial) triples.
127    pub properties: Vec<(String, String, bool)>,
128    #[serde(default)]
129    pub new_comment: Option<String>,
130}
131
132#[derive(Debug, Clone, Serialize, Deserialize)]
133pub struct AddEdgePropRedo {
134    pub src_label: LabelId,
135    pub dst_label: LabelId,
136    pub edge_label: LabelId,
137    /// (property name, type name, is_serial) triples.
138    pub properties: Vec<(String, String, bool)>,
139    #[serde(default)]
140    pub new_comment: Option<String>,
141}
142
143#[derive(Debug, Clone, Serialize, Deserialize)]
144pub struct DeleteVertexPropRedo {
145    pub label: LabelId,
146    pub prop_names: Vec<std::sync::Arc<str>>,
147}
148
149#[derive(Debug, Clone, Serialize, Deserialize)]
150pub struct DeleteEdgePropRedo {
151    pub src_label: LabelId,
152    pub dst_label: LabelId,
153    pub edge_label: LabelId,
154    pub prop_names: Vec<std::sync::Arc<str>>,
155}
156
157#[derive(Debug, Clone, Serialize, Deserialize)]
158pub struct DeleteVertexPropsRedo {
159    pub label: LabelId,
160    pub vid: VertexId,
161    pub prop_names: Vec<std::sync::Arc<str>>,
162}
163
164#[derive(Debug, Clone, Serialize, Deserialize)]
165pub struct RenameVertexPropRedo {
166    pub label: LabelId,
167    pub old_name: String,
168    pub new_name: String,
169}
170
171#[derive(Debug, Clone, Serialize, Deserialize)]
172pub struct RenameEdgePropRedo {
173    pub src_label: LabelId,
174    pub dst_label: LabelId,
175    pub edge_label: LabelId,
176    pub old_name: String,
177    pub new_name: String,
178}
179
180#[derive(Debug, Clone, Serialize, Deserialize)]
181pub struct RenameTagRedo {
182    pub space_id: u64,
183    pub old_name: String,
184    pub new_name: String,
185}
186
187#[derive(Debug, Clone, Serialize, Deserialize)]
188pub struct RenameEdgeTypeRedo {
189    pub space_id: u64,
190    pub old_name: String,
191    pub new_name: String,
192}
193
194#[derive(Debug, Clone, Serialize, Deserialize)]
195pub struct CreateTagIndexRedo {
196    pub space_id: u64,
197    pub index_name: String,
198    pub fields: Vec<(String, String)>,
199    pub properties: Vec<String>,
200    pub is_unique: bool,
201}
202
203#[derive(Debug, Clone, Serialize, Deserialize)]
204pub struct DropTagIndexRedo {
205    pub space_id: u64,
206    pub index_name: String,
207}
208
209#[derive(Debug, Clone, Serialize, Deserialize)]
210pub struct CreateEdgeIndexRedo {
211    pub space_id: u64,
212    pub index_name: String,
213    pub fields: Vec<(String, String)>,
214    pub properties: Vec<String>,
215    pub is_unique: bool,
216}
217
218#[derive(Debug, Clone, Serialize, Deserialize)]
219pub struct DropEdgeIndexRedo {
220    pub space_id: u64,
221    pub index_name: String,
222}
223
224// Compact has no redo data (just timestamp in the WAL header).
225// A struct exists for completeness but carries no payload.
226#[derive(Debug, Clone, Serialize, Deserialize)]
227pub struct CompactRedo;
228
229// ============================================================================
230// Sequence Operations
231// ============================================================================
232
233/// Redo record for sequence (auto-increment) counter updates.
234///
235/// When a transaction allocates SERIAL values, the counter state is logged
236/// to the WAL so that recovery can re-seed the allocator to at least the
237/// allocated high-water mark, preventing duplicate id generation after crash.
238#[derive(Debug, Clone, Serialize, Deserialize)]
239pub struct UpdateSequenceRedo {
240    pub space_id: u64,
241    pub table_name: String,
242    pub next_value: u64,
243}
244
245// ============================================================================
246// Macro / Type-alias catalog operations
247// ============================================================================
248
249/// Redo record for `CREATE MACRO`.
250///
251/// Replayed by inserting (or overwriting) the macro definition in the macro
252/// catalog; recovery is last-writer-wins.
253#[derive(Debug, Clone, Serialize, Deserialize)]
254pub struct CreateMacroRedo {
255    pub space_name: String,
256    pub name: String,
257    pub params: Vec<crate::metadata::MacroParamDef>,
258    pub body: crate::types::expr::Expression,
259}
260
261/// Redo record for `DROP MACRO`.
262///
263/// Replayed by removing the macro definition if present (idempotent).
264#[derive(Debug, Clone, Serialize, Deserialize)]
265pub struct DropMacroRedo {
266    pub space_name: String,
267    pub name: String,
268}
269
270/// Redo record for `CREATE TYPE` (type alias).
271///
272/// Replayed by inserting (or overwriting) the alias in the type catalog.
273#[derive(Debug, Clone, Serialize, Deserialize)]
274pub struct CreateTypeAliasRedo {
275    pub space_name: String,
276    pub name: String,
277    pub underlying: String,
278}
279
280/// Redo record for `DROP TYPE` (type alias).
281///
282/// Replayed by removing the alias if present (idempotent).
283#[derive(Debug, Clone, Serialize, Deserialize)]
284pub struct DropTypeAliasRedo {
285    pub space_name: String,
286    pub name: String,
287}