MySQL 8.4.2
Source Code Documentation
|
#include <persisted_variable.h>
Classes | |
struct | Key_info |
Public Member Functions | |
Persisted_variables_cache () | |
int | init (int *argc, char ***argv) |
Initialize class members. More... | |
bool | set_variable (THD *thd, set_var *system_var) |
Update in-memory copy for every SET PERSIST statement. More... | |
bool | flush_to_file () |
Driver: Flush in-memory copy to persistent file. More... | |
bool | write_persist_file_v2 (String &dest, bool &do_cleanup) |
Write v2 persistent file. More... | |
int | read_persist_file () |
Driver function: Read options from persistent file. More... | |
int | read_persist_file_v1 (const Json_object *json_object) |
Read v1 persistent file. More... | |
int | read_persist_file_v2 (const Json_object *json_object) |
Read v2 persistent file. More... | |
bool | load_persist_file () |
Search for persisted config file and if found read persistent options. More... | |
bool | set_persisted_options (bool plugin_options, const char *target_var_name=nullptr, int target_var_name_length=0) |
set_persisted_options() will set the options read from persisted config file More... | |
bool | reset_persisted_variables (THD *thd, const char *name, bool if_exists) |
Reset persisted options. More... | |
Persisted_variables_uset * | get_persisted_dynamic_variables () |
Get persisted variables. More... | |
Persisted_variables_uset * | get_persisted_dynamic_parse_early_variables () |
Get persisted parse-early variables. More... | |
Persisted_variables_uset * | get_persisted_dynamic_sensitive_variables (THD *thd) |
Get SENSITIVE persisted variables. More... | |
Persisted_variables_umap * | get_persisted_static_variables () |
Get persisted static variables. More... | |
Persisted_variables_umap * | get_persisted_static_parse_early_variables () |
Get persisted parse-early static variables. More... | |
Persisted_variables_umap * | get_persisted_static_sensitive_variables (THD *thd) |
Get SENSITIVE persisted static variables. More... | |
bool | append_read_only_variables (int *argc, char ***argv, bool arg_separator_added=false, bool plugin_options=false, MEM_ROOT *root_to_use=nullptr) |
append read only persisted variables to command line options with a separator. More... | |
bool | append_parse_early_variables (int *argc, char ***argv, bool &arg_separator_added) |
append PARSE EARLY read only persisted variables to command line options with a separator. More... | |
void | cleanup () |
void | lock () |
Acquire lock on m_persisted_dynamic_variables/m_persisted_static_variables. More... | |
void | unlock () |
Release lock on m_persisted_dynamic_variables/m_persisted_static_variables. More... | |
void | assert_lock_owner () |
Assert caller that owns lock on m_persisted_dynamic_variables/m_persisted_static_variables. More... | |
void | keyring_support_available () |
Set internal state to reflect keyring support status. More... | |
std::string | to_hex (const std::string &value) |
std::string | from_hex (const std::string &value) |
Static Public Member Functions | |
static Persisted_variables_cache * | get_instance () |
Return a singleton object. More... | |
Protected Types | |
enum class | File_version { VERSION_V1 = 1 , VERSION_V2 } |
Private Types | |
enum class | return_status { NOT_REQUIRED , SUCCESS , ERROR } |
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... | |
void | load_aliases () |
After extracting the variables from the JSON, we duplicate any variable definition that relates to an alias. More... | |
bool | get_file_encryption_key (std::unique_ptr< unsigned char[]> &file_key, size_t &file_key_length, bool generate=false) |
Get file encryption key. More... | |
return_status | encrypt_sensitive_variables () |
Encrypt sensitive variables values. More... | |
return_status | decrypt_sensitive_variables () |
Decrypt sensitive variables values. More... | |
void | set_parse_early_sources () |
Helper to set source information for PARSE_EARLY variables. More... | |
void | handle_option_type_change () |
Helper function to handle changes in option type. More... | |
void | clear_sensitive_blob_and_iv () |
bool | open_persist_file (int flag) |
Open persisted config file. More... | |
bool | open_persist_backup_file (int flag) |
Open persisted backup config file. More... | |
void | close_persist_file () |
Close persisted config file. More... | |
Static Private Member Functions | |
static String * | get_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_alias (const sys_var *system_var) |
If the variable has an alias, return the name for the alias. More... | |
static std::string | get_variable_alias (const char *name) |
Static Private Attributes | |
static Persisted_variables_cache * | m_instance = nullptr |
|
strongprotected |
|
strongprivate |
|
explicit |
bool Persisted_variables_cache::append_parse_early_variables | ( | int * | argc, |
char *** | argv, | ||
bool & | arg_separator_added | ||
) |
append PARSE EARLY read only persisted variables to command line options with a separator.
append_parse_early_variables() does a lookup into persist_variables for parse early 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.
[in] | argc | Pointer to argc of original program |
[in] | argv | Pointer to argv of original program |
[out] | arg_separator_added | Whether the separator is added or not |
bool Persisted_variables_cache::append_read_only_variables | ( | int * | argc, |
char *** | argv, | ||
bool | arg_separator_added = false , |
||
bool | plugin_options = false , |
||
MEM_ROOT * | root = nullptr |
||
) |
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.
[in] | argc | Pointer to argc of original program |
[in] | argv | Pointer to argv of original program |
[in] | arg_separator_added | This flag tells whether arg separator has already been added or not |
[in] | plugin_options | This flag tells whether options are handled during plugin install. If set to true options are handled as part of |
[in] | root | The memory root to use for the allocations. Null if you want to use the PV cache root(s). install plugin. |
|
inline |
Assert caller that owns lock on m_persisted_dynamic_variables/m_persisted_static_variables.
void Persisted_variables_cache::cleanup | ( | ) |
|
private |
|
private |
Close persisted config file.
|
private |
Decrypt sensitive variables values.
false | Success |
true | Error |
|
private |
Encrypt sensitive variables values.
|
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: { "mysql_static_parse_early_variables": { "variable_name_1" : { "Value" : "variable_value", "Metadata" : { "Timestamp" : timestamp_value, "User" : "user_name", "Host" : "host_name" } }, "variable_name_2" : { "Value" : "variable_value", "Metadata" : { "Timestamp" : timestamp_value, "User" : "user_name", "Host" : "host_name" } }, ... ... "variable_name_n" : { "Value" : "variable_value", "Metadata" : { "Timestamp" : timestamp_value, "User" : "user_name", "Host" : "host_name" } } }, "mysql_dynamic_parse_early_variables": { "variable_name_1" : { "Value" : "variable_value", "Metadata" : { "Timestamp" : timestamp_value, "User" : "user_name", "Host" : "host_name" } }, "variable_name_2" : { "Value" : "variable_value", "Metadata" : { "Timestamp" : timestamp_value, "User" : "user_name", "Host" : "host_name" } }, ... ... "variable_name_n" : { "Value" : "variable_value", "Metadata" : { "Timestamp" : timestamp_value, "User" : "user_name", "Host" : "host_name" } } }, "mysql_static_variables": { "variable_name_1" : { "Value" : "variable_value", "Metadata" : { "Timestamp" : timestamp_value, "User" : "user_name", "Host" : "host_name" } }, "variable_name_2" : { "Value" : "variable_value", "Metadata" : { "Timestamp" : timestamp_value, "User" : "user_name", "Host" : "host_name" } }, ... ... "variable_name_n" : { "Value" : "variable_value", "Metadata" : { "Timestamp" : timestamp_value, "User" : "user_name", "Host" : "host_name" } } }, "mysql_dynamic_variables": { "variable_name_1" : { "Value" : "variable_value", "Metadata" : { "Timestamp" : timestamp_value, "User" : "user_name", "Host" : "host_name" } }, "variable_name_2" : { "Value" : "variable_value", "Metadata" : { "Timestamp" : timestamp_value, "User" : "user_name", "Host" : "host_name" } }, ... ... "variable_name_n" : { "Value" : "variable_value", "Metadata" : { "Timestamp" : timestamp_value, "User" : "user_name", "Host" : "host_name" } } }, "mysql_sensitive_variables" : { "master_key": "<master_key_name>", "mysql_file_key": "<ENCRYPTED_FILE_KEY_IN_HEX>", "mysql_file_key_iv": "<IV_IN_HEX>", "key_encryption_algorithm": "AES_256_CBC", "mysql_sensitive_variables_blob": "<SENSITIVE_VARIABLES_INFO_IN_ENCRYPTED_FORM_IN_HEX>", "mysql_sensitive_variables_iv": "<IV_IN_HEX>", "data_encryption_algorithm": "AES_256_CBC" } }
[in] | dom | Pointer to the Json_dom object which is an internal representation of parsed json string |
[in] | is_read_only | Bool value when set to TRUE extracts read only variables and dynamic variables when set to FALSE. |
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" } }
If we are reading from a v1 persisted file, all static options including PARSE_EARLY options are stored in array "mysql_server_static_options". Since there is no way to identify PARSE_EARLY static variables, we push all these variables to m_persisted_static_parse_early_variables.
bool Persisted_variables_cache::flush_to_file | ( | ) |
Driver: Flush in-memory copy to persistent file.
Convert in-memory copy into a stream of characters and write this stream to persisted config file.
true | An error occurred |
false | Success |
std::string Persisted_variables_cache::from_hex | ( | const std::string & | value | ) |
|
private |
Get file encryption key.
Use master key from keyring to decrypt it
[out] | file_key | Decrypted Key |
[out] | file_key_length | Decrypted key length |
[in] | generate | Generate key if missing |
true | Error |
false | Success |
|
static |
Return a singleton object.
Persisted_variables_uset * Persisted_variables_cache::get_persisted_dynamic_parse_early_variables | ( | ) |
Get persisted parse-early variables.
Get PARSE_EARLY persisted variables.
Persisted_variables_uset * Persisted_variables_cache::get_persisted_dynamic_sensitive_variables | ( | THD * | thd | ) |
Get SENSITIVE persisted variables.
Persisted_variables_uset * Persisted_variables_cache::get_persisted_dynamic_variables | ( | ) |
Get persisted variables.
Return in-memory copy persist_variables_.
Persisted_variables_umap * Persisted_variables_cache::get_persisted_static_parse_early_variables | ( | ) |
Get persisted parse-early static variables.
Persisted_variables_umap * Persisted_variables_cache::get_persisted_static_sensitive_variables | ( | THD * | thd | ) |
Get SENSITIVE persisted static variables.
Persisted_variables_umap * Persisted_variables_cache::get_persisted_static_variables | ( | ) |
Get persisted static variables.
Return in-memory copy for static persisted variables.
|
staticprivate |
|
staticprivate |
If the variable has an alias, return the name for the alias.
|
staticprivate |
Retrieve variables value from sys_var.
[in] | thd | Pointer to connection handler |
[in] | system_var | Pointer to sys_var which is being SET |
[in] | str | Pointer to String instance into which value is copied |
[out] | is_null | Is value NULL or not. |
|
private |
Helper function to handle changes in option type.
Function to recategorize variables based on changes in their properties.
It is possible that during the course of development, we reclassify certain variables. Such an action may have an impact on when and how the persisted values of such variables are used/applied.
If such variables are persisted using previous versions of the server binary, it is important that we move them to correct in-memory containers so that,
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.
[in] | argc | Pointer to argc of original program |
[in] | argv | Pointer to argv of original program |
void Persisted_variables_cache::keyring_support_available | ( | ) |
Set internal state to reflect keyring support status.
We cache keyring support status just after reading manifest file.
This is required because in the absence of a keyring component, keyring plugin may provide some of the services through daemon proxy keyring.
However, we CANNOT use keyring plugin to encrypt SENSITIVE variables because upon server restart, keyring plugins will be loaded quite late.
Later on, before each encryption operation, we refer to this cached value to decide whether to proceed with encryption or not.
|
private |
After extracting the variables from the JSON, we duplicate any variable definition that relates to an alias.
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
true | An error occurred |
false | Success |
|
inline |
Acquire lock on m_persisted_dynamic_variables/m_persisted_static_variables.
|
private |
Open persisted backup config file.
[in] | flag | file open mode |
true | An error occurred |
false | Success |
|
private |
Open persisted config file.
[in] | flag | File open mode |
true | An error occurred |
false | Success |
int Persisted_variables_cache::read_persist_file | ( | ) |
Driver function: Read options from persistent file.
read_persist_file() reads the persisted config file
This function does following:
-1 | or 1 Failure |
0 | Success |
int Persisted_variables_cache::read_persist_file_v1 | ( | const Json_object * | json_object | ) |
Read v1 persistent file.
int Persisted_variables_cache::read_persist_file_v2 | ( | const Json_object * | json_object | ) |
Read v2 persistent file.
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.
[in] | thd | Pointer to connection handle. |
[in] | name | Name of variable to remove, if NULL all variables are removed from config file. |
[in] | if_exists | Bool value when set to true reports warning else error if variable is not present in the config file. |
|
private |
Helper to set source information for PARSE_EARLY variables.
bool Persisted_variables_cache::set_persisted_options | ( | bool | plugin_options, |
const char * | target_var_name = nullptr , |
||
int | target_var_name_length = 0 |
||
) |
set_persisted_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. Initial call to set_persisted_options(false) is needed to initialize m_persisted_dynamic_plugin_variables set, so that next subsequent set_persisted_options(true) calls will work with correct state.
[in] | plugin_options | Flag which tells what options are being set. If set to false non dynamically-registered system variables are set else plugin- and component-registered variables are set. |
[in] | target_var_name | If not-null the name of variable to try and set from the persisted cache values |
[in] | target_var_name_length | length of target_var_name |
true | An error occurred |
false | Success |
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
[in] | thd | Pointer to connection handler |
[in] | setvar | Pointer to set_var which is being SET |
If server was upgraded, it is possible that persisted variables were initially read from an old format file. If so, all RO variables: PARSE_EARLY or otherwise, persisted before the upgrade may be present in m_persisted_static_parse_early_variables container.
This SET PERSIST/SET PERSIST_ONLY call may be setting one of those variables. If so, remove those values from m_persisted_static_parse_early_variables.
std::string Persisted_variables_cache::to_hex | ( | const std::string & | value | ) |
|
inline |
Release lock on m_persisted_dynamic_variables/m_persisted_static_variables.
bool Persisted_variables_cache::write_persist_file_v2 | ( | String & | dest, |
bool & | do_cleanup | ||
) |
Write v2 persistent file.
If original file was of File_version::VERSION_V1, some of the variables which may belong to object "mysql_static_variables" could be part of "mysql_static_parse_early_variables" object. This is because we move such variables to "mysql_static_variables" only when SET PERSIST or SET PERSIST_ONLY is executed for them.
|
private |
|
private |
|
staticprivate |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |