MySQL  8.0.17
Source Code Documentation
Persisted_variables_cache Class Reference

#include <persisted_variable.h>

Public Member Functions

int init (int *argc, char ***argv)
 Initialize class members. More...
 
void set_variable (THD *thd, set_var *system_var)
 Update in-memory copy for every SET PERSIST statement. More...
 
bool flush_to_file ()
 Flush in-memory copy to persistent file. More...
 
int read_persist_file ()
 Read options from persistent file. More...
 
bool load_persist_file ()
 Search for persisted config file and if found read persistent options. More...
 
bool set_persist_options (bool plugin_options=false)
 Set persisted options. More...
 
bool reset_persisted_variables (THD *thd, const char *name, bool if_exists)
 Reset persisted options. More...
 
std::vector< st_persist_var > * get_persisted_variables ()
 Get persisted variables. More...
 
std::map< std::string, st_persist_var > * get_persist_ro_variables ()
 Get persisted static variables. More...
 
bool append_read_only_variables (int *argc, char ***argv, bool plugin_options=false)
 append read only persisted variables to command line options with a separator. More...
 
void cleanup ()
 
void lock ()
 Acquire lock on m_persist_variables/m_persist_ro_variables. More...
 
void unlock ()
 Release lock on m_persist_variables/m_persist_ro_variables. More...
 
void assert_lock_owner ()
 Assert caller that owns lock on m_persist_variables/m_persist_ro_variables. More...
 

Static Public Member Functions

static Persisted_variables_cacheget_instance ()
 Return a singleton object. More...
 

Private Member Functions

bool extract_variables_from_json (const Json_dom *dom, bool is_read_only=false)
 extract_variables_from_json() is used to extract all the variable information which is in the form of Json_object. More...
 
bool open_persist_file (int flag)
 Open persisted config file. More...
 
void close_persist_file ()
 Close persisted config file. More...
 

Static Private Member Functions

static Stringget_variable_value (THD *thd, sys_var *system_var, String *str, bool *is_null)
 Retrieve variables value from sys_var. More...
 
static const char * get_variable_name (sys_var *system_var)
 Retrieve variables name from sys_var. More...
 
static Stringconstruct_json_string (std::string name, std::string value, ulonglong timestamp, std::string user, std::string host, bool is_null, String *dest)
 Given information of variable which needs to be persisted, this function will construct a json foematted string out of it. More...
 

Private Attributes

std::vector< st_persist_varm_persist_variables
 
std::vector< st_persist_varm_persist_plugin_variables
 
std::map< std::string, st_persist_varm_persist_ro_variables
 
mysql_mutex_t m_LOCK_persist_variables
 
MYSQL_FILEm_fd
 
std::string m_persist_filename
 
mysql_mutex_t m_LOCK_persist_file
 
MEM_ROOT ro_persisted_argv_alloc {PSI_NOT_INSTRUMENTED, 512}
 
MEM_ROOT ro_persisted_plugin_argv_alloc {PSI_NOT_INSTRUMENTED, 512}
 

Static Private Attributes

static Persisted_variables_cachem_instance = NULL
 

Member Function Documentation

◆ append_read_only_variables()

bool Persisted_variables_cache::append_read_only_variables ( int *  argc,
char ***  argv,
bool  plugin_options = false 
)

append read only persisted variables to command line options with a separator.

append_read_only_variables() does a lookup into persist_variables for read only variables and place them after the command line options with a separator "----persist-args-separator----"

This function does nothing when –no-defaults is set or if persisted_globals_load is disabled.

Parameters
[in]argcPointer to argc of original program
[in]argvPointer to argv of original program
[in]plugin_optionsThis flag tells wether options are handled during plugin install. If set to true options are handled as part of install plugin.
Returns
0 Success
1 Failure

◆ assert_lock_owner()

void Persisted_variables_cache::assert_lock_owner ( )
inline

Assert caller that owns lock on m_persist_variables/m_persist_ro_variables.

◆ cleanup()

void Persisted_variables_cache::cleanup ( )

◆ close_persist_file()

void Persisted_variables_cache::close_persist_file ( )
private

Close persisted config file.

Returns
void

◆ construct_json_string()

String * Persisted_variables_cache::construct_json_string ( std::string  name,
std::string  value,
ulonglong  timestamp,
std::string  user,
std::string  host,
bool  is_null,
String dest 
)
staticprivate

Given information of variable which needs to be persisted, this function will construct a json foematted string out of it.

Format will be as below for variable named "X": "X" : { "Value" : "value", "Metadata" : { "Timestamp" : timestamp_value, "User" : "user_name", "Host" : "host_name" } }

Parameters
[in]nameVariable name
[in]valueVariable value
[in]timestampTimestamp value when this variable was set
[in]userUser who set this variable
[in]hostHost on which this variable was set
[in]is_nullIs variable value NULL or not.
[out]destString object where json formatted string is stored
Returns
Pointer to String instance holding the json formatted string

◆ extract_variables_from_json()

bool Persisted_variables_cache::extract_variables_from_json ( const Json_dom dom,
bool  is_read_only = false 
)
private

extract_variables_from_json() is used to extract all the variable information which is in the form of Json_object.

New format for mysqld-auto.cnf is as below: { "Version" : 1, "mysql_server" : { "variable_name" : { "Value" : "variable_value", "Metadata" : { "Timestamp" : timestamp_value, "User" : "user_name", "Host" : "host_name" } } } { "variable_name" : { ...

{ "mysql_server_static_options" : { "variable_name" : { "Value" : "variable_value", ... } ... }

Parameters
[in]domPointer to the Json_dom object which is an internal representation of parsed json string
[in]is_read_onlyBool value when set to TRUE extracts read only variables and dynamic variables when set to FALSE.
Returns
0 Success
1 Failure

Static variables by themselves is represented as a json object with key "mysql_server_static_options" as parent element.

Every Json object which represents Variable information must have only 2 elements which is { "Value" : "variable_value", – 1st element "Metadata" : { – 2nd element "Timestamp" : timestamp_value, "User" : "user_name", "Host" : "host_name" } }

◆ flush_to_file()

bool Persisted_variables_cache::flush_to_file ( )

Flush in-memory copy to persistent file.

Convert in-memory copy into a stream of characters and write this stream to persisted config file.

Returns
Error state
Return values
trueAn error occurred
falseSuccess

◆ get_instance()

Persisted_variables_cache * Persisted_variables_cache::get_instance ( )
static

Return a singleton object.

◆ get_persist_ro_variables()

map< string, st_persist_var > * Persisted_variables_cache::get_persist_ro_variables ( )

Get persisted static variables.

Return in-memory copy for static persisted variables.

◆ get_persisted_variables()

vector< st_persist_var > * Persisted_variables_cache::get_persisted_variables ( )

Get persisted variables.

Return in-memory copy persist_variables_.

◆ get_variable_name()

const char * Persisted_variables_cache::get_variable_name ( sys_var system_var)
staticprivate

Retrieve variables name from sys_var.

Parameters
[in]system_varPointer to sys_var which is being SET
Returns
Pointer to buffer holding the name

◆ get_variable_value()

String * Persisted_variables_cache::get_variable_value ( THD thd,
sys_var system_var,
String str,
bool is_null 
)
staticprivate

Retrieve variables value from sys_var.

Parameters
[in]thdPointer to connection handler
[in]system_varPointer to sys_var which is being SET
[in]strPointer to String instance into which value is copied
[out]is_nullIs value NULL or not.
Returns
Pointer to String instance holding the value

◆ init()

int Persisted_variables_cache::init ( int *  argc,
char ***  argv 
)

Initialize class members.

This function reads datadir if present in config file or set at command line, in order to know from where to load this config file. If datadir is not set then read from MYSQL_DATADIR.

Parameters
[in]argcPointer to argc of original program
[in]argvPointer to argv of original program
Returns
0 Success
1 Failure

◆ load_persist_file()

bool Persisted_variables_cache::load_persist_file ( )

Search for persisted config file and if found read persistent options.

load_persist_file() read persisted config file

Returns
Error state
Return values
trueAn error occurred
falseSuccess

◆ lock()

void Persisted_variables_cache::lock ( )
inline

Acquire lock on m_persist_variables/m_persist_ro_variables.

◆ open_persist_file()

bool Persisted_variables_cache::open_persist_file ( int  flag)
private

Open persisted config file.

Parameters
[in]flagFile open mode
Returns
Error state
Return values
trueAn error occurred
falseSuccess

◆ read_persist_file()

int Persisted_variables_cache::read_persist_file ( )

Read options from persistent file.

read_persist_file() reads the persisted config file

This function does following:

  1. Read the persisted config file into a string buffer
  2. This string buffer is parsed with JSON parser to check if the format is correct or not.
  3. Check for correct group name.
  4. Extract key/value pair and populate in m_persist_variables, m_persist_ro_variables. mysqld-auto.cnf file will have variable properties like when a variable is set, by wholm and on what host this variable was set.
Returns
Error state
Return values
-1or 1 Failure
0Success

◆ reset_persisted_variables()

bool Persisted_variables_cache::reset_persisted_variables ( THD thd,
const char *  name,
bool  if_exists 
)

Reset persisted options.

reset_persisted_variables() does a lookup into persist_variables and remove the variable from the hash if present and flush the hash to file.

Parameters
[in]thdPointer to connection handle.
[in]nameName of variable to remove, if NULL all variables are removed from config file.
[in]if_existsBool value when set to true reports warning else error if variable is not present in the config file.
Returns
0 Success
1 Failure

◆ set_persist_options()

bool Persisted_variables_cache::set_persist_options ( bool  plugin_options = false)

Set persisted options.

set_persist_options() will set the options read from persisted config file

This function does nothing when –no-defaults is set or if persisted_globals_load is set to false

Parameters
[in]plugin_optionsFlag which tells what options are being set. If set to false non plugin variables are set else plugin variables are set
Returns
Error state
Return values
trueAn error occurred
falseSuccess

◆ set_variable()

void Persisted_variables_cache::set_variable ( THD thd,
set_var setvar 
)

Update in-memory copy for every SET PERSIST statement.

Retrieve variables name/value and update the in-memory copy with this new values.

If value is default then remove this entry from in-memory copy, else update existing key with new value

Parameters
[in]thdPointer to connection handler
[in]setvarPointer to set_var which is being SET
Returns
void

◆ unlock()

void Persisted_variables_cache::unlock ( )
inline

Release lock on m_persist_variables/m_persist_ro_variables.

Member Data Documentation

◆ m_fd

MYSQL_FILE* Persisted_variables_cache::m_fd
private

◆ m_instance

Persisted_variables_cache * Persisted_variables_cache::m_instance = NULL
staticprivate

◆ m_LOCK_persist_file

mysql_mutex_t Persisted_variables_cache::m_LOCK_persist_file
private

◆ m_LOCK_persist_variables

mysql_mutex_t Persisted_variables_cache::m_LOCK_persist_variables
private

◆ m_persist_filename

std::string Persisted_variables_cache::m_persist_filename
private

◆ m_persist_plugin_variables

std::vector<st_persist_var> Persisted_variables_cache::m_persist_plugin_variables
private

◆ m_persist_ro_variables

std::map<std::string, st_persist_var> Persisted_variables_cache::m_persist_ro_variables
private

◆ m_persist_variables

std::vector<st_persist_var> Persisted_variables_cache::m_persist_variables
private

◆ ro_persisted_argv_alloc

MEM_ROOT Persisted_variables_cache::ro_persisted_argv_alloc {PSI_NOT_INSTRUMENTED, 512}
private

◆ ro_persisted_plugin_argv_alloc

MEM_ROOT Persisted_variables_cache::ro_persisted_plugin_argv_alloc {PSI_NOT_INSTRUMENTED, 512}
private

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