[MXS-3609] Some statistics use 32-bit integers Created: 2021-06-10  Updated: 2021-08-31  Resolved: 2021-08-17

Status: Closed
Project: MariaDB MaxScale
Component/s: Core
Affects Version/s: 2.4.10, 2.5.14
Fix Version/s: 2.4.18

Type: Bug Priority: Minor
Reporter: markus makela Assignee: markus makela
Resolution: Fixed Votes: 0
Labels: None

Sprint: MXS-SPRINT-138

 Description   

Some statistics in 2.4 use plain int types for statistics which overflow into negative values. Depending on the statistic it might take longer but the counter for the number of executed queries is the most problematic one.

This is not a problem in 2.5 where the statistics were converted into the generic statistics object.

The JSON library used by MaxScale doesn't support unsigned 64-bit values. To correctly handle statistics that are stored as unsigned 64-bit values, they must be made to fit the positive range of the 64-bit signed integer. This isn't really a problem in practice as most counters in MaxScale grow slowly enough to never wrap around.



 Comments   
Comment by markus makela [ 2021-08-02 ]

This will most likely be a problem in 2.5 as well as it seems to be a "limitation" of the JSON library we use. Internally, the library uses a signed 64-bit object to represent integer values in JSON objects. As we use unsigned 64-bit integers in MaxScale for statistics, the values should overflow into negative values even if the original value is not negative.

Comment by markus makela [ 2021-08-17 ]

Upon further analysis, this isn't that important to fix any time soon. Since we don't measure anything that grows by very large amounts per client request, this is not that relevant right now. Unlike values like Bytes_sent or Rows_sent in MariaDB, the fastest growing counter in MaxScale would be the epoll event counters and the packet number counter, the latter of which only counts client side packets.

The original problem described in this issue is most likely due to the fact that readconnroute uses the following struct to track statistics:

struct Stats
{
    int n_sessions = 0;     /**< Number sessions created     */
    int n_queries = 0;      /**< Number of queries forwarded */
};

A signed 32-bit integer will roll over soon enough for this to become a problem. Converting these into unsigned 64-bit integers should be an adequate solution. If counters that truly do overflow the 64-bit signed integer are added, a separate function for those that truncates the value to 63-bits is needed. For now this doesn't seem necessary.

Generated at Thu Feb 08 04:22:40 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.