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

feat: implemented ftp backend #581

Merged
merged 15 commits into from
Sep 4, 2022
Merged

feat: implemented ftp backend #581

merged 15 commits into from
Sep 4, 2022

Conversation

ArberSephirotheca
Copy link
Contributor

@ArberSephirotheca ArberSephirotheca commented Aug 27, 2022

I hereby agree to the terms of the CLA available at: https://databend.rs/dev/policies/cla/

Summary

Summary about this PR
I've implemented ftp backend.
I tested it locally with vsftpd and it works fine. I didn't make too much tests on tls mode, but it should be working as supftp almost handle everything for us.

It also pass all the behavior tests:

czy@czy-Inspiron-5680:~/opendal$ cargo test ftp
   Compiling opendal v0.13.1 (/home/czy/opendal)
    Finished test [unoptimized + debuginfo] target(s) in 9.02s
     Running unittests src/lib.rs (target/debug/deps/opendal-5b46cd0e7a5789ec)

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 29 filtered out; finished in 0.00s

     Running tests/behavior/main.rs (target/debug/deps/behavior-516c49dc2e664db6)

running 42 tests
test behavior::services_ftp::test_create_dir ... ok
test behavior::services_ftp::test_create_file_existing ... ok
test behavior::services_ftp::test_create_file_with_special_chars ... ok
test behavior::services_ftp::test_delete_empty_dir ... ok
test behavior::services_ftp::test_create_file ... ok
test behavior::services_ftp::test_list_dir_with_file_path ... ok
test behavior::services_ftp::test_delete ... ok
test behavior::services_ftp::test_list_dir ... ok
test behavior::services_ftp::test_delete_not_existing ... ok
test behavior::services_ftp::test_check ... ok
test behavior::services_ftp::test_create_dir_exising ... ok
test behavior::services_ftp::test_delete_with_special_chars ... ok
test behavior::services_ftp::test_list_nested_dir ... ok
test behavior::services_ftp::test_list_empty_dir ... ok
test behavior::services_ftp::test_list_sub_dir ... ok
test behavior::services_ftp::test_object_id ... ok
test behavior::services_ftp::test_object_name ... ok
test behavior::services_ftp::test_multipart_abort ... ok
test behavior::services_ftp::test_multipart_complete ... ok
test behavior::services_ftp::test_object_path ... ok
test behavior::services_ftp::test_presign_read ... ok
test behavior::services_ftp::test_presign_write ... ok
test behavior::services_ftp::test_presign_write_multipart ... ok
test behavior::services_ftp::test_metadata ... ok
test behavior::services_ftp::test_read_full ... ok
test behavior::services_ftp::test_read_not_exist ... ok
test behavior::services_ftp::test_read_range ... ok
test behavior::services_ftp::test_read_with_dir_path ... ok
test behavior::services_ftp::test_stat_dir ... ok
test behavior::services_ftp::test_stat_not_cleaned_path ... ok
test behavior::services_ftp::test_read_with_special_chars ... ok
test behavior::services_ftp::test_remove_all ... ok
test behavior::services_ftp::test_stat_not_exist ... ok
test behavior::services_ftp::test_stat_root ... ok
test behavior::services_ftp::test_stat_with_special_chars ... ok
test behavior::services_ftp::test_walk_bottom_up ... ok
test behavior::services_ftp::test_write ... ok
test behavior::services_ftp::test_write_with_special_chars ... ok
test behavior::services_ftp::test_write_with_dir_path ... ok
test behavior::services_ftp::test_stat ... ok
test behavior::services_ftp::test_walk_top_down ... ok
test behavior::services_ftp::test_walk_top_down_within_empty_dir ... ok

test result: ok. 42 passed; 0 failed; 0 ignored; 0 measured; 252 filtered out; finished in 0.01s

I created a example file in examples/ if you want to try.
The error handling looks kind cluttered tho, and Im trying to improve it.

@Xuanwo
Copy link
Member

Xuanwo commented Aug 27, 2022

So nice!

Copy link
Contributor

@ClSlaid ClSlaid left a comment

Choose a reason for hiding this comment

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

Bravo!

src/services/ftp/backend.rs Outdated Show resolved Hide resolved
src/services/ftp/backend.rs Outdated Show resolved Hide resolved
src/services/ftp/backend.rs Outdated Show resolved Hide resolved
src/services/ftp/backend.rs Outdated Show resolved Hide resolved
src/services/ftp/backend.rs Outdated Show resolved Hide resolved
src/services/ftp/backend.rs Outdated Show resolved Hide resolved
src/services/ftp/dir_stream.rs Show resolved Hide resolved
tests/behavior/behavior.rs Show resolved Hide resolved
@ClSlaid
Copy link
Contributor

ClSlaid commented Aug 27, 2022

Clippy and Rustfmt are your friends. Before commit, you can run cargo clippy for checks and advices, and run cargo fmt to reformat you code.

@ClSlaid ClSlaid changed the title implemented ftp backend feat: implemented ftp backend Aug 27, 2022
@ArberSephirotheca
Copy link
Contributor Author

ArberSephirotheca commented Aug 27, 2022

@ClSlaid Thanks for the review. I am moving house right now so I may not update too frequent, but I hope I can get all these thing fixed within a week.

.env.example Outdated Show resolved Hide resolved
Cargo.toml Outdated Show resolved Hide resolved
examples/ftp.rs Outdated Show resolved Hide resolved
src/services/ftp/backend.rs Outdated Show resolved Hide resolved
src/services/ftp/backend.rs Outdated Show resolved Hide resolved
src/services/ftp/backend.rs Outdated Show resolved Hide resolved
src/services/ftp/backend.rs Outdated Show resolved Hide resolved
src/services/ftp/backend.rs Outdated Show resolved Hide resolved
src/services/ftp/err.rs Outdated Show resolved Hide resolved
tests/behavior/behavior.rs Show resolved Hide resolved
@Xuanwo
Copy link
Member

Xuanwo commented Aug 27, 2022

This PR is really great and almost done. I left some reviews on this PR. Please take a look when you are free.

I am moving house right now so I may not update too frequent

And congrats on your new move. Hoping your new house is nice and comfortable.

"Cargo.toml":
Hide FTP support under new feature flag.

"operator.rs", "scheme.rs, src/services/mod.rs":
Added conditional compilation for ftp services.

"src/services/ftp/backend.rs":
Removed any unnecessary helper functions that only use
once.
Removed username and password store to avoid data breach.
Combine port and endpoint into one.
Built a FTP command stream inside Builder's build() function
and persist this stream inside Backend.
Changed tls to enable_secure. Developer can use enable_secure() function
to enable tls connection.
Modified read() function to avoid putting all stream content into memory.
Fixed stat() function, when path argument is empty, stat() function will
return the stat of root directory.

"src/services/ftp/dir_stream.rs"
Added more metadata in DirEntry.

"src/services/ftp/err.rs":
Removed any unnecessary error functions.

"src/services/ftp/mod.rs":
Remove empty line.

"tests/behavior/behavior.rs":
Added feature for ftp.

Resolve conflict.
Remove duplicate pattern.

"Cargo.toml":
add services-ftp under example.
Added example section for ftp.
@ArberSephirotheca
Copy link
Contributor Author

ArberSephirotheca commented Sep 3, 2022

@Xuanwo I think I got everything fixed. If you find anything needed to be changed, Please point out.

CI/check indicates a vulnerability due to outdated time crate:

Crate:     time
error: 1 vulnerability found!
Version:   0.1.44
Title:     Potential segfault in the time crate
Date:      2020-11-18
ID:        RUSTSEC-2020-0071
URL:       https://rustsec.org/advisories/RUSTSEC-2020-0071
Solution:  Upgrade to >=0.2.23
Dependency tree:
time 0.1.44
└── chrono 0.4.22
    └── suppaftp 4.4.0
        └── opendal 0.14.1

However, according to this, the chrono team are mostly likely not going to update this dependency as the vulnerability does not affect them, and they will remove this dependency in the future.
Also for Service Test HDFS, my change doesn't touch this part, I don't know why it fails(and it success in my previous commit...).

@Xuanwo
Copy link
Member

Xuanwo commented Sep 3, 2022

However, according to this, the chrono team are mostly likely not going to update this dependency as the vulnerability does not affect them, and they will remove this dependency in the future.

Please add an audit.toml like databend dose: https://github.com/datafuselabs/databend/blob/main/.cargo/audit.toml#L9

Also for Service Test HDFS, my change doesn't touch this part, I don't know why it fails(and it success in my previous commit...).

It's a known issue that the HDFS test is flaky: #465

Please just ignore it.

src/services/ftp/backend.rs Show resolved Hide resolved
src/services/ftp/backend.rs Outdated Show resolved Hide resolved
src/services/ftp/backend.rs Outdated Show resolved Hide resolved
src/services/ftp/backend.rs Show resolved Hide resolved
src/services/ftp/backend.rs Show resolved Hide resolved
@Xuanwo
Copy link
Member

Xuanwo commented Sep 3, 2022

I have to admit that we (reviewers) made a mistake.

Reusing the same connection makes everything complex:

  • We can't use async API because we can't init the stream during build
    • Thus, we can't use put_with_stream because the requirement for the reader is different.
  • We can't return the reader/dirstream to users because they referred to FtpStream.
    • Thus, we have to read them in memory slower than multiple connections.

I plan to merge this PR and leave this improvement as new issue.

  • Use multiple connections instead of reusing the same one.
  • In the future, we can implement a connection pool for FTP connections.

Ignore unaffected vulnerability.

"src/services/ftp/backend.rs":
Added other options insde from_iter() function.
Removed unused code.

"src/services/ftp/backend.rs":
Use resume_transfer() function for offset.

"src/services/ftp/backend.rs":
fixed minor reference bug.

"examples/ftp.rs":
fixed minor reference bug.
@Xuanwo
Copy link
Member

Xuanwo commented Sep 4, 2022

Great work!

@Xuanwo Xuanwo merged commit b19979a into apache:main Sep 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants