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

[BugFix] do flush before error check in BinaryOutputArchive (backport #48074) #48120

Merged
merged 2 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions be/src/storage/persistent_index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1798,6 +1798,12 @@ Status ShardByLengthMutableIndex::commit(MutableIndexMetaPB* meta, const EditVer
LOG(WARNING) << err_msg;
return Status::InternalError(err_msg);
}
if (!ar_out.close()) {
std::string err_msg =
strings::Substitute("failed to dump snapshot to file $0, because of close", file_name);
LOG(WARNING) << err_msg;
return Status::InternalError(err_msg);
}
}
// dump snapshot success, set _index_file to new snapshot file
WritableFileOptions wblock_opts;
Expand Down
11 changes: 9 additions & 2 deletions be/src/util/phmap/phmap_dump.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,13 +235,20 @@ class BinaryOutputArchive {

bool dump(const char* p, size_t sz) {
ofs_.write(p, sz);
return ofs_.good();
return !ofs_.fail();
}

template <typename V>
typename std::enable_if<type_traits_internal::IsTriviallyCopyable<V>::value, bool>::type dump(const V& v) {
ofs_.write(reinterpret_cast<const char*>(&v), sizeof(V));
return ofs_.good();
return !ofs_.fail();
}

bool close() {
ofs_.flush(); // do flush, so we can check if it success at next line.
if (ofs_.fail()) return false;
ofs_.close();
return !ofs_.fail();
}

private:
Expand Down
Loading