risingwave_object_store/object/opendal_engine/
fs.rs

1// Copyright 2023 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::sync::Arc;
16
17use opendal::Operator;
18use opendal::layers::LoggingLayer;
19use opendal::services::Fs;
20use risingwave_common::config::ObjectStoreConfig;
21
22use super::{MediaType, OpendalObjectStore, new_operator};
23use crate::object::ObjectResult;
24use crate::object::object_metrics::ObjectStoreMetrics;
25use crate::object::opendal_engine::ATOMIC_WRITE_DIR;
26
27impl OpendalObjectStore {
28    /// create opendal fs engine.
29    pub fn new_fs_engine(
30        root: String,
31        config: Arc<ObjectStoreConfig>,
32        metrics: Arc<ObjectStoreMetrics>,
33    ) -> ObjectResult<Self> {
34        // Create fs backend builder.
35        let mut builder = Fs::default().root(&root);
36        if config.set_atomic_write_dir {
37            let atomic_write_dir = format!("{}/{}", root, ATOMIC_WRITE_DIR);
38            builder = builder.atomic_write_dir(&atomic_write_dir);
39        }
40
41        let op = new_operator(
42            &config,
43            Operator::new(builder)?.layer(LoggingLayer::default()),
44        );
45
46        Ok(Self {
47            op,
48            media_type: MediaType::Fs,
49            config,
50            metrics,
51        })
52    }
53}