MySQL 8.4.0
Source Code Documentation
Session_sysvar_resource_manager Class Reference

#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
 

Detailed Description

Session_sysvar_resource_manager

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.

Member Function Documentation

◆ claim_memory_ownership()

void Session_sysvar_resource_manager::claim_memory_ownership ( bool  claim)

◆ deinit()

void Session_sysvar_resource_manager::deinit ( void  )

Frees the memory allocated for Sys_var_charptr session variables.

◆ init()

bool Session_sysvar_resource_manager::init ( char **  var)

Allocates memory for Sys_var_charptr session variable during session initialization.

Parameters
varThe variable.
Returns
Success - false Failure - true

◆ update()

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.

Parameters
varThe variable.
valThe new value.
val_lenLength of the new value.
Returns
Success - false Failure - true

Member Data Documentation

◆ m_sysvar_string_alloc_hash

malloc_unordered_map<char **, unique_ptr_my_free<char> > Session_sysvar_resource_manager::m_sysvar_string_alloc_hash
private
Initial value:
{
PSI_memory_key key_memory_THD_Session_sysvar_resource_manager
Definition: psi_memory_key.cc:90

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