-
Notifications
You must be signed in to change notification settings - Fork 973
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# Description Resolves #4546 This change calls fsync after writing `BucketIndex` files. This change was slightly more involved than expected. There's no way to fall fsync on files opened via `std::fstream`, so I had to implement a new cereal archive type that accepts our own `asio::buffered_write_streamasio::buffered_write_stream` backed stream type. # Checklist - [x] Reviewed the [contributing](https://github.com/stellar/stellar-core/blob/master/CONTRIBUTING.md#submitting-changes) document - [x] Rebased on top of master (no merge commits) - [x] Ran `clang-format` v8.0.0 (via `make format` or the Visual Studio extension) - [x] Compiles - [x] Ran all tests - [ ] If change impacts performance, include supporting evidence per the [performance document](https://github.com/stellar/stellar-core/blob/master/performance-eval/performance-eval.md)
- Loading branch information
Showing
9 changed files
with
200 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
#pragma once | ||
|
||
#include "util/XDRStream.h" | ||
#include <cereal/archives/binary.hpp> | ||
#include <cereal/cereal.hpp> | ||
|
||
namespace cereal | ||
{ | ||
|
||
// Mirrors CEREAL_ARCHIVE_RESTRICT from cereal/details/traits.hpp for single | ||
// types | ||
#define CEREAL_ARCHIVE_RESTRICT_SINGLE_TYPE(TYPE) \ | ||
typename std::enable_if< \ | ||
cereal::traits::is_same_archive<Archive, TYPE>::value, void>::type | ||
|
||
// This is a basic reimplementation of BinaryOutputArchive | ||
// (cereal/archives/binary.hpp) that uses our own OutputFileStream instead of | ||
// std::ofstream for writes in order to support fsync. For input we can just use | ||
// cereal's BinaryInputArchive because we don't care about fsync for reads. | ||
class BufferedAsioOutputArchive | ||
: public OutputArchive<BufferedAsioOutputArchive, AllowEmptyClassElision> | ||
{ | ||
public: | ||
// Construct, outputting to the provided stream | ||
// @param stream The stream to output to. Can be a stringstream, a file | ||
// stream, or even cout! | ||
BufferedAsioOutputArchive(stellar::OutputFileStream& stream) | ||
: OutputArchive<BufferedAsioOutputArchive, AllowEmptyClassElision>(this) | ||
, itsStream(stream) | ||
{ | ||
} | ||
|
||
~BufferedAsioOutputArchive() CEREAL_NOEXCEPT = default; | ||
|
||
// Writes size bytes of data to the output stream | ||
void | ||
saveBinary(const void* data, std::streamsize size) | ||
{ | ||
itsStream.writeBytes(static_cast<char const*>(data), size); | ||
} | ||
|
||
private: | ||
stellar::OutputFileStream& itsStream; | ||
}; | ||
|
||
// Saving for POD types to binary | ||
template <class T> | ||
inline typename std::enable_if<std::is_arithmetic<T>::value, void>::type | ||
CEREAL_SAVE_FUNCTION_NAME(BufferedAsioOutputArchive& ar, T const& t) | ||
{ | ||
ar.saveBinary(std::addressof(t), sizeof(t)); | ||
} | ||
|
||
// Serializing NVP types to binary | ||
template <class Archive, class T> | ||
|
||
inline CEREAL_ARCHIVE_RESTRICT_SINGLE_TYPE(BufferedAsioOutputArchive) | ||
CEREAL_SERIALIZE_FUNCTION_NAME(Archive& ar, NameValuePair<T>& t) | ||
{ | ||
ar(t.value); | ||
} | ||
|
||
// Serializing SizeTags to binary | ||
template <class Archive, class T> | ||
inline CEREAL_ARCHIVE_RESTRICT_SINGLE_TYPE(BufferedAsioOutputArchive) | ||
CEREAL_SERIALIZE_FUNCTION_NAME(Archive& ar, SizeTag<T>& t) | ||
{ | ||
ar(t.size); | ||
} | ||
|
||
// Saving binary data | ||
template <class T> | ||
inline void | ||
CEREAL_SAVE_FUNCTION_NAME(BufferedAsioOutputArchive& ar, | ||
BinaryData<T> const& bd) | ||
{ | ||
ar.saveBinary(bd.data, static_cast<std::streamsize>(bd.size)); | ||
} | ||
} | ||
|
||
CEREAL_REGISTER_ARCHIVE(cereal::BufferedAsioOutputArchive) |
Oops, something went wrong.