MySQL 8.3.0
Source Code Documentation
resourcegroups::Resource_group_mgr Class Reference

This is a singleton class that provides various functionalities related to Resource group management, more importantly the managing and the mapping of resource group names to the corresponding in-memory resource group object. More...

#include <resource_group_mgr.h>

Public Member Functions

bool resource_group_support ()
 Check if support for Resource group exists at runtime. More...
 
const char * unsupport_reason ()
 Reason for resource group not being supported. More...
 
void set_unsupport_reason (const std::string &reason)
 Set reason for resource group not being supported. More...
 
bool init ()
 Initialize the Resource group manager. More...
 
bool post_init ()
 Post initialization sequence during mysqld startup. More...
 
void disable_resource_group ()
 Disable and deinitialize the resource group if it was initialized before. More...
 
Resource_groupget_resource_group (const std::string &resource_group_name)
 Get the in-memory Resource group object corresponding to a resource group name. More...
 
bool get_thread_attributes (PSI_thread_attrs *pfs_thread_attr, ulonglong thread_id)
 Get the thread attributes identified by PSI thread ID. More...
 
bool add_resource_group (std::unique_ptr< Resource_group > resource_group_ptr)
 Add the resource group to the Resource group map. More...
 
void remove_resource_group (const std::string &name)
 Remove the resource group from the map identified by it's name. More...
 
Resource_groupcreate_and_add_in_resource_group_hash (const LEX_CSTRING &name, Type type, bool enabled, std::unique_ptr< std::vector< Range > > cpus, int thr_priority)
 Create an in-memory resource group identified by its attributes and add it to the resource group map. More...
 
bool move_resource_group (Resource_group *from_res_grp, Resource_group *to_res_grp)
 Move the Resource group of the current thread identified by from_res_group to the Resource group to_res_grp. More...
 
Resource_groupdeserialize_resource_group (const dd::Resource_group *res_grp)
 Deserialize a DD resource group object into an in-memory Resource group object. More...
 
void set_res_grp_in_pfs (const char *name, int length, ulonglong thread_id)
 Set Resource group name in the PFS table performance_schema.threads for the PFS thread id. More...
 
Resource_groupsys_default_resource_group ()
 Return the SYS_default resource group instance. More...
 
Resource_groupusr_default_resource_group ()
 Return the USR_default resource group instance. More...
 
const char * sys_default_resource_group_name ()
 Get names of SYS_default and USR_default resource groups. More...
 
const char * usr_default_resource_group_name ()
 
bool is_resource_group_default (const Resource_group *res_grp)
 Check if a given Resource group is either SYS_default or USR_default. More...
 
bool thread_priority_available ()
 Check if a thread priority setting can be done. More...
 
bool acquire_shared_mdl_for_resource_group (THD *thd, const char *res_grp_name, enum_mdl_duration lock_duration, MDL_ticket **ticket, bool acquire_lock)
 Acquire an shared MDL lock on resource group name. More...
 
void release_shared_mdl_for_resource_group (THD *thd, MDL_ticket *ticket)
 Release the shared MDL lock held on a resource group. More...
 
const char * resource_group_type_str (const Type &type)
 String corresponding to the type of resource group. More...
 
uint32_t num_vcpus ()
 Number of VCPUs present in the system. More...
 
void deinit ()
 
bool disable_pfs_notification ()
 
bool switch_resource_group_if_needed (THD *thd, resourcegroups::Resource_group **src_res_grp, resourcegroups::Resource_group **dest_res_grp, MDL_ticket **ticket, MDL_ticket **cur_ticket)
 Switch Resource Group if it is requested by environment. More...
 
void restore_original_resource_group (THD *thd, resourcegroups::Resource_group *src_res_grp, resourcegroups::Resource_group *dest_res_grp)
 Restore original resource group if resource group switching was performed before. More...
 

Static Public Member Functions

static Resource_group_mgrinstance ()
 Singleton method to return an instance of this class. More...
 
static void destroy_instance ()
 Destroy the singleton instance. More...
 

Private Member Functions

 Resource_group_mgr ()
 
 ~Resource_group_mgr ()=default
 
 Resource_group_mgr (const Resource_group_mgr &)=delete
 
void operator= (const Resource_group_mgr &)=delete
 

Private Attributes

const mysql_service_registry_tm_registry_svc
 Handles to the PFS registry, Resource Group and Notification services. More...
 
const mysql_service_pfs_resource_group_v3_tm_resource_group_svc
 
const mysql_service_pfs_notification_v3_tm_notify_svc
 
my_h_service m_h_res_grp_svc
 
my_h_service m_h_notification_svc
 
int m_notify_handle
 
Resource_groupm_usr_default_resource_group
 Pointer to USR_default and SYS_default resource groups. More...
 
Resource_groupm_sys_default_resource_group
 
collation_unordered_map< std::string, std::unique_ptr< Resource_group > > * m_resource_group_hash
 Map mapping resource group name with it's corresponding in-memory Resource_group object. More...
 
mysql_rwlock_t m_map_rwlock
 Lock protecting the resource group map. More...
 
bool m_thread_priority_available
 Boolean value indicating whether setting of thread priority is allowed. More...
 
bool m_resource_group_support
 Bool value indicating support for resource group. More...
 
std::string m_unsupport_reason
 String indicating reason for resource group not being supported. More...
 
uint32_t m_num_vcpus
 Value indicating the number of vcpus in the system. More...
 

Static Private Attributes

static Resource_group_mgrm_instance = nullptr
 Pointer to singleton instance of the Resource_group_mgr class. More...
 

Detailed Description

This is a singleton class that provides various functionalities related to Resource group management, more importantly the managing and the mapping of resource group names to the corresponding in-memory resource group object.

Constructor & Destructor Documentation

◆ Resource_group_mgr() [1/2]

resourcegroups::Resource_group_mgr::Resource_group_mgr ( )
inlineprivate

◆ ~Resource_group_mgr()

resourcegroups::Resource_group_mgr::~Resource_group_mgr ( )
privatedefault

◆ Resource_group_mgr() [2/2]

resourcegroups::Resource_group_mgr::Resource_group_mgr ( const Resource_group_mgr )
privatedelete

Member Function Documentation

◆ acquire_shared_mdl_for_resource_group()

bool resourcegroups::Resource_group_mgr::acquire_shared_mdl_for_resource_group ( THD thd,
const char *  res_grp_name,
enum_mdl_duration  lock_duration,
MDL_ticket **  ticket,
bool  acquire_lock 
)

Acquire an shared MDL lock on resource group name.

Parameters
thdPointer to THD context.
res_grp_nameResource group name.
lock_durationDuration of lock.
[out]ticketreference to ticket object.
acquire_locktrue if one needs to wait on lock else false.
Returns
true if lock acquisition failed else false.

◆ add_resource_group()

bool resourcegroups::Resource_group_mgr::add_resource_group ( std::unique_ptr< Resource_group resource_group_ptr)

Add the resource group to the Resource group map.

Parameters
resource_group_ptrpointer to in-memory Resource_group.
Returns
true if the call failed else false.

◆ create_and_add_in_resource_group_hash()

Resource_group * resourcegroups::Resource_group_mgr::create_and_add_in_resource_group_hash ( const LEX_CSTRING name,
Type  type,
bool  enabled,
std::unique_ptr< std::vector< Range > >  cpus,
int  thr_priority 
)

Create an in-memory resource group identified by its attributes and add it to the resource group map.

Parameters
nameName of resource group.
typeType of resource group.
enabledIs resource group enabled?
cpusPointer to list of Range objects representing CPU IDS.
thr_priorityThread priority.
Returns
Pointer to Resource Group object if call is successful else null.

◆ deinit()

void resourcegroups::Resource_group_mgr::deinit ( )

◆ deserialize_resource_group()

Resource_group * resourcegroups::Resource_group_mgr::deserialize_resource_group ( const dd::Resource_group res_grp)

Deserialize a DD resource group object into an in-memory Resource group object.

Parameters
res_grpPointer to DD Resource_group object.
Returns
Pointer to in-memory Resource_group subject if Successful else null.

◆ destroy_instance()

void resourcegroups::Resource_group_mgr::destroy_instance ( )
static

Destroy the singleton instance.

◆ disable_pfs_notification()

bool resourcegroups::Resource_group_mgr::disable_pfs_notification ( )

◆ disable_resource_group()

void resourcegroups::Resource_group_mgr::disable_resource_group ( )
inline

Disable and deinitialize the resource group if it was initialized before.

◆ get_resource_group()

Resource_group * resourcegroups::Resource_group_mgr::get_resource_group ( const std::string &  resource_group_name)

Get the in-memory Resource group object corresponding to a resource group name.

Parameters
resource_group_nameName of the resource group.
Returns
Pointer to the Resource group if it exists else nullptr.

◆ get_thread_attributes()

bool resourcegroups::Resource_group_mgr::get_thread_attributes ( PSI_thread_attrs pfs_thread_attr,
ulonglong  thread_id 
)
inline

Get the thread attributes identified by PSI thread ID.

Parameters
[out]pfs_thread_attrPointer to thread attribute object which shall be populated if the call is successful.
thread_idPFS thread identifier representing a thread of mysqld.
Returns
true if call failed else false.

◆ init()

bool resourcegroups::Resource_group_mgr::init ( )

Initialize the Resource group manager.

Must be called before instance() can be used.

Returns
true if initialization failed, false otherwise.

◆ instance()

Resource_group_mgr * resourcegroups::Resource_group_mgr::instance ( )
static

Singleton method to return an instance of this class.

◆ is_resource_group_default()

bool resourcegroups::Resource_group_mgr::is_resource_group_default ( const Resource_group res_grp)
inline

Check if a given Resource group is either SYS_default or USR_default.

Returns
true if resource is USR_default or SYS_default else false.

◆ move_resource_group()

bool resourcegroups::Resource_group_mgr::move_resource_group ( Resource_group from_res_grp,
Resource_group to_res_grp 
)

Move the Resource group of the current thread identified by from_res_group to the Resource group to_res_grp.

Parameters
from_res_grpPointer to current Resource_group of the thread.
to_res_grpPointer to the destination Resource group which the thread will be switched to.
Returns
true if move_resource_group failed else false.

◆ num_vcpus()

uint32_t resourcegroups::Resource_group_mgr::num_vcpus ( )
inline

Number of VCPUs present in the system.

Returns
Number of VCPUs in the system.

◆ operator=()

void resourcegroups::Resource_group_mgr::operator= ( const Resource_group_mgr )
privatedelete

◆ post_init()

bool resourcegroups::Resource_group_mgr::post_init ( )

Post initialization sequence during mysqld startup.

Returns
true if post initialization failed, else false.

◆ release_shared_mdl_for_resource_group()

void resourcegroups::Resource_group_mgr::release_shared_mdl_for_resource_group ( THD thd,
MDL_ticket ticket 
)
inline

Release the shared MDL lock held on a resource group.

Parameters
thdTHD context.
ticketPointer to lock ticket object.

◆ remove_resource_group()

void resourcegroups::Resource_group_mgr::remove_resource_group ( const std::string &  name)

Remove the resource group from the map identified by it's name.

Parameters
nameof the resource group.

◆ resource_group_support()

bool resourcegroups::Resource_group_mgr::resource_group_support ( )
inline

Check if support for Resource group exists at runtime.

Returns
true if resource group feature is supported else false.

◆ resource_group_type_str()

const char * resourcegroups::Resource_group_mgr::resource_group_type_str ( const Type type)
inline

String corresponding to the type of resource group.

Parameters
typeType of resource group.
Returns
string corresponding to resource group type.

◆ restore_original_resource_group()

void resourcegroups::Resource_group_mgr::restore_original_resource_group ( THD thd,
resourcegroups::Resource_group src_res_grp,
resourcegroups::Resource_group dest_res_grp 
)
inline

Restore original resource group if resource group switching was performed before.

Parameters
thdThread context.
[out]src_res_grpresource group to that switching was performed
[out]dest_res_grporiginal resource group to that switching is performed

◆ set_res_grp_in_pfs()

void resourcegroups::Resource_group_mgr::set_res_grp_in_pfs ( const char *  name,
int  length,
ulonglong  thread_id 
)
inline

Set Resource group name in the PFS table performance_schema.threads for the PFS thread id.

Parameters
namePointer to name of resource group.
lengthlength of the resource group name.
thread_idPFS thread id of the thread,

◆ set_unsupport_reason()

void resourcegroups::Resource_group_mgr::set_unsupport_reason ( const std::string &  reason)
inline

Set reason for resource group not being supported.

Parameters
reasonstring representing reason for resource group unsupported.

◆ switch_resource_group_if_needed()

bool resourcegroups::Resource_group_mgr::switch_resource_group_if_needed ( THD thd,
resourcegroups::Resource_group **  src_res_grp,
resourcegroups::Resource_group **  dest_res_grp,
MDL_ticket **  ticket,
MDL_ticket **  cur_ticket 
)

Switch Resource Group if it is requested by environment.

Parameters
thdTHD context.
[out]src_res_grpOriginal resource group from that switching is performed
[out]dest_res_grpDestination resource group to that switching is performed
[out]ticketPointer to MDL ticket object.
[out]cur_ticketPointer to current resource group MDL ticket object.
Returns
true if switching was performed, else false

◆ sys_default_resource_group()

Resource_group * resourcegroups::Resource_group_mgr::sys_default_resource_group ( )
inline

Return the SYS_default resource group instance.

Returns
pointer to the SYS_default resource group.

◆ sys_default_resource_group_name()

const char * resourcegroups::Resource_group_mgr::sys_default_resource_group_name ( )
inline

Get names of SYS_default and USR_default resource groups.

Called by thread_create_callback only.

◆ thread_priority_available()

bool resourcegroups::Resource_group_mgr::thread_priority_available ( )
inline

Check if a thread priority setting can be done.

Returns
true if thread priority setting could be done else false.

◆ unsupport_reason()

const char * resourcegroups::Resource_group_mgr::unsupport_reason ( )
inline

Reason for resource group not being supported.

Returns
pointer to string which indicate reason for resource group unsupported

◆ usr_default_resource_group()

Resource_group * resourcegroups::Resource_group_mgr::usr_default_resource_group ( )
inline

Return the USR_default resource group instance.

Returns
pointer to the USR_default resource group.

◆ usr_default_resource_group_name()

const char * resourcegroups::Resource_group_mgr::usr_default_resource_group_name ( )
inline

Member Data Documentation

◆ m_h_notification_svc

my_h_service resourcegroups::Resource_group_mgr::m_h_notification_svc
private

◆ m_h_res_grp_svc

my_h_service resourcegroups::Resource_group_mgr::m_h_res_grp_svc
private

◆ m_instance

Resource_group_mgr * resourcegroups::Resource_group_mgr::m_instance = nullptr
staticprivate

Pointer to singleton instance of the Resource_group_mgr class.

◆ m_map_rwlock

mysql_rwlock_t resourcegroups::Resource_group_mgr::m_map_rwlock
private

Lock protecting the resource group map.

◆ m_notify_handle

int resourcegroups::Resource_group_mgr::m_notify_handle
private

◆ m_notify_svc

const mysql_service_pfs_notification_v3_t* resourcegroups::Resource_group_mgr::m_notify_svc
private

◆ m_num_vcpus

uint32_t resourcegroups::Resource_group_mgr::m_num_vcpus
private

Value indicating the number of vcpus in the system.

This is initialized during startup so that we do not call the platform API every time which is expensive.

◆ m_registry_svc

const mysql_service_registry_t* resourcegroups::Resource_group_mgr::m_registry_svc
private

Handles to the PFS registry, Resource Group and Notification services.

◆ m_resource_group_hash

collation_unordered_map<std::string, std::unique_ptr<Resource_group> >* resourcegroups::Resource_group_mgr::m_resource_group_hash
private

Map mapping resource group name with it's corresponding in-memory Resource_group object.

◆ m_resource_group_support

bool resourcegroups::Resource_group_mgr::m_resource_group_support
private

Bool value indicating support for resource group.

◆ m_resource_group_svc

const mysql_service_pfs_resource_group_v3_t* resourcegroups::Resource_group_mgr::m_resource_group_svc
private

◆ m_sys_default_resource_group

Resource_group* resourcegroups::Resource_group_mgr::m_sys_default_resource_group
private

◆ m_thread_priority_available

bool resourcegroups::Resource_group_mgr::m_thread_priority_available
private

Boolean value indicating whether setting of thread priority is allowed.

◆ m_unsupport_reason

std::string resourcegroups::Resource_group_mgr::m_unsupport_reason
private

String indicating reason for resource group not being supported.

◆ m_usr_default_resource_group

Resource_group* resourcegroups::Resource_group_mgr::m_usr_default_resource_group
private

Pointer to USR_default and SYS_default resource groups.

Owernship of these pointers is resource group hash.


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