Use system call I/O in PosixSequentialFile instead of libc stdio to avoid extra buffer copies and FreeBSD stdio open file limits #14229
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PosixSequentialFile as currently implemented opens a file using posix system calls, then uses buffered libc stdio to wrap the file descriptor and perform all subsequent I/O.
As users of PosixSequentialFile handle their own buffering, the additional buffering provided by stdio introduces needless additional copying of memory on I/O. Notably none of the other Posix*File classes (PosixWritableFile, PosixRandomAccessFile, PosixMmapFile, etc.) make any use of libc stdio calls relying exclusively on file descriptors and posix system calls.
Finally some platforms' libc stdio implementations are limited and fail unexpectedly in the face of large numbers of open file description, most notably FreeBSD's libc stdio which causes rocksdb to fail when more than 32,767 files are open.
This pull request removes the FILE file member from PosixSequentialFile and replaces use of stdio fdopen/fread/fseek/fclose calls with the equivalent -/read/lseek/close system calls instead.
Note there is additional code in function PosixHelper::GetQueueSysfsFileValueOfFd() in env/io_posix.cc that uses libc stdio fopen() and friends to read files under /sys/dev/block however this code is all under an #ifdef OS_LINUX condition compile block and so is not present in FreeBSD builds hence was left alone for the purposes of this pull request.
During development the following trivial bugs arose and were fixed in this pull request as well: