-
-
Notifications
You must be signed in to change notification settings - Fork 94
Correct the use of ::read() #1025
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
Conversation
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.
I did not run this on my machine, since it is very hard to test for this case, but from looking at the code and the man page this seems to be correct.
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.
I'm a bit on the fence. There are two changes here (which would have been nice to make explicit, either via commit message or comment):
- Do not fail when
read(2)
returns 0. - Busy-loop until all requested bytes are fetched.
Is this correct?
Maybe we need a check for |
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.
There seems to be a bug though: you are overwriting the same buffer
multiple times instead of advancing the pointer by taken
.
6a74f84
to
aa3832e
Compare
It looks correct now. However, the fact that the first review didn't catch this immediately indicates that we need a more objective way to verify the functionality. How would you suggest we test this? A unit test that reads a large file? |
I think the function signature is not good, actually. It should return auto xs = span<byte>{...};
auto n = read(xs);
if (!n)
// failure
else if (*n != xs.size())
// partial read The |
a017bc6
to
e5a4621
Compare
Why are we changing the implementation of the POSIX wrappers so dramatically with the latest changes? Wasn't it almost working already? |
libvast/test/filesystem.cpp
Outdated
|
||
FIXTURE_SCOPE(chunk_tests, fixtures::filesystem) | ||
|
||
// This test takes almost one minute on macOS 10.14. |
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.
In CI or in general?
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.
Or rather: With HFS oder APFS?
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.
In general with APFS on my office iMac.
@mavam As discussed I figured out how to use the level 2 API correctly on macOS. The code can now be reviewed again. |
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.
I like the current solution.
One last thing: please add a changelog entry about the bugfix since this was a user-reported error.
We now take care to not call `::read` and `::write` with more than `INT_MAX` bytes.
Co-authored-by: Matthias Vallentin <matthias@tenzir.com>
We now let the caller decided wheter reading a smaller-than-expected file is a problem or not.
0fbe4f7
to
0577cfc
Compare
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.
I hate to be piling on here, but imho read/write
are not good names for these functions. There is already a well-known function called read(int, void*, size_t)
that everyone is familiar with, and from looking at the name and signature I'd expect a function called posix::read()
to be just a thing wrapper around that. As is, everybody glancing at that will assume there is a bug in the calling code because we dont retry in case of a partial read.
I dont mind committing this now to get the bugfix out to DCSO, but imho renaming this to something like read_all()
/safe_read()
/read_n()
/etc. (that can maybe call the actual read internally) should be the near-term goal.
Addendum to the above: I just realized that the API change is bigger than I initially thought. Usually one passes an upper bound to |
That is not the case, see https://github.com/tenzir/vast/pull/1025/files#diff-4d6b0fc0d187a8a24760ed369528e14fR272-R273. |
No description provided.