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
fsreplace1
should fallocate()
#20352
Comments
A quick look into implementing this shows that this isn't really much of a consideration. Two reasons:
|
That'd just be a protocol/program bug. But I suppose you mean that at this point we send a wrong (outdated) size? I suppose writing more data than set with fallocate is relatively harmless -- the file would hopefully just grow (with a potential ENOSPC of course). If it shrinks, the channel could maybe do a final ftruncate()? |
Ya. I think fruncate() might be worthwhile here. The bookkeeping gets a bit annoying, though. There's no variant of fruncate that accepts "to the current offset", so we'd either need to do a seek call to find out, or keep a counter while we're writing. Neither of those would be the end of the world... |
This approach has one drawback: if we |
Seek call seems nice. And I do like knowing up front that you have ENOSPACE, that is a great improvement thanks for opening this issue!
That is weird, and this should be ordered no? open I thought the protocol guaranteed this order. |
Until now we've been using fsreplace1 for very small files, but we're going to be using it to upload potentially large files in the future.
It occurred to me that — particularly on extent-based filesystems — best practice is to fallocate() the full size of the file in advance. This has two major advantages:
Python has
os.posix_fallocate()
since at least 3.6: https://docs.python.org/3.6/library/os.html#os.posix_fallocateJust as we recently added to
fsread1
, we could create asize-hint
forfsreplace1
which results in the temporary file being created immediately andposix_fallocate()
being called on it.One consideration: the "hint" in the name in this case is potentially problematic, though, since this would be more than a hint:
posix_fallocate()
doesn't merely allocate the space: it also changes the length of the file. Also: the creation of the tempfile as soon as the channel opens sort of excludes the possibility of then deleting the file. For this reason, it's more than a "hint" and maybe should just be calledsize
— unless we go out of our way to truncate the data back to the received size again in case we get less than we were expecting (which could be desirable if we ever wanted to support resuming uploads or something like that).Another consideration: we implemented
upload()
incockpit-upload-helper.ts
as an operation on aReadableStream
, but this doesn't let us determine the overall size of the file. Maybe it would be better to change this back to being aBlob
, or to give some other way to provide the size.cc: @jelly
The text was updated successfully, but these errors were encountered: