Bug #78454 Overflow in calculation of 'memory usage percent' in Event Buffer
Submitted: 16 Sep 2015 12:54 Modified: 18 Sep 2015 11:16
Reporter: Ole John Aske Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Cluster: NDB API Severity:S3 (Non-critical)
Version:7.4.8 OS:Any
Assigned to: CPU Architecture:Any

[16 Sep 2015 12:54] Ole John Aske
Description:
The Event-API calculates a 'memory usage percent' from the total amount
of event memory allocated (EventBuffer::m_total_alloc). As this calculation
is performed as Uint32 arithmetics, the calculation will overflow when 
m_total_alloc > ~40Mb (40Mb * 100 > 4Gb!). Thus any reported 'memory usage percent'
becomes unreliable when the total amount of allocated event buffer memory exceed 40Mb.

This affects (at least):

- Ndb::get_eventbuffer_memory_usage() may report an incorrect EventBufferMemoryUsage::usage_percent

And likely more serious:

- It breaks the protection mechanism intended to start rejecting incoming events 
  and instead creates a gap-event if the 'memory_usage_percent' becomes to high.
  (Ref : Ndb::set_eventbuf_max_alloc() and Ndb::set_eventbuffer_free_percent())

How to repeat:
Check code

Suggested fix:
Use UInt64 in the internal calculations.
[18 Sep 2015 11:16] Jon Stephens
Documented bug fix in the NDB 7.4.8 changelog as follows:

    If the total amount of memory allocated for the event buffer
    exceeded approximately 40 MB, the calculation of memory usage
    percentages could overflow during computation. This was due to
    the fact that the associated routine used 32-bit arithmetic;
    this has now been changed to use Uint64 values instead.
      
Closed.