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

replace file system with file builder #96

Merged
merged 3 commits into from
Sep 9, 2021
Merged

replace file system with file builder #96

merged 3 commits into from
Sep 9, 2021

Conversation

tabokie
Copy link
Member

@tabokie tabokie commented Sep 7, 2021

Signed-off-by: tabokie xy.tao@outlook.com

Replace file system(#91) with an Allocator-like type FileBuilder.

File builder is better, it's strongly typed with our own file writer/reader, so that 1) we don't need to propagate Send and Sync trait bound outside of this library, 2) user writers or readers are promised to use our writer/reader as a backend.

There still are some reasonable requirements on user types, such as no buffering and no length altering, which are documented in trait definition.

Related: TiKV commit that implements a FileBuilder for encryption and rate limiting.

@tabokie
Copy link
Member Author

tabokie commented Sep 7, 2021

@yiwu-arbug @Connor1996 @MrCroxx Could any of you help take a look at this while you have time? The FileBuilder trait uses an incomplete feature rust-lang/rust#44265 which I haven't found an alternative to work around. Maybe you have better idea.

@skyzh
Copy link
Member

skyzh commented Sep 7, 2021

@yiwu-arbug @Connor1996 @MrCroxx Could any of you help take a look at this while you have time? The FileBuilder trait uses an incomplete feature rust-lang/rust#44265 which I haven't found an alternative to work around. Maybe you have better idea.

GAT will be stable soon. I think it's okay to use it.

path: &Path,
reader: R,
) -> Result<Self::Reader<R>, Box<dyn std::error::Error>>
where

This comment was marked as resolved.

pub trait FileBuilder: Send + Sync {
/// Types of outcome file reader/writer. They must not alter the length of
/// bytes stream, nor buffer bytes between operations.
type Reader<R: Seek + Read>: Seek + Read;
Copy link
Member

Choose a reason for hiding this comment

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

type Reader: Seek + Read should be enough? Then all across the file builder should use Reader.

Copy link
Member Author

Choose a reason for hiding this comment

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

It is enough, but then we can't guarantee the implementor will actually use R/W from typing perspective. Though I'm not sure this is the idiomatic way to contracting such requirement.

Copy link
Member Author

Choose a reason for hiding this comment

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

Also, I think it would be hard for implementor to wrap a generic R/W into a non-generic Reader type.

@tabokie
Copy link
Member Author

tabokie commented Sep 7, 2021

@yiwu-arbug @Connor1996 @MrCroxx Could any of you help take a look at this while you have time? The FileBuilder trait uses an incomplete feature rust-lang/rust#44265 which I haven't found an alternative to work around. Maybe you have better idea.

GAT will be stable soon. I think it's okay to use it.

Good to know! Reviews are still welcome.

Signed-off-by: tabokie <xy.tao@outlook.com>
Signed-off-by: tabokie <xy.tao@outlook.com>
@Connor1996
Copy link
Member

@yiwu-arbug @Connor1996 @MrCroxx Could any of you help take a look at this while you have time? The FileBuilder trait uses an incomplete feature rust-lang/rust#44265 which I haven't found an alternative to work around. Maybe you have better idea.

LGTM

@@ -116,10 +59,7 @@ impl LogFd {
}

pub fn sync(&self) -> IoResult<()> {
let start = Instant::now();
let res = fsync(self.0).map_err(|e| from_nix_error(e, "fsync"));
LOG_SYNC_TIME_HISTOGRAM.observe(start.saturating_elapsed().as_secs_f64());
Copy link
Member

Choose a reason for hiding this comment

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

keep the metrics?

Copy link
Member Author

Choose a reason for hiding this comment

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

They are actually moved out to file_pipe_log.rs.

@tabokie tabokie merged commit dc20bab into tikv:master Sep 9, 2021
@tabokie tabokie deleted the fs branch September 9, 2021 12:59
@tabokie tabokie mentioned this pull request Dec 6, 2021
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