MySQL 8.4.2
Source Code Documentation
mysql_harness::DynamicState Class Reference

DynamicState represents a MySQLRouter dynamic state object. More...

#include <dynamic_state.h>

Classes

struct  Pimpl
 

Public Member Functions

 DynamicState (const std::string &file_name)
 Creates and initializes dynamic state object. More...
 
 ~DynamicState ()
 Destructor. More...
 
bool load ()
 Loads the json state object from the associated file, overwrites the current with the file content. More...
 
bool save (bool is_clusterset, bool pretty=true)
 Saves the json state object to the associated file, overwrites the the file content. More...
 
bool save_to_stream (std::ostream &output_stream, bool is_clusterset, bool pretty=true)
 Saves the json state object to the output stream given as a parameter, overwrites the stream content. More...
 
std::unique_ptr< JsonValueget_section (const std::string &section_name)
 Returns selected state object section by its name. More...
 
bool update_section (const std::string &section_name, JsonValue &&value)
 Updates selected state object section. More...
 

Private Member Functions

bool load_from_stream (std::istream &input_stream)
 
void ensure_valid_against_schema ()
 
void ensure_version_compatibility ()
 
std::ifstream open_for_read ()
 
std::ofstream open_for_write ()
 

Private Attributes

std::unique_ptr< Pimplpimpl_
 
std::string file_name_
 

Detailed Description

DynamicState represents a MySQLRouter dynamic state object.

It's meant to be used as a singleton that provides methods to read/update sections from the specific modules requiring saving their runtime state.

It handles the file handling synchronization, versioning and validation.

Constructor & Destructor Documentation

◆ DynamicState()

mysql_harness::DynamicState::DynamicState ( const std::string &  file_name)

Creates and initializes dynamic state object.

Parameters
file_namepath to the json file where the state is being stored

◆ ~DynamicState()

mysql_harness::DynamicState::~DynamicState ( )
default

Destructor.

Member Function Documentation

◆ ensure_valid_against_schema()

void mysql_harness::DynamicState::ensure_valid_against_schema ( )
private

◆ ensure_version_compatibility()

void mysql_harness::DynamicState::ensure_version_compatibility ( )
private

◆ get_section()

std::unique_ptr< JsonValue > mysql_harness::DynamicState::get_section ( const std::string &  section_name)

Returns selected state object section by its name.

Parameters
section_namename of the section to retrieve
Returns
pointer to the rapidJson object containing the section, nullptr if the section with a given name does not exist

◆ load()

bool mysql_harness::DynamicState::load ( )

Loads the json state object from the associated file, overwrites the current with the file content.

Returns
success of operation
Return values
trueoperation succeeded
falseoperation failed

◆ load_from_stream()

bool mysql_harness::DynamicState::load_from_stream ( std::istream &  input_stream)
private

◆ open_for_read()

std::ifstream mysql_harness::DynamicState::open_for_read ( )
private

◆ open_for_write()

std::ofstream mysql_harness::DynamicState::open_for_write ( )
private

◆ save()

bool mysql_harness::DynamicState::save ( bool  is_clusterset,
bool  pretty = true 
)

Saves the json state object to the associated file, overwrites the the file content.

Parameters
is_clustersettrue if the metadata is configured to work with a ClusterSet, false if a single Cluster
prettyif true the json data is written in a human readable json format
Returns
success of operation
Return values
trueoperation succeeded
falseoperation failed

◆ save_to_stream()

bool mysql_harness::DynamicState::save_to_stream ( std::ostream &  output_stream,
bool  is_clusterset,
bool  pretty = true 
)

Saves the json state object to the output stream given as a parameter, overwrites the stream content.

Parameters
output_streamstream where json content should be written to
is_clustersettrue if the metadata is configured to work with a ClusterSet, false if a single Cluster
prettyif true the json data is written in a human readable json format
Returns
success of operation
Return values
trueoperation succeeded
falseoperation failed

◆ update_section()

bool mysql_harness::DynamicState::update_section ( const std::string &  section_name,
JsonValue &&  value 
)

Updates selected state object section.

Parameters
section_namename of the section to update
valuerapidJson object to replaces the section value
Returns
success of operation
Return values
trueoperation succeeded
falseoperation failed

Member Data Documentation

◆ file_name_

std::string mysql_harness::DynamicState::file_name_
private

◆ pimpl_

std::unique_ptr<Pimpl> mysql_harness::DynamicState::pimpl_
private

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