-
Notifications
You must be signed in to change notification settings - Fork 392
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
[#6279] feat (gvfs-fuse): Add gvfs-fuse integration tests for big files and open-file flag test cases #6280
Open
diqiu50
wants to merge
27
commits into
apache:main
Choose a base branch
from
diqiu50:gvfs-pr9
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+579
−119
Open
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
8bedc8f
Add testers for fileset fs
diqiu50 0b6cf88
Add integration test script
diqiu50 90bd355
Add integration testers script
diqiu50 c0d8d10
Fix
diqiu50 c1bd3cd
Fix
diqiu50 6dff6cd
Fix
diqiu50 6ba8391
Fix
diqiu50 9611a3c
Update test script
diqiu50 9459887
Add integration test
diqiu50 ccac1be
fix some logs
diqiu50 d56c8db
Test s3
diqiu50 32d5a86
Update
diqiu50 da1832e
refector s3 testcases
diqiu50 cfde267
Fix
diqiu50 08b8436
Integration with localstack
diqiu50 b94ecd8
Add pipline
diqiu50 52238fb
Fix
diqiu50 f2c43ea
Fix ci error
diqiu50 ae61ac6
Fix
diqiu50 bef5e49
Fix
diqiu50 c8c35c9
Add bigfile and openfile flag testcases
diqiu50 702616e
Add more testcases
diqiu50 00c644c
Fix rebase error
diqiu50 c586f87
Fix some errors
diqiu50 4093a6c
add flag to TestRawFs::create_file
diqiu50 b654b36
Fix format error
diqiu50 9099a40
Fix
diqiu50 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,7 @@ use bytes::Bytes; | |
use fuse3::FileType::{Directory, RegularFile}; | ||
use fuse3::{Errno, FileType, Timestamp}; | ||
use log::error; | ||
use opendal::{EntryMode, ErrorKind, Metadata, Operator}; | ||
use opendal::{Buffer, EntryMode, ErrorKind, Metadata, Operator}; | ||
use std::path::{Path, PathBuf}; | ||
use std::time::SystemTime; | ||
|
||
|
@@ -37,6 +37,8 @@ pub(crate) struct OpenDalFileSystem { | |
impl OpenDalFileSystem {} | ||
|
||
impl OpenDalFileSystem { | ||
const WRITE_BUFFER_SIZE: usize = 5 * 1024 * 1024; | ||
|
||
pub(crate) fn new(op: Operator, _config: &AppConfig, _fs_context: &FileSystemContext) -> Self { | ||
Self { op: op } | ||
} | ||
|
@@ -120,14 +122,27 @@ impl PathFileSystem for OpenDalFileSystem { | |
.map_err(opendal_error_to_errno)?; | ||
file.reader = Some(Box::new(FileReaderImpl { reader })); | ||
} | ||
if flags.is_write() || flags.is_create() || flags.is_append() || flags.is_truncate() { | ||
if !flags.is_create() && flags.is_append() { | ||
error!("The file system does not support open a exists file with the append mode"); | ||
return Err(Errno::from(libc::EBADF)); | ||
} | ||
|
||
if flags.is_truncate() { | ||
self.op | ||
.write(&file_name, Buffer::new()) | ||
.await | ||
.map_err(opendal_error_to_errno)?; | ||
} | ||
|
||
if flags.is_write() || flags.is_append() || flags.is_truncate() { | ||
let writer = self | ||
.op | ||
.writer_with(&file_name) | ||
.await | ||
.map_err(opendal_error_to_errno)?; | ||
file.writer = Some(Box::new(FileWriterImpl { writer })); | ||
file.writer = Some(Box::new(FileWriterImpl::new(writer))); | ||
} | ||
|
||
Ok(file) | ||
} | ||
|
||
|
@@ -141,15 +156,17 @@ impl PathFileSystem for OpenDalFileSystem { | |
|
||
async fn create_file(&self, path: &Path, flags: OpenFileFlags) -> Result<OpenedFile> { | ||
let file_name = path.to_string_lossy().to_string(); | ||
if flags.is_exclusive() { | ||
let meta = self.op.stat(&file_name).await; | ||
if meta.is_ok() { | ||
return Err(Errno::from(libc::EEXIST)); | ||
} | ||
} | ||
|
||
let mut writer = self | ||
.op | ||
.writer_with(&file_name) | ||
self.op | ||
.write(&file_name, Buffer::new()) | ||
.await | ||
.map_err(opendal_error_to_errno)?; | ||
|
||
writer.close().await.map_err(opendal_error_to_errno)?; | ||
|
||
let file = self.open_file(path, flags).await?; | ||
Ok(file) | ||
} | ||
|
@@ -210,19 +227,44 @@ impl FileReader for FileReaderImpl { | |
|
||
struct FileWriterImpl { | ||
writer: opendal::Writer, | ||
buffer: Vec<u8>, | ||
} | ||
|
||
impl FileWriterImpl { | ||
fn new(writer: opendal::Writer) -> Self { | ||
Self { | ||
writer, | ||
buffer: Vec::with_capacity(OpenDalFileSystem::WRITE_BUFFER_SIZE + 4096), | ||
} | ||
} | ||
} | ||
|
||
#[async_trait] | ||
impl FileWriter for FileWriterImpl { | ||
async fn write(&mut self, _offset: u64, data: &[u8]) -> Result<u32> { | ||
self.writer | ||
.write(data.to_vec()) | ||
.await | ||
.map_err(opendal_error_to_errno)?; | ||
if self.buffer.len() > OpenDalFileSystem::WRITE_BUFFER_SIZE { | ||
let mut new_buffer: Vec<u8> = | ||
Vec::with_capacity(OpenDalFileSystem::WRITE_BUFFER_SIZE + 4096); | ||
new_buffer.append(&mut self.buffer); | ||
|
||
self.writer | ||
.write(new_buffer) | ||
.await | ||
.map_err(opendal_error_to_errno)?; | ||
} | ||
self.buffer.extend(data); | ||
Ok(data.len() as u32) | ||
} | ||
|
||
async fn close(&mut self) -> Result<()> { | ||
if !self.buffer.is_empty() { | ||
let mut new_buffer: Vec<u8> = vec![]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. buffer not cleared too? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same |
||
new_buffer.append(&mut self.buffer); | ||
self.writer | ||
.write(new_buffer) | ||
.await | ||
.map_err(opendal_error_to_errno)?; | ||
} | ||
self.writer.close().await.map_err(opendal_error_to_errno)?; | ||
Ok(()) | ||
} | ||
|
@@ -260,10 +302,12 @@ fn opendal_filemode_to_filetype(mode: EntryMode) -> FileType { | |
#[cfg(test)] | ||
mod test { | ||
use crate::config::AppConfig; | ||
use crate::open_dal_filesystem::OpenDalFileSystem; | ||
use crate::s3_filesystem::extract_s3_config; | ||
use crate::s3_filesystem::tests::s3_test_config; | ||
use crate::test_enable_with; | ||
use crate::RUN_TEST_WITH_S3; | ||
use bytes::Buf; | ||
use opendal::layers::LoggingLayer; | ||
use opendal::{services, Builder, Operator}; | ||
|
||
|
@@ -327,4 +371,63 @@ mod test { | |
} | ||
} | ||
} | ||
|
||
#[tokio::test] | ||
async fn s3_ut_test_s3_write() { | ||
test_enable_with!(RUN_TEST_WITH_S3); | ||
let config = s3_test_config(); | ||
|
||
let op = create_opendal(&config); | ||
let path = "/s1/fileset1/gvfs_test/test_dir/test_file"; | ||
let mut writer = op.writer_with(path).await.unwrap(); | ||
|
||
let mut buffer: Vec<u8> = vec![]; | ||
let num_batch = 10 * 1024; | ||
for i in 0..num_batch { | ||
let data = vec![i as u8; num_batch]; | ||
buffer.extend(&data); | ||
|
||
if buffer.len() > OpenDalFileSystem::WRITE_BUFFER_SIZE { | ||
writer.write(buffer).await.unwrap(); | ||
buffer = vec![]; | ||
}; | ||
} | ||
|
||
if !buffer.is_empty() { | ||
writer.write(buffer).await.unwrap(); | ||
} | ||
writer.close().await.unwrap(); | ||
} | ||
|
||
#[tokio::test] | ||
async fn s3_ut_test_s3_read() { | ||
test_enable_with!(RUN_TEST_WITH_S3); | ||
let config = s3_test_config(); | ||
|
||
let op = create_opendal(&config); | ||
let path = "/s1/fileset1/test_dir/test_big_file"; | ||
let meta = op.stat(path).await; | ||
if meta.is_err() { | ||
println!("stat error: {:?}", meta.err()); | ||
return; | ||
} | ||
let reader = op.reader(path).await.unwrap(); | ||
|
||
let mut buffer = Vec::new(); | ||
|
||
let batch_size = 1024; | ||
let mut start = 0; | ||
let mut end = batch_size; | ||
loop { | ||
let buf = reader.read(start..end).await.unwrap(); | ||
if buf.is_empty() { | ||
break; | ||
} | ||
buffer.extend_from_slice(buf.chunk()); | ||
start = end; | ||
end += batch_size; | ||
} | ||
|
||
println!("Read {} bytes.", buffer.len()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You didn't clear the buffer after writing to the underlying fs, is that expected?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the
self.buffer
is cleared after the append operation.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you point out where did you clear the buffer?