-
Notifications
You must be signed in to change notification settings - Fork 19
Update Thrift IO structs, add file sink #129
Conversation
@sunchao could you review this PR, please? I am open to suggestions for new names of structs!
Thanks! |
Pull Request Test Coverage Report for Build 547
💛 - Coveralls |
Thanks @sadikovi . I think you are right: |
src/util/io.rs
Outdated
use thrift::transport::TWriteTransport; | ||
|
||
// ---------------------------------------------------------------------- | ||
// Read/write wrappers for `File`. |
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.
nit: Read/write
-> Read/Write
?
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.
Sorry for that, will fix.
|
||
/// Struct that represents `File` output stream with position tracking. | ||
/// Used as a sink in file writer. | ||
pub struct FileSink { |
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.
Since we named this FileSink
, should we rename FileChunk
to FileSource
?
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.
Yep, sounds good - will update.
src/util/io.rs
Outdated
// Thrift IO. | ||
|
||
/// A thin read-only wrapper on `T: Read` to be used by Thrift transport. | ||
pub struct TInputBuffer<'a, T> where T: 'a + Read { |
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.
These (both TInputBuffer
and TOutputBuffer
) do not seem necessary anymore as we can pass Read
and Write
to Thrift transport.
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, you are right. I also made changes in the prototype branch to check it compiles. Will remove.
@sunchao I updated the PR. We do not use Thrift wrappers, and I replaced But we only support Let me know if this is required, I will update the code. |
@sadikovi : could you explain the motivation for tracking cursor position without flushing the internal buffer to file? is this about sharing file handle among multiple sinks? Also, could we also implement |
@sunchao My main idea was minimising number of flushes to a file. We need to extract position quite a few times in the writer, so I thought we should make sure that it does not result in any unnecessary IO. Note that we only need to know the current position, we do not seek in the writer. Let me know what you think. For FileSource, do we need to implement all |
@sadikovi : I see. Sorry for the confusion. In that case, maybe we don't need I can work on implementing |
Yes, you are right. I was thinking if we should instead add Position trait, so both FileSource and FileSeek could implement it. They both have a pointer to the current position. Let me know what you think. The reason for me to have a trait was testing - I could use |
Sounds good @sadikovi . I agree with you. |
Okay, thanks. Will make the changes and let you know. |
I updated the code:
|
@sunchao Let me know if we need to change/update anything! |
Looks good @sadikovi . Merged. Thanks! |
@sunchao Thanks for merging! |
This PR makes the following changes:
FileSink
, which is a buffered wrapper on astd::fs::File
and also tracks position without requiring the flush data into a file.FileChunk
intoFileSource
TMemoryBuffer
, as we do not really need it.