MXS-3609: Use 64-bit integers for statistics

This should be enough to avoid the problem of integer overflow in 2.4.
This commit is contained in:
Markus Mäkelä 2021-08-17 11:44:22 +03:00
parent aa6a1a58eb
commit b4edc74926
No known key found for this signature in database
GPG Key ID: 5CE746D557ACC499
9 changed files with 33 additions and 33 deletions

View File

@ -162,7 +162,7 @@ public:
/* Server connection and usage statistics */
struct ConnStats
{
int n_connections = 0; /**< Number of connections */
uint64_t n_connections = 0; /**< Number of connections */
int n_current = 0; /**< Current connections */
int n_current_ops = 0; /**< Current active operations */
int n_persistent = 0; /**< Current persistent pool */

View File

@ -44,10 +44,10 @@ struct users;
*/
typedef struct
{
time_t started; /**< The time when the service was started */
int n_failed_starts; /**< Number of times this service has failed to start */
int n_sessions; /**< Number of sessions created on service since start */
int n_current; /**< Current number of sessions */
time_t started; /**< The time when the service was started */
int n_failed_starts; /**< Number of times this service has failed to start */
uint64_t n_sessions; /**< Number of sessions created on service since start */
uint64_t n_current; /**< Current number of sessions */
} SERVICE_STATS;
typedef struct server_ref_t

View File

@ -370,7 +370,7 @@ void Server::printServer()
printf("\tServer: %s\n", address);
printf("\tProtocol: %s\n", m_settings.protocol.c_str());
printf("\tPort: %d\n", port);
printf("\tTotal connections: %d\n", stats.n_connections);
printf("\tTotal connections: %lu\n", stats.n_connections);
printf("\tCurrent connections: %d\n", stats.n_current);
printf("\tPersistent connections: %d\n", stats.n_persistent);
printf("\tPersistent actual max: %d\n", persistmax);
@ -496,7 +496,7 @@ void Server::print_to_dcb(DCB* dcb) const
elem.first.c_str(), elem.second.c_str());
}
}
dcb_printf(dcb, "\tNumber of connections: %d\n", server->stats.n_connections);
dcb_printf(dcb, "\tNumber of connections: %lu\n", server->stats.n_connections);
dcb_printf(dcb, "\tCurrent no. of conns: %d\n", server->stats.n_current);
dcb_printf(dcb, "\tCurrent no. of operations: %d\n", server->stats.n_current_ops);
dcb_printf(dcb, "\tNumber of routed packets: %lu\n", server->stats.packets);

View File

@ -961,10 +961,10 @@ void dprintService(DCB* dcb, SERVICE* svc)
}
dcb_printf(dcb,
"\tTotal connections: %d\n",
"\tTotal connections: %lu\n",
service->stats.n_sessions);
dcb_printf(dcb,
"\tCurrently connected: %d\n",
"\tCurrently connected: %lu\n",
service->stats.n_current);
}
@ -993,7 +993,7 @@ void dListServices(DCB* dcb)
{
mxb_assert(service->stats.n_current >= 0);
dcb_printf(dcb,
"%-25s | %-17s | %6d | %14d | ",
"%-25s | %-17s | %6lu | %14lu | ",
service->name(),
service->router_name(),
service->stats.n_current,

View File

@ -496,13 +496,13 @@ void RCR::diagnostics(DCB* dcb)
const char* weightby = serviceGetWeightingParameter(m_pService);
dcb_printf(dcb,
"\tNumber of router sessions: %d\n",
"\tNumber of router sessions: %lu\n",
m_stats.n_sessions);
dcb_printf(dcb,
"\tCurrent no. of router sessions: %d\n",
"\tCurrent no. of router sessions: %lu\n",
m_pService->stats.n_current);
dcb_printf(dcb,
"\tNumber of queries forwarded: %d\n",
"\tNumber of queries forwarded: %lu\n",
m_stats.n_queries);
if (*weightby)
{

View File

@ -84,8 +84,8 @@ private:
*/
struct Stats
{
int n_sessions = 0; /**< Number sessions created */
int n_queries = 0; /**< Number of queries forwarded */
uint64_t n_sessions = 0; /**< Number sessions created */
uint64_t n_queries = 0; /**< Number of queries forwarded */
};
/**

View File

@ -317,7 +317,7 @@ void RWSplit::diagnostics(DCB* dcb)
"\tNumber of router sessions: %" PRIu64 "\n",
stats().n_sessions);
dcb_printf(dcb,
"\tCurrent no. of router sessions: %d\n",
"\tCurrent no. of router sessions: %lu\n",
service()->stats.n_current);
dcb_printf(dcb,
"\tNumber of queries forwarded: %" PRIu64 "\n",

View File

@ -51,7 +51,7 @@ struct Config
bool debug; /**< Enable verbose debug messages to clients */
pcre2_code* ignore_regex; /**< Regular expression used to ignore tables */
pcre2_match_data* ignore_match_data;/**< Match data for @c ignore_regex */
std::set<std::string> ignored_tables; /**< Set of ignored tables */
std::set<std::string> ignored_tables; /**< Set of ignored tables */
SERVER* preferred_server; /**< Server to prefer in conflict situations */
Config(MXS_CONFIG_PARAMETER* conf);
@ -70,17 +70,17 @@ typedef std::shared_ptr<Config> SConfig;
*/
struct Stats
{
int n_queries; /*< Number of queries forwarded */
int n_sescmd; /*< Number of session commands */
int longest_sescmd; /*< Longest chain of stored session commands */
int n_hist_exceeded; /*< Number of sessions that exceeded session
* command history limit */
int sessions; /*< Number of sessions */
int shmap_cache_hit; /*< Shard map was found from the cache */
int shmap_cache_miss;/*< No shard map found from the cache */
double ses_longest; /*< Longest session */
double ses_shortest; /*< Shortest session */
double ses_average; /*< Average session length */
uint64_t n_queries; /*< Number of queries forwarded */
uint64_t n_sescmd; /*< Number of session commands */
uint64_t longest_sescmd; /*< Longest chain of stored session commands */
uint64_t n_hist_exceeded; /*< Number of sessions that exceeded session
* command history limit */
uint64_t sessions; /*< Number of sessions */
uint64_t shmap_cache_hit; /*< Shard map was found from the cache */
uint64_t shmap_cache_miss; /*< No shard map found from the cache */
double ses_longest; /*< Longest session */
double ses_shortest; /*< Shortest session */
double ses_average; /*< Average session length */
Stats()
: n_queries(0)

View File

@ -212,16 +212,16 @@ void SchemaRouter::diagnostics(DCB* dcb)
/** Session command statistics */
dcb_printf(dcb, "\n\33[1;4mSession Commands\33[0m\n");
dcb_printf(dcb,
"Total number of queries: %d\n",
"Total number of queries: %lu\n",
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",
"Longest chain of stored session commands: %lu\n",
m_stats.longest_sescmd);
dcb_printf(dcb,
"Session command history limit exceeded: %d times\n",
"Session command history limit exceeded: %lu times\n",
m_stats.n_hist_exceeded);
/** Session time statistics */
@ -233,8 +233,8 @@ void SchemaRouter::diagnostics(DCB* dcb)
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", m_stats.shmap_cache_hit);
dcb_printf(dcb, "Shard map cache misses: %d\n", m_stats.shmap_cache_miss);
dcb_printf(dcb, "Shard map cache hits: %lu\n", m_stats.shmap_cache_hit);
dcb_printf(dcb, "Shard map cache misses: %lu\n", m_stats.shmap_cache_miss);
dcb_printf(dcb, "\n");
}