Fix variable naming and usage

Don't use `this->` when it's not needed. Use snake_case for member
variables. Initialize the members using a initialization list.
This commit is contained in:
Markus Mäkelä
2017-03-27 12:22:51 +03:00
parent a10aa85736
commit 14cfd482de
4 changed files with 184 additions and 209 deletions

View File

@ -41,29 +41,30 @@ using std::map;
*/
SchemaRouter::SchemaRouter(SERVICE *service, char **options):
mxs::Router<SchemaRouter, SchemaRouterSession>(service)
mxs::Router<SchemaRouter, SchemaRouterSession>(service),
m_service(service)
{
MXS_CONFIG_PARAMETER* conf;
MXS_CONFIG_PARAMETER* param;
/** Add default system databases to ignore */
this->m_ignored_dbs.insert("mysql");
this->m_ignored_dbs.insert("information_schema");
this->m_ignored_dbs.insert("performance_schema");
this->m_service = service;
this->m_stats.longest_sescmd = 0;
this->m_stats.n_hist_exceeded = 0;
this->m_stats.n_queries = 0;
this->m_stats.n_sescmd = 0;
this->m_stats.ses_longest = 0;
this->m_stats.ses_shortest = (double)((unsigned long)(~0));
spinlock_init(&this->m_lock);
m_ignored_dbs.insert("mysql");
m_ignored_dbs.insert("information_schema");
m_ignored_dbs.insert("performance_schema");
m_stats.longest_sescmd = 0;
m_stats.n_hist_exceeded = 0;
m_stats.n_queries = 0;
m_stats.n_sescmd = 0;
m_stats.ses_longest = 0;
m_stats.ses_shortest = (double)((unsigned long)(~0));
spinlock_init(&m_lock);
conf = service->svc_config_param;
this->m_config.refresh_databases = config_get_bool(conf, "refresh_databases");
this->m_config.refresh_min_interval = config_get_integer(conf, "refresh_interval");
this->m_config.debug = config_get_bool(conf, "debug");
m_config.refresh_databases = config_get_bool(conf, "refresh_databases");
m_config.refresh_min_interval = config_get_integer(conf, "refresh_interval");
m_config.debug = config_get_bool(conf, "debug");
if ((config_get_param(conf, "auth_all_servers")) == NULL)
{
@ -96,8 +97,8 @@ SchemaRouter::SchemaRouter(SERVICE *service, char **options):
throw std::bad_alloc();
}
this->m_ignore_regex = re;
this->m_ignore_match_data = match_data;
m_ignore_regex = re;
m_ignore_match_data = match_data;
}
if ((param = config_get_param(conf, "ignore_databases")))
@ -111,7 +112,7 @@ SchemaRouter::SchemaRouter(SERVICE *service, char **options):
while (tok)
{
this->m_ignored_dbs.insert(tok);
m_ignored_dbs.insert(tok);
tok = strtok_r(NULL, sep, &sptr);
}
}
@ -142,15 +143,15 @@ SchemaRouter::SchemaRouter(SERVICE *service, char **options):
}
else if (strcmp(options[i], "refresh_databases") == 0)
{
this->m_config.refresh_databases = config_truth_value(value);
m_config.refresh_databases = config_truth_value(value);
}
else if (strcmp(options[i], "refresh_interval") == 0)
{
this->m_config.refresh_min_interval = atof(value);
m_config.refresh_min_interval = atof(value);
}
else if (strcmp(options[i], "debug") == 0)
{
this->m_config.debug = config_truth_value(value);
m_config.debug = config_truth_value(value);
}
else
{
@ -168,14 +169,14 @@ SchemaRouter::SchemaRouter(SERVICE *service, char **options):
SchemaRouter::~SchemaRouter()
{
if (this->m_ignore_regex)
if (m_ignore_regex)
{
pcre2_code_free(this->m_ignore_regex);
pcre2_code_free(m_ignore_regex);
}
if (this->m_ignore_match_data)
if (m_ignore_match_data)
{
pcre2_match_data_free(this->m_ignore_match_data);
pcre2_match_data_free(m_ignore_match_data);
}
}
@ -191,32 +192,32 @@ SchemaRouterSession* SchemaRouter::newSession(MXS_SESSION* pSession)
void SchemaRouter::diagnostics(DCB* dcb)
{
double sescmd_pct = this->m_stats.n_sescmd != 0 ?
100.0 * ((double)this->m_stats.n_sescmd / (double)this->m_stats.n_queries) :
double sescmd_pct = m_stats.n_sescmd != 0 ?
100.0 * ((double)m_stats.n_sescmd / (double)m_stats.n_queries) :
0.0;
/** Session command statistics */
dcb_printf(dcb, "\n\33[1;4mSession Commands\33[0m\n");
dcb_printf(dcb, "Total number of queries: %d\n",
this->m_stats.n_queries);
m_stats.n_queries);
dcb_printf(dcb, "Percentage of session commands: %.2f\n",
sescmd_pct);
dcb_printf(dcb, "Longest chain of stored session commands: %d\n",
this->m_stats.longest_sescmd);
m_stats.longest_sescmd);
dcb_printf(dcb, "Session command history limit exceeded: %d times\n",
this->m_stats.n_hist_exceeded);
m_stats.n_hist_exceeded);
/** Session time statistics */
if (this->m_stats.sessions > 0)
if (m_stats.sessions > 0)
{
dcb_printf(dcb, "\n\33[1;4mSession Time Statistics\33[0m\n");
dcb_printf(dcb, "Longest session: %.2lf seconds\n", this->m_stats.ses_longest);
dcb_printf(dcb, "Shortest session: %.2lf seconds\n", this->m_stats.ses_shortest);
dcb_printf(dcb, "Average session length: %.2lf seconds\n", this->m_stats.ses_average);
dcb_printf(dcb, "Longest session: %.2lf seconds\n", m_stats.ses_longest);
dcb_printf(dcb, "Shortest session: %.2lf seconds\n", m_stats.ses_shortest);
dcb_printf(dcb, "Average session length: %.2lf seconds\n", m_stats.ses_average);
}
dcb_printf(dcb, "Shard map cache hits: %d\n", this->m_stats.shmap_cache_hit);
dcb_printf(dcb, "Shard map cache misses: %d\n", this->m_stats.shmap_cache_miss);
dcb_printf(dcb, "Shard map cache hits: %d\n", m_stats.shmap_cache_hit);
dcb_printf(dcb, "Shard map cache misses: %d\n", m_stats.shmap_cache_miss);
dcb_printf(dcb, "\n");
}