nodedb_cluster/metadata_group/state.rs
1//! Lifecycle state of a schema descriptor.
2//!
3//! The `DescriptorState` enum is the one-step-at-a-time state machine that
4//! lets in-flight DML observe a safe view of the schema during online DDL.
5//! Every descriptor carries its current state; the
6//! [`crate::metadata_group::cache::MetadataCache`] exposes the state to
7//! planners so they can reject plans that would observe a partially-applied
8//! change.
9
10use serde::{Deserialize, Serialize};
11
12/// Lifecycle state of a descriptor.
13#[derive(
14 Debug,
15 Clone,
16 PartialEq,
17 Eq,
18 Serialize,
19 Deserialize,
20 zerompk::ToMessagePack,
21 zerompk::FromMessagePack,
22)]
23pub enum DescriptorState {
24 /// Fully visible to reads and writes.
25 Public,
26 /// A new column/field is being added at the given descriptor version.
27 AddingField { since_version: u64 },
28 /// A column/field is being removed at the given descriptor version.
29 DroppingField { since_version: u64 },
30 /// The entire descriptor is being dropped; visible only for in-flight
31 /// queries planned before `since_version`.
32 Dropping { since_version: u64 },
33 /// An index or MV is being rebuilt offline.
34 OfflineRebuilding,
35}
36
37impl DescriptorState {
38 pub fn is_public(&self) -> bool {
39 matches!(self, DescriptorState::Public)
40 }
41}