![]() |
MySQL 26.7.0
Source Code Documentation
|
Manages per-channel resources for the Change Stream Applier (CSA). More...
#include <resource_monitor.h>
Public Member Functions | |
| 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) More... | |
| 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 destruction. More... | |
| void | release_resource (const std::string &name, std::size_t amount) |
| Releases the specified amount of the named resource. More... | |
| bool | lock_resource (const std::string &name, std::size_t amount) |
| Waits until the requested resource amount is available or returns an error. More... | |
| Resource_instance_monitor ()=default | |
Static Public Member Functions | |
| static void | release_resource (Resource_entry &resource, std::size_t amount) |
| Releases the specified amount of the named resource. More... | |
| static bool | lock_resource (Resource_entry &resource, std::size_t amount) |
| Waits until the requested resource amount is available or returns an error. More... | |
Private Types | |
| using | Resource_map = std::unordered_map< std::string, std::unique_ptr< Resource_entry > > |
Static Private Member Functions | |
| static bool | try_lock_resource_internal (Resource_entry &resource_entry, std::size_t amount) |
| Internal function that optimistically tries to lock resource without spinning. More... | |
Private Attributes | |
| Resource_map | m_resources |
Manages per-channel resources for the Change Stream Applier (CSA).
Allows registering named resources and locking/releasing them.
This class provides a registry for named resources, each with a configurable limit on maximum available units. Resources can be acquired (locked) using blocking (infinite wait) or non-blocking methods (try lock), and released. It is designed for concurrent access, using atomic operations for counts and spinning with sleep for waiting. One instance is created per channel via Resource_monitor::get(instance_id).
Usage assumptions:
Main functions:
Key concepts of resource acquisition:
|
private |
|
default |
| Locked_resource mysql::csa::Resource_instance_monitor::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 destruction.
| name | The name of the resource. |
| amount | The amount to lock. |
| bool mysql::csa::Resource_instance_monitor::lock_resource | ( | const std::string & | name, |
| std::size_t | amount | ||
| ) |
Waits until the requested resource amount is available or returns an error.
Wait-free in case resource is available in the first check.
| name | The name of the resource. |
| amount | The amount to lock. |
|
static |
Waits until the requested resource amount is available or returns an error.
Wait-free in case resource is available in the first check.
| resource | Resource handle |
| amount | The amount to lock. |
| void mysql::csa::Resource_instance_monitor::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)
| name | The name of the resource. |
| limit | The maximum available count for this resource. |
| stage | Optional PSI stage to set during waiting for lock. |
| void mysql::csa::Resource_instance_monitor::release_resource | ( | const std::string & | name, |
| std::size_t | amount | ||
| ) |
Releases the specified amount of the named resource.
Wait-free.
| name | The name of the resource. |
| amount | The amount to release. |
|
static |
Releases the specified amount of the named resource.
Wait-free.
| resource | Resource handle |
| amount | The amount to release. |
|
staticprivate |
Internal function that optimistically tries to lock resource without spinning.
Performs a single atomic attempt: subtracts the amount and succeeds if the previous available was >= amount or == limit (even for amount > limit). Wait-free; rolls back on failure.
| resource_entry | Resource handle |
| amount | Amount of the resource to lock |
|
private |