24#ifndef MYSQL_CSA_RESOURCE_MONITOR_H
25#define MYSQL_CSA_RESOURCE_MONITOR_H
33#include <unordered_map>
39struct Locked_resource;
41class Resource_instance_monitor;
43 std::reference_wrapper<Resource_instance_monitor>;
130 std::unordered_map<std::string, std::unique_ptr<Resource_entry>>;
Manages per-channel resources for the Change Stream Applier (CSA).
Definition: resource_monitor.h:75
static bool try_lock_resource_internal(Resource_entry &resource_entry, std::size_t amount)
Internal function that optimistically tries to lock resource without spinning.
Definition: resource_monitor.cpp:100
Locked_resource acquire_resource(const std::string &name, std::size_t amount)
Function locks resource and returns resource guard that will release the resource if locked upon dest...
Definition: resource_monitor.cpp:78
void register_resource(const std::string &name, std::size_t limit, PSI_stage_info *stage=nullptr)
Registers a named resource with the given limit (maximum available)
Definition: resource_monitor.cpp:40
void release_resource(const std::string &name, std::size_t amount)
Releases the specified amount of the named resource.
Definition: resource_monitor.cpp:112
Resource_instance_monitor()=default
Resource_map m_resources
Definition: resource_monitor.h:131
bool lock_resource(const std::string &name, std::size_t amount)
Waits until the requested resource amount is available or returns an error.
Definition: resource_monitor.cpp:89
std::unordered_map< std::string, std::unique_ptr< Resource_entry > > Resource_map
Definition: resource_monitor.h:130
Singleton Resource Monitor for all channels/instances.
Definition: resource_monitor.h:136
Resource_monitor()=default
static Instances_map m_instances
Instances for separate channels, may be accessed concurrently between channel threads.
Definition: resource_monitor.h:152
static Resource_instance_monitor & get(std::size_t instance_id)
Get the Resource_instance_monitor for the given channel/instance ID.
Definition: resource_monitor.cpp:35
std::array< Resource_instance_monitor, scheduler::Constants::max_instances > Instances_map
Definition: resource_monitor.h:148
Definition: channel.cpp:28
std::reference_wrapper< Resource_instance_monitor > Resource_instance_monitor_ref
Definition: resource_monitor.h:43
noexcept
The return type for any call_and_catch(f, args...) call where f(args...) returns Type.
Definition: call_and_catch.h:76
Performance schema instrumentation interface.
case opt name
Definition: sslopt-case.h:29
Stage instrument information.
Definition: psi_stage_bits.h:74
Resource guard class, used to check if resource was successfully locked and release resource in destr...
Definition: resource_monitor.h:157
std::size_t m_requested_amount
Requested amount.
Definition: resource_monitor.h:181
Locked_resource()=default
Default construct.
~Locked_resource()
Unlocks resource if locked.
Definition: resource_monitor.cpp:131
bool m_is_locked
True if successfully locked.
Definition: resource_monitor.h:183
Resource_entry * m_resource
Resource handle.
Definition: resource_monitor.h:179
bool is_locked() const
Check if resource is locked.
Definition: resource_monitor.cpp:129
Locked_resource(Locked_resource &&) noexcept=delete
Entry for a named resource, managing available count and synchronization.
Definition: resource_monitor.h:188
PSI_stage_info * m_stage
Waiting stage set only if the requested amount is higher than currently available and thread waits fo...
Definition: resource_monitor.h:195
Resource_entry()=default
Default constructible.
std::atomic< long long > m_limit
Resource limit.
Definition: resource_monitor.h:192
std::atomic< long long > m_available
Currently available amount of the resource.
Definition: resource_monitor.h:190
static constexpr unsigned int max_instances
The maximum number of scheduler instances supported This value should be aligned with the 'MAX_CHANNE...
Definition: constants.h:34