risingwave_common/util/batch_spill_config.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
15use std::path::{Path, PathBuf};
16use std::sync::LazyLock;
17
18const RW_BATCH_SPILL_DIR_ENV: &str = "RW_BATCH_SPILL_DIR";
19const DEFAULT_SPILL_DIR: &str = "/tmp";
20
21/// Returns the base directory for spill (env value or default)
22pub fn batch_spill_base_dir() -> &'static Path {
23 static BASE_DIR: LazyLock<PathBuf> = LazyLock::new(|| {
24 let raw =
25 std::env::var(RW_BATCH_SPILL_DIR_ENV).unwrap_or_else(|_| DEFAULT_SPILL_DIR.to_owned());
26 let mut dir = PathBuf::from(raw.trim());
27 if dir.is_relative() {
28 dir = std::env::current_dir().unwrap().join(dir);
29 }
30 dir
31 });
32 BASE_DIR.as_path()
33}