use super::operators::state::{
BlockingState, ExchangeState, FulltextState, GraphState, JoinState, SetState, SinkState,
SourceState, TxnState, VectorState,
};
pub type TaskId = usize;
#[derive(Debug)]
pub enum GlobalState {
Source(SourceState),
Blocking(Box<BlockingState>),
Join(JoinState),
Graph(GraphState),
Sink(SinkState),
Set(SetState),
Exchange(ExchangeState),
Fulltext(FulltextState),
Vector(VectorState),
Txn(TxnState),
}
#[derive(Debug)]
pub enum LocalState {
Source(SourceState),
Blocking(Box<BlockingState>),
Join(JoinState),
Graph(GraphState),
Sink(SinkState),
Set(SetState),
Exchange(ExchangeState),
Fulltext(FulltextState),
Vector(VectorState),
Txn(TxnState),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct GlobalStateKey(
pub crate::executor::streaming::plan::types::PhysicalOperatorId,
pub Option<usize>,
);
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct LocalStateKey(
pub crate::executor::streaming::plan::types::PhysicalOperatorId,
pub Option<usize>,
pub TaskId,
);
#[derive(Debug, Default)]
pub struct GlobalStateArena {
states: std::collections::HashMap<GlobalStateKey, GlobalState>,
}
impl GlobalStateArena {
pub fn new() -> Self {
Self {
states: std::collections::HashMap::new(),
}
}
pub fn insert(&mut self, key: GlobalStateKey, state: GlobalState) {
self.states.insert(key, state);
}
pub fn get(&self, key: &GlobalStateKey) -> Option<&GlobalState> {
self.states.get(key)
}
pub fn get_mut(&mut self, key: &GlobalStateKey) -> Option<&mut GlobalState> {
self.states.get_mut(key)
}
pub fn remove(&mut self, key: &GlobalStateKey) -> Option<GlobalState> {
self.states.remove(key)
}
pub fn clear(&mut self) {
self.states.clear();
}
pub fn len(&self) -> usize {
self.states.len()
}
pub fn is_empty(&self) -> bool {
self.states.is_empty()
}
}
#[derive(Debug, Default)]
pub struct LocalStateArena {
states: std::collections::HashMap<LocalStateKey, LocalState>,
}
impl LocalStateArena {
pub fn new() -> Self {
Self {
states: std::collections::HashMap::new(),
}
}
pub fn insert(&mut self, key: LocalStateKey, state: LocalState) {
self.states.insert(key, state);
}
pub fn get(&self, key: &LocalStateKey) -> Option<&LocalState> {
self.states.get(key)
}
pub fn get_mut(&mut self, key: &LocalStateKey) -> Option<&mut LocalState> {
self.states.get_mut(key)
}
pub fn remove(&mut self, key: &LocalStateKey) -> Option<LocalState> {
self.states.remove(key)
}
pub fn clear_operator(
&mut self,
op_id: &crate::executor::streaming::plan::types::PhysicalOperatorId,
) {
self.states.retain(|k, _| k.0 != *op_id);
}
pub fn clear(&mut self) {
self.states.clear();
}
pub fn len(&self) -> usize {
self.states.len()
}
pub fn is_empty(&self) -> bool {
self.states.is_empty()
}
}
#[derive(Debug, Default)]
pub struct StateArenaSet {
pub global: GlobalStateArena,
pub local: LocalStateArena,
}
impl StateArenaSet {
pub fn new() -> Self {
Self {
global: GlobalStateArena::new(),
local: LocalStateArena::new(),
}
}
pub fn clear(&mut self) {
self.global.clear();
self.local.clear();
}
}