MySQL 9.1.0
Source Code Documentation
|
#include <sys_vars_resource_mgr.h>
Public Member Functions | |
bool | init (char **var) |
Allocates memory for Sys_var_charptr session variable during session initialization. More... | |
bool | update (char **var, char *val, size_t val_len) |
Frees the old allocated memory, memdup()'s the given val to a new memory address & updates the session variable pointer. More... | |
void | claim_memory_ownership (bool claim) |
void | deinit () |
Frees the memory allocated for Sys_var_charptr session variables. More... | |
Private Attributes | |
malloc_unordered_map< char **, unique_ptr_my_free< char > > | m_sysvar_string_alloc_hash |
When a session (THD) gets initialized, it receives a shallow copy of all global system variables. thd->variables= global_system_variables; (see plugin_thdvar_init())
In case of Sys_var_charptr variables, we need to maintain a separate copy for each session though so that global and session variables can be altered independently.
This class is responsible for alloc|dealloc-ating memory for Sys_var_charptr variables for every session. It works in three steps :
(1) init : Creates a copy (memdup()) of global Sys_var_charptr system variable for the respective session variable (passed as a parameter) & inserts it into sysvar_string_alloc_hash (containing the allocated address) to infer that memory has been allocated for the session. init() is called during the initialization of session system variables. (plugin_thdvar_init()) (2) update : When the session variable is updated, the old memory is freed and new memory is allocated to hold the new value. The corresponding member in sysvar_string_alloc_hash is also updated to hold the new allocated memory address. (Sys_var_charptr::session_update()) (3) deinit : Its a one-shot operation to free all the session Sys_var_charptr system variables. It basically traverses down the sysvar_string_alloc_hash hash and calls free() for all the addresses that it holds.
Note, there should always be at most one node per Sys_var_charptr session system variable.
void Session_sysvar_resource_manager::claim_memory_ownership | ( | bool | claim | ) |
void Session_sysvar_resource_manager::deinit | ( | void | ) |
Frees the memory allocated for Sys_var_charptr session variables.
bool Session_sysvar_resource_manager::init | ( | char ** | var | ) |
Allocates memory for Sys_var_charptr session variable during session initialization.
var | The variable. |
bool Session_sysvar_resource_manager::update | ( | char ** | var, |
char * | val, | ||
size_t | val_len | ||
) |
Frees the old allocated memory, memdup()'s the given val to a new memory address & updates the session variable pointer.
var | The variable. |
val | The new value. |
val_len | Length of the new value. |
|
private |