MySQL 9.0.0
Source Code Documentation
Basic_binlog_ifile Class Referenceabstract

Base class of binlog input files. More...

#include <binlog_istream.h>

Inheritance diagram for Basic_binlog_ifile:
[legend]

Public Member Functions

 Basic_binlog_ifile (Binlog_read_error *binlog_read_error)
 
 Basic_binlog_ifile (const Basic_binlog_ifile &)=delete
 
Basic_binlog_ifileoperator= (const Basic_binlog_ifile &)=delete
 
 ~Basic_binlog_ifile () override
 
bool open (const char *file_name)
 Open a binlog file. More...
 
void close ()
 Close the binlog file it is reading. More...
 
ssize_t read (unsigned char *buffer, size_t length) override
 Read some bytes from the input stream. More...
 
bool seek (my_off_t position) override
 Puts the read position to a given offset. More...
 
my_off_t position () const
 
bool is_open () const
 
const std::string & file_name () const
 
my_off_t length () override
 Get length of the binlog file. More...
 
- Public Member Functions inherited from Basic_seekable_istream
 ~Basic_seekable_istream () override=default
 
- Public Member Functions inherited from Basic_istream
virtual ~Basic_istream ()=default
 

Protected Member Functions

virtual std::unique_ptr< Basic_seekable_istreamopen_file (const char *file_name)=0
 Open the system layer file. More...
 

Protected Attributes

Binlog_read_errorm_error
 It is convenient for caller to share a Binlog_read_error object between streams. More...
 

Private Member Functions

bool read_binlog_magic ()
 Read binlog magic from binlog file and check if it is valid binlog magic. More...
 

Private Attributes

my_off_t m_position = 0
 The binlog's position where it is reading. More...
 
std::unique_ptr< Basic_seekable_istreamm_istream
 It is the entry of the low level stream pipeline. More...
 
std::string m_file_name
 Name of the file opened. More...
 

Detailed Description

Base class of binlog input files.

It is a logical binlog file which wraps and hides the detail of lower layer storage implementation. Binlog reader and other binlog code just uses this class to control real storage.

Constructor & Destructor Documentation

◆ Basic_binlog_ifile() [1/2]

Basic_binlog_ifile::Basic_binlog_ifile ( Binlog_read_error binlog_read_error)
Parameters
[in]binlog_read_errorBasic_binlog_ifile doesn't own an Binlog_read_error. So the caller should provide one to it. When error happens, the error type will be set into 'error'.

◆ Basic_binlog_ifile() [2/2]

Basic_binlog_ifile::Basic_binlog_ifile ( const Basic_binlog_ifile )
delete

◆ ~Basic_binlog_ifile()

Basic_binlog_ifile::~Basic_binlog_ifile ( )
override

Member Function Documentation

◆ close()

void Basic_binlog_ifile::close ( )

Close the binlog file it is reading.

◆ file_name()

const std::string & Basic_binlog_ifile::file_name ( ) const
inline

◆ is_open()

bool Basic_binlog_ifile::is_open ( ) const
inline

◆ length()

my_off_t Basic_binlog_ifile::length ( )
overridevirtual

Get length of the binlog file.

It is not os file length. The content maybe encrypted or compressed. It is the total length of BINLOG_MAGIC and all raw binlog events.

Implements Basic_seekable_istream.

◆ open()

bool Basic_binlog_ifile::open ( const char *  file_name)

Open a binlog file.

Parameters
[in]file_namename of the binlog file which will be opened.

◆ open_file()

virtual std::unique_ptr< Basic_seekable_istream > Basic_binlog_ifile::open_file ( const char *  file_name)
protectedpure virtual

Open the system layer file.

It is the entry of the stream pipeline. Implementation is delegated to sub-classes. Sub-classes opens system layer files in different way.

Parameters
[in]file_namename of the binlog file which will be opened.

Implemented in Binlog_ifile, and Relaylog_ifile.

◆ operator=()

Basic_binlog_ifile & Basic_binlog_ifile::operator= ( const Basic_binlog_ifile )
delete

◆ position()

my_off_t Basic_binlog_ifile::position ( ) const
inline

◆ read()

ssize_t Basic_binlog_ifile::read ( unsigned char *  buffer,
size_t  length 
)
overridevirtual

Read some bytes from the input stream.

It should read exact 'length' bytes unless error happens or it reaches the end of the stream. It should block when reaching the end of a pipe that is not closed.

Parameters
[out]bufferWhere data will be put in.
[in]lengthThe number of bytes that you want to read. length should not be larger than max long.
Returns
Return values fall into three cases:
Return values
'length'Read 'length' bytes successfully
>=0Reach EOF, return the number of bytes actually read. It is between 0 and length-1.
-1Error.

Implements Basic_istream.

◆ read_binlog_magic()

bool Basic_binlog_ifile::read_binlog_magic ( )
private

Read binlog magic from binlog file and check if it is valid binlog magic.

This function also takes care of setting up any other stream layer (i.e. encryption) when needed.

Return values
falseThe high level stream layer was recognized as a binary log.
trueFailure identifying the high level stream layer.

◆ seek()

bool Basic_binlog_ifile::seek ( my_off_t  offset)
overridevirtual

Puts the read position to a given offset.

The offset counts from the beginning of the stream. In case an implementing class transforms the data in a way that does not preserve positions, the offset here will be relative to the bytes that are read out from the stream, not relative to the bytes in lower layer storage.

it is allowed for a subclass to return success even if the position is greater than the size of the file. Error may be returned by the next read for this case. Users should call length() if they need to check that the position is within bounds.

Parameters
[in]offsetWhere the read position will be.
Return values
falseSuccess
trueError

Implements Basic_seekable_istream.

Member Data Documentation

◆ m_error

Binlog_read_error* Basic_binlog_ifile::m_error
protected

It is convenient for caller to share a Binlog_read_error object between streams.

So Binlog_read_error pointer is defined here. It should be initialized in constructor by caller.

◆ m_file_name

std::string Basic_binlog_ifile::m_file_name
private

Name of the file opened.

◆ m_istream

std::unique_ptr<Basic_seekable_istream> Basic_binlog_ifile::m_istream
private

It is the entry of the low level stream pipeline.

◆ m_position

my_off_t Basic_binlog_ifile::m_position = 0
private

The binlog's position where it is reading.

It is the position in logical binlog file, but not the position of system file.


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