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