Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#5982] feat (gvfs-fuse): Implement Gravitino fileset file system #5984

Merged
merged 72 commits into from
Dec 31, 2024
Merged
Show file tree
Hide file tree
Changes from 67 commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
f025216
Add SimpleFilesystem
diqiu50 Dec 17, 2024
97e066d
Update
diqiu50 Dec 17, 2024
d0b6958
Add uts
diqiu50 Dec 17, 2024
3769400
Fix test error
diqiu50 Dec 17, 2024
3ecb980
Update comments
diqiu50 Dec 17, 2024
4fe58f2
Fix ci error
diqiu50 Dec 17, 2024
a55bff8
Add description of gvfs-fuse filesystem struct
diqiu50 Dec 18, 2024
58922e1
Update
diqiu50 Dec 18, 2024
cda8275
Update
diqiu50 Dec 18, 2024
5f93717
Update
diqiu50 Dec 18, 2024
39e55fe
Update for review
diqiu50 Dec 18, 2024
366c77a
Update
diqiu50 Dec 18, 2024
33dc3bd
Update
diqiu50 Dec 18, 2024
865f213
Update
diqiu50 Dec 18, 2024
2570eb8
Update
diqiu50 Dec 18, 2024
bfd3945
Update
diqiu50 Dec 19, 2024
4fb77e1
Update
diqiu50 Dec 19, 2024
8cf0c4a
Update
diqiu50 Dec 19, 2024
21b080d
Update
diqiu50 Dec 19, 2024
4fe5fe3
Update
diqiu50 Dec 19, 2024
2517afa
Update
diqiu50 Dec 19, 2024
d32cd6a
Add
diqiu50 Dec 19, 2024
53e4c4e
remove unused mod
diqiu50 Dec 19, 2024
568fefe
Update
diqiu50 Dec 20, 2024
76305a9
Update
diqiu50 Dec 20, 2024
5459622
Update path interface
diqiu50 Dec 20, 2024
1ea53ef
Merge branch 'gvfs-pr2' into gvfs-pr3
diqiu50 Dec 20, 2024
dbca557
Fix error
diqiu50 Dec 20, 2024
d444ad3
Fix
diqiu50 Dec 20, 2024
2570f54
Update
diqiu50 Dec 23, 2024
f6ce011
Update
diqiu50 Dec 23, 2024
8fb13bb
Update
diqiu50 Dec 23, 2024
e23a589
Update
diqiu50 Dec 23, 2024
e8c74f6
Update
diqiu50 Dec 23, 2024
b99af10
Update
diqiu50 Dec 24, 2024
4dd5bf4
Update
diqiu50 Dec 24, 2024
01d90a6
Update
diqiu50 Dec 24, 2024
14609cf
Update
diqiu50 Dec 24, 2024
127cb41
Update
diqiu50 Dec 24, 2024
df48db4
Update
diqiu50 Dec 24, 2024
37a46d6
Update
diqiu50 Dec 24, 2024
2bd05da
Merge branch 'gvfs-pr2' into gvfs-pr3
diqiu50 Dec 24, 2024
364ce34
Merge remote-tracking branch 'gt/branch-gvfs-fuse-dev' into gvfs-pr3
diqiu50 Dec 24, 2024
3a863ed
Update
diqiu50 Dec 24, 2024
406641b
Update
diqiu50 Dec 24, 2024
0e512fc
Update
diqiu50 Dec 24, 2024
da02b01
Add testers
diqiu50 Dec 24, 2024
c043b95
Fix test
diqiu50 Dec 24, 2024
d4da504
Add testers
diqiu50 Dec 24, 2024
3b12f11
Change v1
diqiu50 Dec 25, 2024
252d399
Temp
diqiu50 Dec 25, 2024
1debe02
Merge remote-tracking branch 'gt/branch-gvfs-fuse-dev' into gvfs-pr4
diqiu50 Dec 25, 2024
573c80b
Update
diqiu50 Dec 25, 2024
f9c4546
refact config
diqiu50 Dec 26, 2024
40d1543
Update
diqiu50 Dec 26, 2024
7071618
Add error handling
diqiu50 Dec 26, 2024
81f5e71
fix testers
diqiu50 Dec 26, 2024
4fcd913
Update
diqiu50 Dec 26, 2024
757a486
Udpate
diqiu50 Dec 26, 2024
01e6f6e
Fix error
diqiu50 Dec 26, 2024
0677f2f
Add comments
diqiu50 Dec 26, 2024
0eecbd8
Fix some errors
diqiu50 Dec 26, 2024
33e1588
Update conf
diqiu50 Dec 26, 2024
8296ea0
Update
diqiu50 Dec 27, 2024
bdd0928
Fix error
diqiu50 Dec 27, 2024
b2564cc
Fix config error
diqiu50 Dec 27, 2024
c0c4a72
Fix
diqiu50 Dec 27, 2024
fdc72e1
Fix
diqiu50 Dec 27, 2024
18400c2
Update
diqiu50 Dec 30, 2024
166770b
Update
diqiu50 Dec 30, 2024
99e73be
Update
diqiu50 Dec 30, 2024
fcc8b9e
Update
diqiu50 Dec 31, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions clients/filesystem-fuse/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,18 @@ name = "gvfs_fuse"
[dependencies]
async-trait = "0.1"
bytes = "1.6.0"
config = "0.13"
dashmap = "6.1.0"
fuse3 = { version = "0.8.1", "features" = ["tokio-runtime", "unprivileged"] }
futures-util = "0.3.30"
libc = "0.2.168"
log = "0.4.22"
once_cell = "1.20.2"
reqwest = { version = "0.12.9", features = ["json"] }
serde = { version = "1.0.216", features = ["derive"] }
tokio = { version = "1.38.0", features = ["full"] }
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
urlencoding = "2.1.3"

[dev-dependencies]
mockito = "0.31"
38 changes: 38 additions & 0 deletions clients/filesystem-fuse/conf/gvfs_fuse.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

# fuse settings
[fuse]
file_mask = 0o600
dir_mask = 0o700
fs_type = "memory"

[fuse.properties]

# filesystem settings
[filesystem]
block_size = 8192

# Gravitino settings
[gravitino]
gravitino_url = "http://localhost:8090"
metalake = "your_metalake"

# extent settings
[extend_config]
access_key = "your access_key"
secret_key = "your_secret_key"
330 changes: 330 additions & 0 deletions clients/filesystem-fuse/src/config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,330 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
use crate::error::ErrorCode::{ConfigNotFound, InvalidConfig};
use crate::utils::GvfsResult;
use config::{builder, Config};
use log::{error, info, warn};
use serde::Deserialize;
use std::collections::HashMap;
use std::fs;

pub(crate) const CONF_FUSE_FILE_MASK: ConfigEntity<u32> = ConfigEntity::new(
FuseConfig::MODULE_NAME,
"file_mask",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we add filesystem prefix ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to add a prefix. It is below FuseConfig::MODULE_NAME.

"The default file mask for the FUSE filesystem",
0o600,
);

pub(crate) const CONF_FUSE_DIR_MASK: ConfigEntity<u32> = ConfigEntity::new(
FuseConfig::MODULE_NAME,
"dir_mask",
"The default directory mask for the FUSE filesystem",
0o700,
);

pub(crate) const CONF_FUSE_FS_TYPE: ConfigEntity<&'static str> = ConfigEntity::new(
FuseConfig::MODULE_NAME,
"fs_type",
"The type of the FUSE filesystem",
"memory",
);

pub(crate) const CONF_FUSE_CONFIG_PATH: ConfigEntity<&'static str> = ConfigEntity::new(
FuseConfig::MODULE_NAME,
"config_path",
"The path of the FUSE configuration file",
"/etc/gvfs/gvfs.toml",
);

pub(crate) const CONF_FILESYSTEM_BLOCK_SIZE: ConfigEntity<u32> = ConfigEntity::new(
FilesystemConfig::MODULE_NAME,
"block_size",
"The block size of the gvfs fuse filesystem",
4096,
);

pub(crate) const CONF_GRAVITINO_URL: ConfigEntity<&'static str> = ConfigEntity::new(
GravitinoConfig::MODULE_NAME,
"gravitino_url",
FANNG1 marked this conversation as resolved.
Show resolved Hide resolved
"The URL of the Gravitino server",
"http://localhost:8090",
);

pub(crate) const CONF_GRAVITINO_METALAKE: ConfigEntity<&'static str> = ConfigEntity::new(
GravitinoConfig::MODULE_NAME,
"metalake",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gravitino_metalake?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to add a prefix. It is below GravitinoConfig::MODULE_NAME.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it does not consist of gravitino_uri,

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change to uri

"The metalake of the Gravitino server",
"",
);

pub(crate) struct ConfigEntity<T: 'static> {
module: &'static str,
name: &'static str,
description: &'static str,
pub(crate) default: T,
}

impl<T> ConfigEntity<T> {
const fn new(
module: &'static str,
name: &'static str,
description: &'static str,
default: T,
) -> Self {
ConfigEntity {
module: module,
name: name,
description: description,
default: default,
}
}
}

enum ConfigValue {
I32(ConfigEntity<i32>),
U32(ConfigEntity<u32>),
String(ConfigEntity<&'static str>),
Bool(ConfigEntity<bool>),
Float(ConfigEntity<f64>),
}

struct DefaultConfig {
configs: HashMap<String, ConfigValue>,
}

impl Default for DefaultConfig {
fn default() -> Self {
let mut configs = HashMap::new();

configs.insert(
Self::compose_key(CONF_FUSE_FILE_MASK),
ConfigValue::U32(CONF_FUSE_FILE_MASK),
);
configs.insert(
Self::compose_key(CONF_FUSE_DIR_MASK),
ConfigValue::U32(CONF_FUSE_DIR_MASK),
);
configs.insert(
Self::compose_key(CONF_FUSE_FS_TYPE),
ConfigValue::String(CONF_FUSE_FS_TYPE),
);
configs.insert(
Self::compose_key(CONF_FUSE_CONFIG_PATH),
ConfigValue::String(CONF_FUSE_CONFIG_PATH),
);
configs.insert(
Self::compose_key(CONF_GRAVITINO_URL),
ConfigValue::String(CONF_GRAVITINO_URL),
);
configs.insert(
Self::compose_key(CONF_GRAVITINO_METALAKE),
ConfigValue::String(CONF_GRAVITINO_METALAKE),
);
configs.insert(
Self::compose_key(CONF_FILESYSTEM_BLOCK_SIZE),
ConfigValue::U32(CONF_FILESYSTEM_BLOCK_SIZE),
);

DefaultConfig { configs }
}
}

impl DefaultConfig {
fn compose_key<T>(entity: ConfigEntity<T>) -> String {
format!("{}.{}", entity.module, entity.name)
}
}

#[derive(Debug, Deserialize)]
pub struct AppConfig {
#[serde(default)]
pub fuse: FuseConfig,
#[serde(default)]
pub filesystem: FilesystemConfig,
#[serde(default)]
pub gravitino: GravitinoConfig,
#[serde(default)]
pub extend_config: HashMap<String, String>,
}

impl Default for AppConfig {
fn default() -> Self {
let builder = Self::crete_default_config_builder();
let conf = builder
.build()
.expect("Failed to build default configuration");
conf.try_deserialize::<AppConfig>()
.expect("Failed to deserialize default AppConfig")
}
}

type ConfigBuilder = builder::ConfigBuilder<builder::DefaultState>;

impl AppConfig {
fn crete_default_config_builder() -> ConfigBuilder {
let default = DefaultConfig::default();

default
.configs
.values()
.fold(
Config::builder(),
|builder, config_entity| match config_entity {
ConfigValue::I32(entity) => Self::add_config(builder, entity),
ConfigValue::U32(entity) => Self::add_config(builder, entity),
ConfigValue::String(entity) => Self::add_config(builder, entity),
ConfigValue::Bool(entity) => Self::add_config(builder, entity),
ConfigValue::Float(entity) => Self::add_config(builder, entity),
},
)
}

fn add_config<T: Clone + Into<config::Value>>(
builder: ConfigBuilder,
entity: &ConfigEntity<T>,
) -> ConfigBuilder {
let name = format!("{}.{}", entity.module, entity.name);
builder
.set_default(&name, entity.default.clone().into())
.unwrap_or_else(|e| panic!("Failed to set default for {}: {}", entity.name, e))
}

pub fn from_file(config_file_path: Option<&str>) -> GvfsResult<AppConfig> {
let builder = Self::crete_default_config_builder();

let config_path = {
if config_file_path.is_some() {
let path = config_file_path.unwrap();
//check config file exists
if fs::metadata(path).is_err() {
return Err(
ConfigNotFound.to_error("The configuration file not found".to_string())
);
}
info!("Use configuration file: {}", path);
path
} else {
//use default config
if fs::metadata(CONF_FUSE_CONFIG_PATH.default).is_err() {
warn!(
"The default configuration file is not found, using the default configuration"
);
return Ok(AppConfig::default());
} else {
warn!(
"Using the default config file {}",
CONF_FUSE_CONFIG_PATH.default
);
}
CONF_FUSE_CONFIG_PATH.default
}
};
let config = builder
.add_source(config::File::with_name(config_path).required(true))
.build();
if let Err(e) = config {
let msg = format!("Failed to build configuration: {}", e);
error!("{}", msg);
return Err(InvalidConfig.to_error(msg));
}

let conf = config.unwrap();
let app_config = conf.try_deserialize::<AppConfig>();

if let Err(e) = app_config {
let msg = format!("Failed to deserialize configuration: {}", e);
error!("{}", msg);
return Err(InvalidConfig.to_error(msg));
}
Ok(app_config.unwrap())
}
}

#[derive(Debug, Deserialize, Default)]
pub struct FuseConfig {
#[serde(default)]
pub file_mask: u32,
#[serde(default)]
pub dir_mask: u32,
#[serde(default)]
pub fs_type: String,
#[serde(default)]
pub config_path: String,
#[serde(default)]
pub properties: HashMap<String, String>,
}

impl FuseConfig {
const MODULE_NAME: &'static str = "fuse";
}

#[derive(Debug, Deserialize, Default)]
pub struct FilesystemConfig {
#[serde(default)]
pub block_size: u32,
}

impl FilesystemConfig {
const MODULE_NAME: &'static str = "filesystem";
}

#[derive(Debug, Deserialize, Default)]
pub struct GravitinoConfig {
#[serde(default)]
pub gravitino_url: String,
#[serde(default)]
pub metalake: String,
}

impl GravitinoConfig {
const MODULE_NAME: &'static str = "gravitino";
}

#[cfg(test)]
mod test {
use crate::config::AppConfig;

#[test]
fn test_config_from_file() {
let config = AppConfig::from_file(Some("tests/conf/gvfs_fuse_test.toml")).unwrap();
assert_eq!(config.fuse.file_mask, 0o644);
assert_eq!(config.fuse.dir_mask, 0o755);
assert_eq!(config.filesystem.block_size, 8192);
assert_eq!(config.gravitino.gravitino_url, "http://localhost:8090");
assert_eq!(config.gravitino.metalake, "test");
assert_eq!(
config.extend_config.get("access_key"),
Some(&"XXX_access_key".to_string())
);
assert_eq!(
config.extend_config.get("secret_key"),
Some(&"XXX_secret_key".to_string())
);
}

#[test]
fn test_default_config() {
let config = AppConfig::default();
assert_eq!(config.fuse.file_mask, 0o600);
assert_eq!(config.fuse.dir_mask, 0o700);
assert_eq!(config.filesystem.block_size, 4096);
assert_eq!(config.gravitino.gravitino_url, "http://localhost:8090");
assert_eq!(config.gravitino.metalake, "");
}
}
Loading
Loading