MySQL 26.7.0
Source Code Documentation
mysql::csa::Istream_prefetched Class Reference

Implementation of the Basic_istream, which reads data from the prefetched relay log. More...

#include <istream_prefetched.h>

Inheritance diagram for mysql::csa::Istream_prefetched:
[legend]

Public Member Functions

 Istream_prefetched (Log_prefetcher_sptr prefetcher, const std::string &file_name)
 Construct from prefetcher. More...
 
ssize_t read (unsigned char *buffer, std::size_t length) override
 Read requested number of bytes from the input stream. More...
 
bool seek (my_off_t offset) override
 If possible, seeks to a given file offset. More...
 
my_off_t length () override
 Returns currently opened file length... More...
 
virtual ~Istream_prefetched () override=default
 
- Public Member Functions inherited from Basic_seekable_istream
virtual ~Basic_seekable_istream () override=default
 
- Public Member Functions inherited from Basic_istream
virtual ssize_t read (unsigned char *buffer, size_t length)=0
 Read some bytes from the input stream. More...
 
virtual ~Basic_istream ()=default
 

Private Types

using Batch_type = Log_prefetcher::Elem_type
 

Private Member Functions

void copy_to (unsigned char *buffer, std::size_t &buffer_offset, std::size_t bytes)
 Helper function that copies the requested number of bytes from the current batch into buffer, using the current buffer offset. More...
 
ssize_t skip (std::size_t length)
 Skips requested number of bytes. More...
 
bool read_next_batch ()
 Reads the next batch. More...
 

Private Attributes

Log_prefetcher_sptr m_prefetcher
 Prefetcher that asynchronously fetches chunks of data from the relay log. More...
 
std::string m_allowed_file_name {""}
 Prefetcher works asynchronously on the whole relay log. More...
 
Batch_type m_current_batch
 Batch currently in use. More...
 
std::size_t m_current_offset {0}
 Current batch offset. More...
 
std::atomic< bool > m_is_stopped {false}
 Variable used to stop waiting for data (read may block) More...
 
bool m_prefetcher_error {false}
 True in case there has been prefetcher error which needs to be propagated. More...
 
std::size_t m_file_offset {0}
 Offset from start of the file. More...
 

Detailed Description

Implementation of the Basic_istream, which reads data from the prefetched relay log.

Reads cannot go outside a single relay log file boundary (legacy design). Note that prefetcher is able to move across relay log files. Therefore, to read from the next file, it is sufficient to create a new Istream_prefetched object with the same shared prefetcher object. Istream_prefetched allows for:

  • reading requested number of bytes into the preallocated buffer (read)
  • skipping requested number of bytes
  • seeking to a given file position (forward only)
  • length Function that will return the size of the file; length function is implemented as required by the Basic_seekable_istream, however, it is probably not required (note Stdin_binlog_istream has the 'length' function disabled) Istream_prefetched does not add new errors to error model, however, it needs to propagate prefetcher error. In case of prefetcher error, read, skip and seek functions will return an error value.

Member Typedef Documentation

◆ Batch_type

Constructor & Destructor Documentation

◆ Istream_prefetched()

mysql::csa::Istream_prefetched::Istream_prefetched ( Log_prefetcher_sptr  prefetcher,
const std::string &  file_name 
)

Construct from prefetcher.

Parameters
prefetcherPrefetcher object used to obtain data
file_nameThe file we are allowed to read from

◆ ~Istream_prefetched()

virtual mysql::csa::Istream_prefetched::~Istream_prefetched ( )
overridevirtualdefault

Member Function Documentation

◆ copy_to()

void mysql::csa::Istream_prefetched::copy_to ( unsigned char *  buffer,
std::size_t &  buffer_offset,
std::size_t  bytes 
)
private

Helper function that copies the requested number of bytes from the current batch into buffer, using the current buffer offset.

Buffer offset is updated after copy

Parameters
bufferData will be copied into the following address: buffer + buffer_offset
buffer_offsetCurrent buffer offset, which will be advanced after copy
bytesCopies this amount of bytes

◆ length()

my_off_t mysql::csa::Istream_prefetched::length ( )
overridevirtual

Returns currently opened file length...

Returns
file length

Implements Basic_seekable_istream.

◆ read()

ssize_t mysql::csa::Istream_prefetched::read ( unsigned char *  buffer,
std::size_t  length 
)
override

Read requested number of bytes from the input stream.

It will block when reaching the end of the open stream that is not yet prefetched. This function will read beyond the one file boundary if called many times, unless the requested read would be split into several files. In that case, it will return the number of bytes read till reaching the end of the file.

Parameters
bufferPreallocated buffer to >= length or nullptr
lengthThe requested number of bytes to read.
Return values
lengthBytes read
>=0Reached the end of the file or was stopped in the process. EOF : Since one operation cannot go beyond file boundary, operation has been stopped
-1Error, i.e. prefetcher errored out and cannot read more data

◆ read_next_batch()

bool mysql::csa::Istream_prefetched::read_next_batch ( )
private

Reads the next batch.

Return values
trueStopped in the process or source filename changed
falseData read successfully without file change

◆ seek()

bool mysql::csa::Istream_prefetched::seek ( my_off_t  offset)
overridevirtual

If possible, seeks to a given file offset.

Return values
FalseSuccess
TrueCannot seek to requested postion or prefetcher has errored out

Implements Basic_seekable_istream.

◆ skip()

ssize_t mysql::csa::Istream_prefetched::skip ( std::size_t  length)
private

Skips requested number of bytes.

Applies the same rules as for read fuction

Return values
lengthThe requested number of bytes have been skipped
>=0Reached the end of the file or was stopped in the process. EOF : Since one operation cannot go beyond file boundary, operation has been stopped
-1Error, i.e. prefetcher errored out and cannot read more data

Member Data Documentation

◆ m_allowed_file_name

std::string mysql::csa::Istream_prefetched::m_allowed_file_name {""}
private

Prefetcher works asynchronously on the whole relay log.

To comply with implemented structure of Binlog readers, we need to restrict fetching the data to the file that was requested to open. After reaching end of this file, instead of fetching next batches we report EOF.

◆ m_current_batch

Batch_type mysql::csa::Istream_prefetched::m_current_batch
private

Batch currently in use.

◆ m_current_offset

std::size_t mysql::csa::Istream_prefetched::m_current_offset {0}
private

Current batch offset.

◆ m_file_offset

std::size_t mysql::csa::Istream_prefetched::m_file_offset {0}
private

Offset from start of the file.

◆ m_is_stopped

std::atomic<bool> mysql::csa::Istream_prefetched::m_is_stopped {false}
private

Variable used to stop waiting for data (read may block)

◆ m_prefetcher

Log_prefetcher_sptr mysql::csa::Istream_prefetched::m_prefetcher
private

Prefetcher that asynchronously fetches chunks of data from the relay log.

◆ m_prefetcher_error

bool mysql::csa::Istream_prefetched::m_prefetcher_error {false}
private

True in case there has been prefetcher error which needs to be propagated.


The documentation for this class was generated from the following files: