24#ifndef BINLOG_OSTREAM_INCLUDED
25#define BINLOG_OSTREAM_INCLUDED
27#include <openssl/evp.h>
48template <
class ISTREAM,
class OSTREAM>
50 bool *ostream_error =
nullptr) {
52 unsigned char *
buffer =
nullptr;
56 while (!ret &&
length > 0) {
58 if (ostream_error !=
nullptr) *ostream_error =
true;
98 bool seek(
my_off_t offset [[maybe_unused]])
override {
return true; }
138 bool flush()
override {
return false; }
139 bool sync()
override {
return false; }
259 bool open(std::unique_ptr<Truncatable_ostream> down_ostream);
272 bool open(std::unique_ptr<Truncatable_ostream> down_ostream,
273 std::unique_ptr<Rpl_encryption_header> header);
284 std::pair<bool, std::string>
reencrypt();
290 bool flush()
override;
291 bool sync()
override;
bool stream_copy(ISTREAM *istream, OSTREAM *ostream, bool *ostream_error=nullptr)
Copy data from an input stream to an output stream.
Definition: binlog_ostream.h:49
bool binlog_cache_is_reset
Definition: binlog_ostream.cc:38
The abstract class for basic output streams which provides write operation.
Definition: basic_ostream.h:37
virtual bool write(const unsigned char *buffer, my_off_t length)=0
Write some bytes into the output stream.
Byte container that provides a storage for serializing session binlog events.
Definition: binlog_ostream.h:174
bool truncate(my_off_t offset)
Truncates some data at the end of the binlog cache.
Definition: binlog_ostream.h:192
~Binlog_cache_storage() override
Definition: binlog_ostream.cc:267
my_off_t length() const
Returns data length.
Definition: binlog_ostream.h:230
IO_CACHE_binlog_cache_storage m_file
Definition: binlog_ostream.h:238
bool is_empty() const
Returns true if binlog cache is empty.
Definition: binlog_ostream.h:234
Truncatable_ostream * m_pipeline_head
Definition: binlog_ostream.h:237
bool open(my_off_t cache_size, my_off_t max_cache_size)
Definition: binlog_ostream.cc:253
bool reset()
Reset status and drop all data.
Definition: binlog_ostream.h:198
size_t disk_writes() const
Returns the count of disk writes.
Definition: binlog_ostream.h:202
const char * tmp_file_name() const
Returns the name of the temporary file.
Definition: binlog_ostream.h:206
bool copy_to(Basic_ostream *ostream, bool *ostream_error=nullptr)
Copy all data to a output stream.
Definition: binlog_ostream.h:222
bool write(const unsigned char *buffer, my_off_t length) override
Write some bytes into the output stream.
Definition: binlog_ostream.h:181
void close()
Definition: binlog_ostream.cc:262
It is an Truncatable_ostream which provides encryption feature.
Definition: binlog_ostream.h:246
int get_header_size()
Return the encrypted file header size.
Definition: binlog_ostream.cc:411
bool open(std::unique_ptr< Truncatable_ostream > down_ostream)
Initialize the context used in the encryption stream and write encryption header into down stream.
Definition: binlog_ostream.cc:280
std::unique_ptr< Rpl_encryption_header > m_header
Definition: binlog_ostream.h:301
std::unique_ptr< Truncatable_ostream > m_down_ostream
Definition: binlog_ostream.h:300
std::unique_ptr< Stream_cipher > m_encryptor
Definition: binlog_ostream.h:302
void close()
Definition: binlog_ostream.cc:363
std::pair< bool, std::string > reencrypt()
Re-encrypt the encrypted binary/relay log file header by replacing its binlog encryption key id with ...
Definition: binlog_ostream.cc:316
bool write(const unsigned char *buffer, my_off_t length) override
Write some bytes into the output stream.
Definition: binlog_ostream.cc:369
bool sync() override
Sync.
Definition: binlog_ostream.cc:409
~Binlog_encryption_ostream() override
Definition: binlog_ostream.cc:269
bool flush() override
Flush data.
Definition: binlog_ostream.cc:407
bool truncate(my_off_t offset) override
Truncate some data at the end of the output stream.
Definition: binlog_ostream.cc:401
bool seek(my_off_t offset) override
Put the write position to a given offset.
Definition: binlog_ostream.cc:396
A binlog cache implementation based on IO_CACHE.
Definition: binlog_ostream.h:70
void disable_encryption()
Disable IO Cache temporary file encryption.
Definition: binlog_ostream.cc:223
bool seek(my_off_t offset) override
Put the write position to a given offset.
Definition: binlog_ostream.h:98
const char * tmp_file_name() const
Returns the file name if a temporary file is opened, otherwise nullptr is returned.
Definition: binlog_ostream.cc:147
my_off_t m_max_cache_size
Definition: binlog_ostream.h:143
IO_CACHE_binlog_cache_storage(const IO_CACHE_binlog_cache_storage &)=delete
bool sync() override
Sync.
Definition: binlog_ostream.h:139
bool begin(unsigned char **buffer, my_off_t *length)
Initializes binlog cache for reading and returns the data at the begin.
Definition: binlog_ostream.cc:151
IO_CACHE_binlog_cache_storage & operator=(const IO_CACHE_binlog_cache_storage &)=delete
bool flush() override
Flush data.
Definition: binlog_ostream.h:138
bool reset()
Reset status and drop all data.
Definition: binlog_ostream.cc:108
bool truncate(my_off_t offset) override
Truncate some data at the end of the output stream.
Definition: binlog_ostream.cc:93
IO_CACHE_binlog_cache_storage()
bool setup_ciphers_password()
Generate a new password for the temporary file encryption.
Definition: binlog_ostream.cc:234
size_t disk_writes() const
Returns the count of calling temporary file's write()
Definition: binlog_ostream.cc:143
bool open(const char *dir, const char *prefix, my_off_t cache_size, my_off_t max_cache_size)
Opens the binlog cache.
Definition: binlog_ostream.cc:44
my_off_t length() const
Definition: binlog_ostream.cc:196
bool enable_encryption()
Enable IO Cache temporary file encryption.
Definition: binlog_ostream.cc:201
void close()
Definition: binlog_ostream.cc:59
IO_CACHE m_io_cache
Definition: binlog_ostream.h:142
~IO_CACHE_binlog_cache_storage() override
Definition: binlog_ostream.cc:42
bool write(const unsigned char *buffer, my_off_t length) override
Write some bytes into the output stream.
Definition: binlog_ostream.cc:61
bool next(unsigned char **buffer, my_off_t *length)
Returns next piece of data.
Definition: binlog_ostream.cc:184
Truncatable_ostream abstract class provides seek() and truncate() interfaces to all truncatable outpu...
Definition: basic_ostream.h:58
virtual bool truncate(my_off_t offset)=0
Truncate some data at the end of the output stream.
#define DBUG_TRACE
Definition: my_dbug.h:146
ulonglong my_off_t
Definition: my_inttypes.h:72
std::string dir
Double write files location.
Definition: buf0dblwr.cc:77
bool length(const dd::Spatial_reference_system *srs, const Geometry *g1, double *length, bool *null) noexcept
Computes the length of linestrings and multilinestrings.
Definition: length.cc:76
mutable_buffer buffer(void *p, size_t n) noexcept
Definition: buffer.h:418
This file includes the major components for encrypting/decrypting binary log files.
static uint64_t cache_size
Definition: xcom_cache.cc:362