Bug #97870 bugs when simulator AIO find free slot in it's slots
Submitted: 3 Dec 2019 22:32 Modified: 4 Dec 2019 13:36
Reporter: Zongzhi Chen (OCA) Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server: InnoDB storage engine Severity:S3 (Non-critical)
Version:ALL OS:Linux
Assigned to: CPU Architecture:Any

[3 Dec 2019 22:32] Zongzhi Chen
Description:
The code version is 8.0.17

when user try to find a free slot in an AIO,   AIO will try to keep adjecent blocks in the same local segment, so it will start search slot at local_seg * slots_per_seg.

it will search to the end of the array. However, it don't search the slot before local_seg * slots_per_seg. Below is the code

  /* We start our search for an available slot from our preferred
  local segment and do a full scan of the array. We are
  guaranteed to find a slot in full scan. */
  for (ulint i = local_seg * slots_per_seg; counter < m_slots.size();
       ++i, ++counter) {
    i %= m_slots.size();

    slot = at(i);

    if (slot->is_reserved == false) {
      break;
    }
  }

How to repeat:
read the code..

Suggested fix:
use another loop from 0 to  local_seg * slots_per_seg to find the free slot
[4 Dec 2019 13:23] MySQL Verification Team
Hello Mr. zongzhi,

Thank you for your bug report.

However, in my humble opinion, this is not a bug. Simply, search starts from the position before which there are few or none contiguous blocks. That is how InnoDB is designed and how it will, most likely, remain.

Your proposition would slow down this storage engine considerably and that is not what majority of our customers and users would like to experience.

If you have an argument of how to do what you propose, without affecting speed of execution, let us know.
[4 Dec 2019 13:36] MySQL Verification Team
Hi Mr. zongzhi,

On further inspection, it turns out that you got confused. The loop uses `counter` variable to know how many iterations to perform, and it performs m_slots.size() iterations, so as many as there are slots:

++++++++++++++++++++++++++++++++++++++++++++++++++

  ulint counter = 0;
...
  for (...; counter < m_slots.size();
       ... ++counter) {

++++++++++++++++++++++++++++++++++++++++++++++++++

The variable `i` is the index of slot considered, and it wraps around thanks to the line 

i %= m_slots.size();

So, all slots will be considered.

Not a bug.