Fix for data are not flushed to disk in context of Kvs::flush()#254
Fix for data are not flushed to disk in context of Kvs::flush()#254tizava wants to merge 4 commits intoeclipse-score:mainfrom
Conversation
License Check Results🚀 The license check job ran with the Bazel command: bazel run --lockfile_mode=error //:license-checkStatus: Click to expand output |
|
The created documentation from the pull request is available at: docu-html |
arkjedrz
left a comment
There was a problem hiding this comment.
Overall LGTM, small issues observed.
| /* Helper: write data to a file and ensure it reaches physical storage.*/ | ||
| score::ResultBlank Kvs::write_and_sync(const std::string& path, const void* data, std::size_t size) | ||
| { | ||
| auto file_deleter = [](std::FILE* f) { |
There was a problem hiding this comment.
Is this actually a deleter? This looks more like FILE cleanup.
There was a problem hiding this comment.
From the point of view of a smart pointer (std::unique_ptr in this case) it is a deleter as it frees memory resources (through fclose) when the smart pointer ends its life when exiting the scope according to the RAII paradigm.
src/cpp/src/kvs.cpp
Outdated
| return score::MakeUnexpected(ErrorCode::PhysicalStorageFailure); | ||
| } | ||
|
|
||
| /* Flush the C library buffer to the OS. */ |
There was a problem hiding this comment.
Is it a "flush of a C library buffer", or "flush buffer to the OS using C library"? Why mention C library at all?
There was a problem hiding this comment.
I think it's better "flush the buffer to the OS" without mentioning the C library. I'll push a fix.
Fixes: 252
In old implementation data were only written using std::fostream, which is an asynchronous API.
Flush to the physical storage is required as well to ensure all the data are persisted.
The std::ostream::flush() will only flush the C++ buffer to OS (Not to the disk), therefore fstream API has been replaced with cstdio.
Posix fdatasync() API, which is synchronous is now called to ensure all buffers are properly flushed.