MySQL 8.0.40
Source Code Documentation
System_variable_tracker Class Referencefinal

Wrapper interface for all kinds of system variables. More...

#include <set_var.h>

Classes

struct  Cache
 
struct  Component
 
struct  Keycache
 
struct  Plugin
 
struct  Static
 

Public Types

enum  Lifetime { STATIC , KEYCACHE , PLUGIN , COMPONENT }
 
typedef Prealloced_array< System_variable_tracker, SYSTEM_VARIABLE_PREALLOCArray
 

Public Member Functions

 System_variable_tracker (const System_variable_tracker &)
 
 ~System_variable_tracker ()
 
void operator= (System_variable_tracker &&)
 
Lifetime lifetime () const
 
bool operator== (const System_variable_tracker &x) const
 
bool is_keycache_var () const
 
bool eq_static_sys_var (const sys_var *var) const
 
const char * get_var_name () const
 
std::string_view get_keycache_name () const
 
bool is_hint_updateable () const
 
bool access_system_variable (THD *thd, std::function< void(const System_variable_tracker &, sys_var *)> function={}, Suppress_not_found_error suppress_not_found_error=Suppress_not_found_error::NO, Force_sensitive_system_variable_access force_sensitive_variable_access=Force_sensitive_system_variable_access::NO, Is_already_locked is_already_locked=Is_already_locked::NO, Is_single_thread is_single_thread=Is_single_thread::NO) const
 
template<typename T >
std::optional< T > access_system_variable (THD *thd, std::function< T(const System_variable_tracker &, sys_var *)> function, Suppress_not_found_error suppress_not_found_error=Suppress_not_found_error::NO, Force_sensitive_system_variable_access force_sensitive_variable_access=Force_sensitive_system_variable_access::NO, Is_already_locked is_already_locked=Is_already_locked::NO, Is_single_thread is_single_thread=Is_single_thread::NO) const
 Safely pass a sys_var object to a function. More...
 
SHOW_TYPE cached_show_type () const
 
bool cached_is_sensitive () const
 

Static Public Member Functions

static System_variable_tracker make_tracker (std::string_view prefix, std::string_view suffix)
 Static "constructor". More...
 
static System_variable_tracker make_tracker (std::string_view multipart_name)
 Static "constructor". More...
 
static bool enumerate_sys_vars (bool sort, enum enum_var_type type, bool strict, Array *output)
 Constructs an array of system variables for display to the user. More...
 

Public Attributes

friend Array
 
sys_varm_static_var
 
struct {
   sys_var *   m_static_var
 
m_static
 
char m_keycache_var_name [NAME_LEN+sizeof(".key_cache_division_limit")]
 A dot-separated key cache name or, for a reduced form of key cache variable names, a key cache property name as specified by the caller of System_variable_tracker::make_traker(). More...
 
size_t m_keycache_name_size
 
sys_varm_keycache_var
 
struct {
   char   m_keycache_var_name [NAME_LEN+sizeof(".key_cache_division_limit")]
 A dot-separated key cache name or, for a reduced form of key cache variable names, a key cache property name as specified by the caller of System_variable_tracker::make_traker(). More...
 
   size_t   m_keycache_name_size
 
   sys_var *   m_keycache_var
 
m_keycache
 
char m_plugin_var_name [NAME_LEN+1]
 A "_"-separated plugin-registered variables name. More...
 
sys_varm_plugin_var_cache
 
struct {
   char   m_plugin_var_name [NAME_LEN+1]
 A "_"-separated plugin-registered variables name. More...
 
   sys_var *   m_plugin_var_cache
 
m_plugin
 
char m_component_var_name [NAME_LEN+sizeof('.')+NAME_LEN+1]
 A dot-separated component-registered variable name. More...
 
sys_varm_component_var_cache
 
struct {
   char   m_component_var_name [NAME_LEN+sizeof('.')+NAME_LEN+1]
 A dot-separated component-registered variable name. More...
 
   sys_var *   m_component_var_cache
 
m_component
 

Static Public Attributes

static constexpr size_t SYSTEM_VARIABLE_PREALLOC = 200
 Number of system variable elements to preallocate. More...
 

Private Member Functions

 System_variable_tracker (Static, sys_var *var)
 
 System_variable_tracker (Keycache, std::string_view cache_name, sys_var *var)
 
 System_variable_tracker (Plugin, std::string_view name)
 
 System_variable_tracker (Component, std::string_view dot_separated_name)
 
 System_variable_tracker (Component, std::string_view component_name, std::string_view variable_name)
 
sys_varget_stable_var () const
 
bool visit_plugin_variable (THD *, std::function< bool(sys_var *)>, Suppress_not_found_error, Is_already_locked, Is_single_thread) const
 
bool visit_component_variable (THD *, std::function< bool(sys_var *)>, Suppress_not_found_error, Is_already_locked, Is_single_thread) const
 
void cache_metadata (THD *thd, sys_var *v) const
 

Static Private Member Functions

static bool enumerate_sys_vars_in_hash (collation_unordered_map< std::string, sys_var * > *hash, enum enum_var_type query_scope, bool strict, System_variable_tracker::Array *output)
 
static bool names_are_same (const char *, const char *)
 

Private Attributes

Lifetime m_tag
 
std::optional< Cachem_cache
 
union {
   struct {
      sys_var *   m_static_var
 
   }   m_static
 
   struct {
      char   m_keycache_var_name [NAME_LEN+sizeof(".key_cache_division_limit")]
 A dot-separated key cache name or, for a reduced form of key cache variable names, a key cache property name as specified by the caller of System_variable_tracker::make_traker(). More...
 
      size_t   m_keycache_name_size
 
      sys_var *   m_keycache_var
 
   }   m_keycache
 
   struct {
      char   m_plugin_var_name [NAME_LEN+1]
 A "_"-separated plugin-registered variables name. More...
 
      sys_var *   m_plugin_var_cache
 
   }   m_plugin
 
   struct {
      char   m_component_var_name [NAME_LEN+sizeof('.')+NAME_LEN+1]
 A dot-separated component-registered variable name. More...
 
      sys_var *   m_component_var_cache
 
   }   m_component
 
}; 
 

Static Private Attributes

static thread_local int m_hash_lock_recursion_depth {0}
 A non-zero value suppresses LOCK_system_variables_hash guards in System_variable_tracker::access_system_variable. More...
 

Detailed Description

Wrapper interface for all kinds of system variables.

The interface encapsulates parse- and execution-time resolvers for all kinds of sys_var: regular (static) system variables MyISAM Multiple Key Cache variables plugin-registered variables component-registered variables Encapsulation of system variable resolving and data accessing tasks.

Member Typedef Documentation

◆ Array

Member Enumeration Documentation

◆ Lifetime

Enumerator
STATIC 

for regular static variables

KEYCACHE 

for MyISAM Multiple Key Cache variables

PLUGIN 

for plugin-registered system variables

COMPONENT 

for component-registered variables

Constructor & Destructor Documentation

◆ System_variable_tracker() [1/6]

System_variable_tracker::System_variable_tracker ( Static  ,
sys_var var 
)
private

◆ System_variable_tracker() [2/6]

System_variable_tracker::System_variable_tracker ( Keycache  ,
std::string_view  cache_name,
sys_var var 
)
private

◆ System_variable_tracker() [3/6]

System_variable_tracker::System_variable_tracker ( Plugin  ,
std::string_view  name 
)
private

◆ System_variable_tracker() [4/6]

System_variable_tracker::System_variable_tracker ( Component  ,
std::string_view  dot_separated_name 
)
private

◆ System_variable_tracker() [5/6]

System_variable_tracker::System_variable_tracker ( Component  ,
std::string_view  component_name,
std::string_view  variable_name 
)
private

◆ System_variable_tracker() [6/6]

System_variable_tracker::System_variable_tracker ( const System_variable_tracker x)

◆ ~System_variable_tracker()

System_variable_tracker::~System_variable_tracker ( )

Member Function Documentation

◆ access_system_variable() [1/2]

template<typename T >
std::optional< T > System_variable_tracker::access_system_variable ( THD thd,
std::function< T(const System_variable_tracker &, sys_var *)>  function,
Suppress_not_found_error  suppress_not_found_error = Suppress_not_found_error::NO,
Force_sensitive_system_variable_access  force_sensitive_variable_access = Force_sensitive_system_variable_access::NO,
Is_already_locked  is_already_locked = Is_already_locked::NO,
Is_single_thread  is_single_thread = Is_single_thread::NO 
) const
inline

Safely pass a sys_var object to a function.

Template variant.

access_system_variable() is the most important interface: it does necessary locks, if a dynamic variable is inaccessible then access_system_variable() exits returning empty std::option, otherwise it calls function and returns the result value of function to the caller.

See the pseudo code part at the comment above a signature of the non-template variant of access_system_variable() for details (replace "return true" with "return std::option{}" and "return false" with "return result value of anonymous function call").

Template Parameters
TA type of a return value of the callback function.
Parameters
thdA connection handler or nullptr.
functionA function to pass a sys_var object if the latest is accessible.
suppress_not_found_errorSuppress or output ER_UNKNOWN_SYSTEM_VARIABLE if a dynamic variable is unavailable.
force_sensitive_variable_accessSuppress privilege check for SENSITIVE variables.
is_already_lockedYES means LOCK_system_variables_hash has already been taken.
is_single_threadYES means we are called from mysqld_main, during bootstrap.
Returns
No value if the dynamic variable is unavailable, otherwise a value of type T returned by the callback function.

◆ access_system_variable() [2/2]

bool System_variable_tracker::access_system_variable ( THD thd,
std::function< void(const System_variable_tracker &, sys_var *)>  function = {},
Suppress_not_found_error  suppress_not_found_error = Suppress_not_found_error::NO,
Force_sensitive_system_variable_access  force_sensitive_variable_access = Force_sensitive_system_variable_access::NO,
Is_already_locked  is_already_locked = Is_already_locked::NO,
Is_single_thread  is_single_thread = Is_single_thread::NO 
) const
Safely pass a sys_var object to a function. Non-template variant.

access_system_variable() is the most important interface:
it does necessary locks,
if a dynamic variable is inaccessible it exits,
otherwise it calls @p function.
access_system_variable() is reentrant:
being called recursively it suppresses double locks.

Simplified pseudo code of access_system_variable() implementation:

    if system variable is @@session_track_system_variables {

a special case: the system variable is static, but it references a comma-separated list of other system variables if function is not no-op { process @session_track_system_variables as plugin-registered one } else { return false // success } } if system variable is static or key cache variable { no dictionary/plugin locks needed call function(cached sys_var pointer) return false // success } if system variable is plugin-registered one { if need to hold LOCK_system_variables_hash { acquire read-only LOCK_system_variables_hash } if need to hold LOCK_plugin { acquire LOCK_plugin, unlock on exit } find sys_var if found { intern_plugin_lock } if this function acquired LOCK_plugin { release LOCK_plugin } if this function acquired LOCK_system_variables_hash { release LOCK_system_variables_hash } if not found or plugin is not in the PLUGIN_IS_READY state { return true // error: variable not found or } call function(found sys_var pointer) return false // success } if system variable is component-registered one { if need to hold LOCK_system_variables_hash(**) { acquire read-only LOCK_system_variables_hash, unlock on exit } find sys_var if not found { return true } call function(found sys_var pointer) return false // success }

Parameters
thdA connection handler or nullptr.
functionAn optional anonymous function to pass a sys_var object if the latest is accessible.
suppress_not_found_errorSuppress or output ER_UNKNOWN_SYSTEM_VARIABLE if a dynamic variable is unavailable.
force_sensitive_variable_accessSuppress privilege check for SENSITIVE variables.
is_already_lockedYES means LOCK_system_variables_hash has already been taken.
is_single_threadYES means we are called from mysqld_main, during bootstrap.
Returns
True if the dynamic variable is unavailable, otherwise false.

◆ cache_metadata()

void System_variable_tracker::cache_metadata ( THD thd,
sys_var v 
) const
private

◆ cached_is_sensitive()

bool System_variable_tracker::cached_is_sensitive ( ) const
inline

◆ cached_show_type()

SHOW_TYPE System_variable_tracker::cached_show_type ( ) const
inline

◆ enumerate_sys_vars()

bool System_variable_tracker::enumerate_sys_vars ( bool  sort,
enum enum_var_type  query_scope,
bool  strict,
System_variable_tracker::Array output 
)
static

Constructs an array of system variables for display to the user.

Parameters
outputPrealloced_array of elements for display
sortIf true, the system variables should be sorted
query_scopeOPT_GLOBAL or OPT_SESSION for SHOW GLOBAL|SESSION VARIABLES
strictUse strict scope checking
Returns
True on error, false otherwise
Note
Requires r/o lock on LOCK_system_variables_hash.

◆ enumerate_sys_vars_in_hash()

bool System_variable_tracker::enumerate_sys_vars_in_hash ( collation_unordered_map< std::string, sys_var * > *  hash,
enum enum_var_type  query_scope,
bool  strict,
System_variable_tracker::Array output 
)
staticprivate

◆ eq_static_sys_var()

bool System_variable_tracker::eq_static_sys_var ( const sys_var var) const
inline

◆ get_keycache_name()

std::string_view System_variable_tracker::get_keycache_name ( ) const
inline
Returns
1) not normalized names of MyISAM Multiple Key Caches, also can return empty string for the implicit prefix (i.e. implicit "DEFAULT."). 2) empty string for the rest of system variables.

◆ get_stable_var()

sys_var * System_variable_tracker::get_stable_var ( ) const
inlineprivate

◆ get_var_name()

const char * System_variable_tracker::get_var_name ( ) const
Returns
1) normalized names of regular system variables; 2) user-specified dot-separated names of key cache variables, or user-specified unqualified names of default key cache property names; 3) user-specified names of plugin-registered variables; 4) user-specified dot-separated names of component-registered variables.

◆ is_hint_updateable()

bool System_variable_tracker::is_hint_updateable ( ) const
inline
Returns
true if the underlying variable can be referenced in the SET_VAR optimizer hint syntax, otherwise false.

◆ is_keycache_var()

bool System_variable_tracker::is_keycache_var ( ) const
inline

◆ lifetime()

Lifetime System_variable_tracker::lifetime ( ) const
inline

◆ make_tracker() [1/2]

System_variable_tracker System_variable_tracker::make_tracker ( std::string_view  multipart_name)
static

Static "constructor".

Note
This function requires no locks and allocates nothing on memory heaps.
Parameters
multipart_nameVariable name, optionally dot-separated.
Returns
System_variable_tracker object

◆ make_tracker() [2/2]

System_variable_tracker System_variable_tracker::make_tracker ( std::string_view  prefix,
std::string_view  suffix 
)
static

Static "constructor".

Note
This function requires no locks and allocates nothing on memory heaps.
Parameters
prefixOne of: component name, MyISAM Multiple Key Cache name, or empty string.
suffixIn a dot-separated syntax (prefix is mandatory): component-registered variable name, or MyISAM Multiple Key Cache property name. Otherwise (is empty): name of static or plugin-registered variables.
Returns
System_variable_tracker object

◆ names_are_same()

bool System_variable_tracker::names_are_same ( const char *  a,
const char *  b 
)
staticprivate

◆ operator=()

void System_variable_tracker::operator= ( System_variable_tracker &&  x)

◆ operator==()

bool System_variable_tracker::operator== ( const System_variable_tracker x) const
inline

◆ visit_component_variable()

bool System_variable_tracker::visit_component_variable ( THD thd,
std::function< bool(sys_var *)>  function,
Suppress_not_found_error  suppress_not_found_error,
Is_already_locked  is_already_locked,
Is_single_thread  is_single_thread 
) const
private

◆ visit_plugin_variable()

bool System_variable_tracker::visit_plugin_variable ( THD thd,
std::function< bool(sys_var *)>  function,
Suppress_not_found_error  suppress_not_found_error,
Is_already_locked  is_already_locked,
Is_single_thread  is_single_thread 
) const
private

Member Data Documentation

◆ 

union { ... } System_variable_tracker::@156

◆ Array

◆ m_cache

std::optional<Cache> System_variable_tracker::m_cache
mutableprivate

◆ 

struct { ... } System_variable_tracker::m_component

◆ m_component_var_cache

sys_var* System_variable_tracker::m_component_var_cache
mutable

◆ m_component_var_name

char System_variable_tracker::m_component_var_name[NAME_LEN+sizeof('.')+NAME_LEN+1]

A dot-separated component-registered variable name.

◆ m_hash_lock_recursion_depth

thread_local int System_variable_tracker::m_hash_lock_recursion_depth {0}
staticprivate

A non-zero value suppresses LOCK_system_variables_hash guards in System_variable_tracker::access_system_variable.

◆ 

struct { ... } System_variable_tracker::m_keycache

◆ m_keycache_name_size

size_t System_variable_tracker::m_keycache_name_size

◆ m_keycache_var

sys_var* System_variable_tracker::m_keycache_var

◆ m_keycache_var_name

char System_variable_tracker::m_keycache_var_name[NAME_LEN+sizeof(".key_cache_division_limit")]

A dot-separated key cache name or, for a reduced form of key cache variable names, a key cache property name as specified by the caller of System_variable_tracker::make_traker().

◆ 

struct { ... } System_variable_tracker::m_plugin

◆ m_plugin_var_cache

sys_var* System_variable_tracker::m_plugin_var_cache
mutable

◆ m_plugin_var_name

char System_variable_tracker::m_plugin_var_name[NAME_LEN+1]

A "_"-separated plugin-registered variables name.

◆ 

struct { ... } System_variable_tracker::m_static

◆ m_static_var

sys_var* System_variable_tracker::m_static_var

◆ m_tag

Lifetime System_variable_tracker::m_tag
private

◆ SYSTEM_VARIABLE_PREALLOC

constexpr size_t System_variable_tracker::SYSTEM_VARIABLE_PREALLOC = 200
staticconstexpr

Number of system variable elements to preallocate.


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