risingwave_common/session_config/locality_backfill_mode.rs
1// Copyright 2026 RisingWave Labs
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! Locality backfill mode for streaming queries.
16
17use std::fmt::Formatter;
18use std::str::FromStr;
19
20#[derive(Copy, Default, Debug, Clone, PartialEq, Eq)]
21pub enum LocalityBackfillMode {
22 #[default]
23 Auto,
24
25 Always,
26}
27
28impl FromStr for LocalityBackfillMode {
29 type Err = &'static str;
30
31 fn from_str(s: &str) -> Result<Self, Self::Err> {
32 if s.eq_ignore_ascii_case("auto") {
33 Ok(Self::Auto)
34 } else if s.eq_ignore_ascii_case("always") {
35 Ok(Self::Always)
36 } else {
37 Err("expect one of [auto, always]")
38 }
39 }
40}
41
42impl std::fmt::Display for LocalityBackfillMode {
43 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
44 match self {
45 Self::Auto => write!(f, "auto"),
46 Self::Always => write!(f, "always"),
47 }
48 }
49}