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

remove useless async #166

Merged
merged 1 commit into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
27 changes: 11 additions & 16 deletions src/server/distributed_engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ where

pub fn create_dir_no_parent(&self, path: &str, mode: u32) -> Result<Vec<u8>, i32> {
match self.file_locks.insert(path.to_owned(), DashMap::new()) {
Some(_) => Err(libc::EEXIST),
Some(_) => Err(libc::EEXIST), // file will be checked in directory_add_entry, no need to recover here
None => self.meta_engine.create_directory(path, mode),
}
}
Expand Down Expand Up @@ -818,7 +818,7 @@ where
}
}

pub async fn read_dir(&self, path: &str, size: u32, offset: i64) -> Result<Vec<u8>, i32> {
pub fn read_dir(&self, path: &str, size: u32, offset: i64) -> Result<Vec<u8>, i32> {
let _file_lock = self.lock_file(path)?;
self.meta_engine.read_directory(path, size, offset)
}
Expand Down Expand Up @@ -1020,28 +1020,28 @@ where
}
}

pub async fn truncate_file(&self, path: &str, length: i64) -> Result<(), i32> {
pub fn truncate_file(&self, path: &str, length: i64) -> Result<(), i32> {
// a temporary implementation
let _file_lock = self.lock_file(path)?;
self.storage_engine.truncate_file(path, length)
}

pub async fn read_file(&self, path: &str, size: u32, offset: i64) -> Result<Vec<u8>, i32> {
pub fn read_file(&self, path: &str, size: u32, offset: i64) -> Result<Vec<u8>, i32> {
let _file_lock = self.lock_file(path)?;
self.storage_engine.read_file(path, size, offset)
}

pub async fn write_file(&self, path: &str, data: &[u8], offset: i64) -> Result<usize, i32> {
pub fn write_file(&self, path: &str, data: &[u8], offset: i64) -> Result<usize, i32> {
let _file_lock = self.lock_file(path)?;
self.storage_engine.write_file(path, data, offset)
}

pub async fn get_file_attr(&self, path: &str) -> Result<Vec<u8>, i32> {
pub fn get_file_attr(&self, path: &str) -> Result<Vec<u8>, i32> {
let _file_lock = self.lock_file(path)?;
self.meta_engine.get_file_attr_raw(path)
}

pub async fn open_file(&self, path: &str, flag: i32, mode: u32) -> Result<(), i32> {
pub fn open_file(&self, path: &str, flag: i32, mode: u32) -> Result<(), i32> {
if (flag & O_CREAT) != 0 {
todo!("create file should be converted at client side")
} else if (flag & O_DIRECTORY) != 0 {
Expand All @@ -1052,7 +1052,7 @@ where
}
}

pub async fn directory_add_entry(&self, path: &str, file_name: String, file_type: u8) -> i32 {
pub fn directory_add_entry(&self, path: &str, file_name: String, file_type: u8) -> i32 {
let _lock = match self.lock_file(path) {
Ok(lock) => lock,
Err(e) => {
Expand All @@ -1075,20 +1075,15 @@ where
}
}

pub async fn check_file(&self, path: &str, file_attr: &FileAttr) -> Result<(), i32> {
pub fn check_file(&self, path: &str, file_attr: &FileAttr) -> Result<(), i32> {
self.meta_engine.complete_transfer_file(path, file_attr)
}

pub async fn check_dir(&self, path: &str, file_attr: &FileAttr) -> Result<(), i32> {
pub fn check_dir(&self, path: &str, file_attr: &FileAttr) -> Result<(), i32> {
self.meta_engine.complete_transfer_file(path, file_attr)
}

pub async fn directory_delete_entry(
&self,
path: &str,
file_name: String,
file_type: u8,
) -> i32 {
pub fn directory_delete_entry(&self, path: &str, file_name: String, file_type: u8) -> i32 {
let _lock = match self.lock_file(path) {
Ok(lock) => lock,
Err(e) => {
Expand Down
80 changes: 38 additions & 42 deletions src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ where
OperationType::GetFileAttr => {
debug!("{} Get File Attr: path: {}", self.engine.address, file_path);
let (return_meta_data, status) =
match self.engine.get_file_attr(file_path).await {
match self.engine.get_file_attr(file_path) {
Ok(value) => (value, 0),
Err(e) => {
debug!(
Expand All @@ -504,11 +504,11 @@ where
debug!("{} Open File {}", self.engine.address, file_path);
let meta_data_unwraped: OpenFileSendMetaData =
bincode::deserialize(&metadata).unwrap();
let status = match self
.engine
.open_file(file_path, meta_data_unwraped.flags, meta_data_unwraped.mode)
.await
{
let status = match self.engine.open_file(
file_path,
meta_data_unwraped.flags,
meta_data_unwraped.mode,
) {
Ok(()) => 0,
Err(e) => {
debug!(
Expand All @@ -526,8 +526,7 @@ where
OperationType::ReadDir => {
debug!("{} Read Dir: {}", self.engine.address, file_path);
let md: ReadDirSendMetaData = bincode::deserialize(&metadata).unwrap();
let (data, status) = match self.engine.read_dir(file_path, md.size, md.offset).await
{
let (data, status) = match self.engine.read_dir(file_path, md.size, md.offset) {
Ok(value) => (value, 0),
Err(e) => {
debug!(
Expand All @@ -545,42 +544,41 @@ where
OperationType::ReadFile => {
debug!("{} Read File: {}", self.engine.address, file_path);
let md: ReadFileSendMetaData = bincode::deserialize(&metadata).unwrap();
let (data, status) =
match self.engine.read_file(file_path, md.size, md.offset).await {
Ok(value) => (value, 0),
Err(e) => {
debug!(
"Read File Failed: {:?}, path: {}, operation_type: {}, flags: {}",
status_to_string(e),
file_path,
operation_type,
flags
);
(Vec::new(), e)
}
};
Ok((status, 0, 0, data.len(), Vec::new(), data))
}
OperationType::WriteFile => {
debug!("{} Write File: {}", self.engine.address, file_path);
let md: WriteFileSendMetaData = bincode::deserialize(&metadata).unwrap();
let (status, size) = match self
.engine
.write_file(file_path, data.as_slice(), md.offset)
.await
{
Ok(size) => (0, size as u32),
let (data, status) = match self.engine.read_file(file_path, md.size, md.offset) {
Ok(value) => (value, 0),
Err(e) => {
debug!(
"Write File Failed: {:?}, path: {}, operation_type: {}, flags: {}",
"Read File Failed: {:?}, path: {}, operation_type: {}, flags: {}",
status_to_string(e),
file_path,
operation_type,
flags
);
(e, 0)
(Vec::new(), e)
}
};
Ok((status, 0, 0, data.len(), Vec::new(), data))
}
OperationType::WriteFile => {
debug!("{} Write File: {}", self.engine.address, file_path);
let md: WriteFileSendMetaData = bincode::deserialize(&metadata).unwrap();
let (status, size) =
match self
.engine
.write_file(file_path, data.as_slice(), md.offset)
{
Ok(size) => (0, size as u32),
Err(e) => {
debug!(
"Write File Failed: {:?}, path: {}, operation_type: {}, flags: {}",
status_to_string(e),
file_path,
operation_type,
flags
);
(e, 0)
}
};
Ok((
status,
0,
Expand Down Expand Up @@ -641,8 +639,7 @@ where
let md: DirectoryEntrySendMetaData = bincode::deserialize(&metadata).unwrap();
Ok((
self.engine
.directory_add_entry(file_path, md.file_name, md.file_type)
.await,
.directory_add_entry(file_path, md.file_name, md.file_type),
0,
0,
0,
Expand All @@ -658,8 +655,7 @@ where
let md: DirectoryEntrySendMetaData = bincode::deserialize(&metadata).unwrap();
Ok((
self.engine
.directory_delete_entry(file_path, md.file_name, md.file_type)
.await,
.directory_delete_entry(file_path, md.file_name, md.file_type),
0,
0,
0,
Expand All @@ -671,7 +667,7 @@ where
debug!("{} Truncate File: {}", self.engine.address, file_path);
let md: TruncateFileSendMetaData = bincode::deserialize(&metadata).unwrap();
let status =
match self.engine.truncate_file(file_path, md.length).await {
match self.engine.truncate_file(file_path, md.length) {
Ok(()) => 0,
Err(e) => {
debug!(
Expand All @@ -687,7 +683,7 @@ where
info!("{} Checkout File: {}", self.engine.address, file_path);
let file_attr = bytes_as_file_attr(&metadata);
let status =
match self.engine.check_file(file_path, file_attr).await {
match self.engine.check_file(file_path, file_attr) {
Ok(()) => 0,
Err(e) => {
info!(
Expand All @@ -703,7 +699,7 @@ where
info!("{} Checkout Dir: {}", self.engine.address, file_path);
let file_attr = bytes_as_file_attr(&metadata);
let status =
match self.engine.check_dir(file_path, file_attr).await {
match self.engine.check_dir(file_path, file_attr) {
Ok(()) => 0,
Err(e) => {
info!(
Expand Down
Loading