risingwave_object_store/object/opendal_engine/
fs.rs1use 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};
23use crate::object::ObjectResult;
24use crate::object::object_metrics::ObjectStoreMetrics;
25use crate::object::opendal_engine::ATOMIC_WRITE_DIR;
26
27impl OpendalObjectStore {
28 pub fn new_fs_engine(
30 root: String,
31 config: Arc<ObjectStoreConfig>,
32 metrics: Arc<ObjectStoreMetrics>,
33 ) -> ObjectResult<Self> {
34 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: Operator = Operator::new(builder)?
42 .layer(LoggingLayer::default())
43 .finish();
44 Ok(Self {
45 op,
46 media_type: MediaType::Fs,
47 config,
48 metrics,
49 })
50 }
51}