Skip to content
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

Fix pageutils will truncate the file if write failed #4925

Merged
merged 13 commits into from
May 19, 2022
7 changes: 1 addition & 6 deletions dbms/src/Storages/Page/PageUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,15 +192,10 @@ void writeFile(
{
ProfileEvents::increment(ProfileEvents::PSMWriteFailed);
auto saved_errno = errno;
// If error occurs, apply `ftruncate` try to truncate the broken bytes we have written.
// Note that the result of this ftruncate is ignored, there is nothing we can do to
// handle ftruncate error. The errno may change after ftruncate called.
int truncate_res = ::ftruncate(file->getFd(), offset);

DB::throwFromErrno(fmt::format("Cannot write to file {},[truncate_res = {}],[errno_after_truncate = {}],"
DB::throwFromErrno(fmt::format("Cannot write to file {},[errno_after_truncate = {}],"
"[bytes_written={},to_write={},offset = {}]",
file->getFileName(),
truncate_res,
strerror(errno),
bytes_written,
to_write,
Expand Down