MySQL 9.1.0
Source Code Documentation
Option_usage_data Class Reference

A helper class to handle option usage population. More...

#include <option_usage_data.h>

Public Member Functions

 Option_usage_data (const char *option_name, const mysql_service_registry_t *registry)
 Use this constructor at init time. More...
 
 Option_usage_data (Option_usage_data &)=delete
 
 ~Option_usage_data ()
 
bool set (bool is_used)
 Records usage. More...
 
bool set_sampled (bool is_used, unsigned long log_usage_every_nth_time)
 Records usage (calls Option_usage_data::set()) every Nth call. More...
 

Protected Attributes

const char * m_option_name
 
const mysql_service_registry_tm_registry
 
std::atomic< unsigned > m_counter
 

Detailed Description

A helper class to handle option usage population.

Adds a top level JSON object (if missing), then adds (if missing, otherwise updates) the following two JSON elements to the top level JSON object: used (boolean) usedDate (ISO 8601 string)

Create an instance of the class at component/plugin init time and dispose of it at deinit time as follows:

...
#include "mysql/components/library_mysys/option_usage_data.h"
...
Option_usage_data *handlerton{nullptr};
...
init() {
...
usage_data = new Option_usage_data("feature name",
SERVICE_PLACEHOLDER(registry)); if (!usage_data) return 1;
...
}
...
deinit() {
..
delete usage_data;
usage_data = nullptr;
..
}
Option_usage_data(const char *option_name, const mysql_service_registry_t *registry)
Use this constructor at init time.
Definition: option_usage_data.h:81
#define SERVICE_PLACEHOLDER(service)
Use this macro to reference the service placeholder as defined by the REQUIRES_SERVICE_PLACEHOLDER ma...
Definition: component_implementation.h:382
handlerton is a singleton structure - one instance per storage engine - to provide access to storage ...
Definition: handler.h:2740

Now, when the functionality is used (careful, an expensive call), do:

usage_data->set_sampled(true);

Do not register usage at the time the plugin component is initilized. Try to register it at the time it is actually being used. But do not do it too often: it parses JSON and writes to an InnoDB table!

Constructor & Destructor Documentation

◆ Option_usage_data() [1/2]

Option_usage_data::Option_usage_data ( const char *  option_name,
const mysql_service_registry_t registry 
)
inline

Use this constructor at init time.

Parameters
option_nameThe name of the option to register usage for
registrya reference to the registry service

◆ Option_usage_data() [2/2]

Option_usage_data::Option_usage_data ( Option_usage_data )
delete

◆ ~Option_usage_data()

Option_usage_data::~Option_usage_data ( )
inline

Member Function Documentation

◆ set()

bool Option_usage_data::set ( bool  is_used)

Records usage.

Parameters
is_usedTrue if the feature is used.
Return values
trueError
falseSuccess

◆ set_sampled()

bool Option_usage_data::set_sampled ( bool  is_used,
unsigned long  log_usage_every_nth_time 
)

Records usage (calls Option_usage_data::set()) every Nth call.

Very useful for high volume of calls to the usage function.

Parameters
is_usedTrue if the feature is used.
log_usage_every_nth_timeLog usage for every Nth call to this function.
Return values
trueError
falseSuccess

Member Data Documentation

◆ m_counter

std::atomic<unsigned> Option_usage_data::m_counter
protected

◆ m_option_name

const char* Option_usage_data::m_option_name
protected

◆ m_registry

const mysql_service_registry_t* Option_usage_data::m_registry
protected

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