mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-07 22:03:14 +00:00
improve channel adapter
This commit is contained in:
+50
-39
@@ -33,33 +33,41 @@ lazy_static! {
|
||||
};
|
||||
}
|
||||
|
||||
/// * read config
|
||||
/// Reads configuration file content from the storage system
|
||||
///
|
||||
/// * @param api
|
||||
/// * @param file
|
||||
/// This function reads a specified configuration file through the provided storage API interface
|
||||
/// and returns its raw byte content. It's a basic configuration reading function that returns
|
||||
/// only the configuration data without any metadata.
|
||||
///
|
||||
/// # Parameters
|
||||
/// * `api` - An Arc smart pointer containing an implementation of the StorageAPI trait
|
||||
/// * `file` - The name of the configuration file to read
|
||||
///
|
||||
/// # Returns
|
||||
/// * `Result<Vec<u8>>` - Returns the configuration file contents as bytes on success, or an error on failure
|
||||
///
|
||||
/// # Errors
|
||||
/// May return the following errors:
|
||||
/// * `ConfigError::NotFound` - When the requested configuration file does not exist
|
||||
/// * Other storage operation related errors
|
||||
///
|
||||
/// * @return
|
||||
/// * @description
|
||||
/// * read config
|
||||
/// * @error
|
||||
/// * * ConfigError::NotFound
|
||||
pub async fn read_config<S: StorageAPI>(api: Arc<S>, file: &str) -> Result<Vec<u8>> {
|
||||
let (data, _obj) = read_config_with_metadata(api, file, &ObjectOptions::default()).await?;
|
||||
Ok(data)
|
||||
}
|
||||
|
||||
/// * read_config_with_metadata
|
||||
/// read config with metadata
|
||||
/// read config with metadata with api,file and opts
|
||||
///
|
||||
/// * @param api
|
||||
/// * @param file
|
||||
/// * @param opts
|
||||
/// # Parameters
|
||||
/// - `api`: StorageAPI
|
||||
/// - `file`: file name
|
||||
/// - `opts`: object options
|
||||
///
|
||||
/// * @return
|
||||
/// * @description
|
||||
/// * read config with metadata
|
||||
/// * @error
|
||||
/// * * ConfigError::NotFound
|
||||
/// # Returns
|
||||
/// Result<(Vec<u8>, ObjectInfo)>
|
||||
///
|
||||
/// # Errors
|
||||
/// - ConfigError::NotFound
|
||||
pub async fn read_config_with_metadata<S: StorageAPI>(
|
||||
api: Arc<S>,
|
||||
file: &str,
|
||||
@@ -86,15 +94,16 @@ pub async fn read_config_with_metadata<S: StorageAPI>(
|
||||
Ok((data, rd.object_info))
|
||||
}
|
||||
|
||||
/// * save_config
|
||||
/// save config with api,file and data
|
||||
///
|
||||
/// * @param api
|
||||
/// * @param file
|
||||
/// * @param data
|
||||
/// # Parameters
|
||||
///
|
||||
/// * @return
|
||||
/// * @description
|
||||
/// * save config
|
||||
/// - `api`: StorageAPI
|
||||
/// - `file`: file name
|
||||
/// - `data`: data to save
|
||||
///
|
||||
/// # Returns
|
||||
/// Result
|
||||
pub async fn save_config<S: StorageAPI>(api: Arc<S>, file: &str, data: Vec<u8>) -> Result<()> {
|
||||
save_config_with_opts(
|
||||
api,
|
||||
@@ -108,13 +117,15 @@ pub async fn save_config<S: StorageAPI>(api: Arc<S>, file: &str, data: Vec<u8>)
|
||||
.await
|
||||
}
|
||||
|
||||
/// * delete_config
|
||||
/// delete config with api and file
|
||||
///
|
||||
/// # Parameters
|
||||
/// - `api`: StorageAPI
|
||||
/// - `file`: file name
|
||||
///
|
||||
/// # Returns
|
||||
/// Result
|
||||
///
|
||||
/// * @param api
|
||||
/// * @param file
|
||||
/// * @return
|
||||
/// * @description
|
||||
/// * delete config
|
||||
pub async fn delete_config<S: StorageAPI>(api: Arc<S>, file: &str) -> Result<()> {
|
||||
match api
|
||||
.delete_object(
|
||||
@@ -139,15 +150,15 @@ pub async fn delete_config<S: StorageAPI>(api: Arc<S>, file: &str) -> Result<()>
|
||||
}
|
||||
}
|
||||
|
||||
/// * save_config_with_opts
|
||||
/// save config with opts
|
||||
/// * @param api
|
||||
/// * @param file
|
||||
/// * @param data
|
||||
/// * @param opts
|
||||
/// * @return
|
||||
/// * @description
|
||||
/// * save config with opts
|
||||
///
|
||||
/// # Parameters
|
||||
/// - `api`: StorageAPI
|
||||
/// - `file`: file name
|
||||
/// - `data`: data to save
|
||||
///
|
||||
/// # Returns
|
||||
/// Result
|
||||
pub async fn save_config_with_opts<S: StorageAPI>(api: Arc<S>, file: &str, data: Vec<u8>, opts: &ObjectOptions) -> Result<()> {
|
||||
let size = data.len();
|
||||
let _ = api
|
||||
|
||||
@@ -8,7 +8,8 @@ use lazy_static::lazy_static;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use tracing::warn;
|
||||
|
||||
// default_parity_count 默认配置,根据磁盘总数分配校验磁盘数量
|
||||
/// Default parity count for a given drive count
|
||||
/// The default configuration allocates the number of check disks based on the total number of disks
|
||||
pub fn default_parity_count(drive: usize) -> usize {
|
||||
match drive {
|
||||
1 => 0,
|
||||
|
||||
Reference in New Issue
Block a user