linkrs_query/executor/streaming/
state.rs1use super::operators::state::{
15 BlockingState, ExchangeState, FulltextState, GraphState, JoinState, SetState, SinkState,
16 SourceState, TxnState, VectorState,
17};
18
19pub type TaskId = usize;
21
22#[derive(Debug)]
28pub enum GlobalState {
29 Source(SourceState),
30 Blocking(Box<BlockingState>),
31 Join(JoinState),
32 Graph(GraphState),
33 Sink(SinkState),
34 Set(SetState),
35 Exchange(ExchangeState),
36 Fulltext(FulltextState),
37 Vector(VectorState),
38 Txn(TxnState),
39}
40
41#[derive(Debug)]
51pub enum LocalState {
52 Source(SourceState),
53 Blocking(Box<BlockingState>),
54 Join(JoinState),
55 Graph(GraphState),
56 Sink(SinkState),
57 Set(SetState),
58 Exchange(ExchangeState),
59 Fulltext(FulltextState),
60 Vector(VectorState),
61 Txn(TxnState),
62}
63
64#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
69pub struct GlobalStateKey(
70 pub crate::executor::streaming::plan::types::PhysicalOperatorId,
71 pub Option<usize>,
72);
73
74#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
76pub struct LocalStateKey(
77 pub crate::executor::streaming::plan::types::PhysicalOperatorId,
78 pub Option<usize>,
79 pub TaskId,
80);
81
82#[derive(Debug, Default)]
89pub struct GlobalStateArena {
90 states: std::collections::HashMap<GlobalStateKey, GlobalState>,
91}
92
93impl GlobalStateArena {
94 pub fn new() -> Self {
95 Self {
96 states: std::collections::HashMap::new(),
97 }
98 }
99
100 pub fn insert(&mut self, key: GlobalStateKey, state: GlobalState) {
102 self.states.insert(key, state);
103 }
104
105 pub fn get(&self, key: &GlobalStateKey) -> Option<&GlobalState> {
107 self.states.get(key)
108 }
109
110 pub fn get_mut(&mut self, key: &GlobalStateKey) -> Option<&mut GlobalState> {
112 self.states.get_mut(key)
113 }
114
115 pub fn remove(&mut self, key: &GlobalStateKey) -> Option<GlobalState> {
117 self.states.remove(key)
118 }
119
120 pub fn clear(&mut self) {
122 self.states.clear();
123 }
124
125 pub fn len(&self) -> usize {
127 self.states.len()
128 }
129
130 pub fn is_empty(&self) -> bool {
131 self.states.is_empty()
132 }
133}
134
135#[derive(Debug, Default)]
142pub struct LocalStateArena {
143 states: std::collections::HashMap<LocalStateKey, LocalState>,
144}
145
146impl LocalStateArena {
147 pub fn new() -> Self {
148 Self {
149 states: std::collections::HashMap::new(),
150 }
151 }
152
153 pub fn insert(&mut self, key: LocalStateKey, state: LocalState) {
155 self.states.insert(key, state);
156 }
157
158 pub fn get(&self, key: &LocalStateKey) -> Option<&LocalState> {
160 self.states.get(key)
161 }
162
163 pub fn get_mut(&mut self, key: &LocalStateKey) -> Option<&mut LocalState> {
165 self.states.get_mut(key)
166 }
167
168 pub fn remove(&mut self, key: &LocalStateKey) -> Option<LocalState> {
170 self.states.remove(key)
171 }
172
173 pub fn clear_operator(
175 &mut self,
176 op_id: &crate::executor::streaming::plan::types::PhysicalOperatorId,
177 ) {
178 self.states.retain(|k, _| k.0 != *op_id);
179 }
180
181 pub fn clear(&mut self) {
183 self.states.clear();
184 }
185
186 pub fn len(&self) -> usize {
188 self.states.len()
189 }
190
191 pub fn is_empty(&self) -> bool {
192 self.states.is_empty()
193 }
194}
195
196#[derive(Debug, Default)]
200pub struct StateArenaSet {
201 pub global: GlobalStateArena,
202 pub local: LocalStateArena,
203}
204
205impl StateArenaSet {
206 pub fn new() -> Self {
207 Self {
208 global: GlobalStateArena::new(),
209 local: LocalStateArena::new(),
210 }
211 }
212
213 pub fn clear(&mut self) {
215 self.global.clear();
216 self.local.clear();
217 }
218}