[MDEV-21343] Threadpool/Unix- wait_begin() function does not wake/create threads, when it should Created: 2019-12-17  Updated: 2020-08-25  Resolved: 2019-12-17

Status: Closed
Project: MariaDB Server
Component/s: Server
Affects Version/s: 5.5, 10.0, 10.1, 10.2, 10.3, 10.4, 10.5
Fix Version/s: 5.5.67, 10.1.44, 10.2.31, 10.3.22, 10.4.12, 10.5.1

Type: Bug Priority: Major
Reporter: Vladislav Vaintroub Assignee: Vladislav Vaintroub
Resolution: Fixed Votes: 0
Labels: None


 Description   

There is a bug in wait notification function that greately reduces its usefulness.
It is present in all versions from 5.5 to 10.5

Let's look at the condition under which threads are woken or created

https://github.com/MariaDB/server/blob/17b4f99928eb222dcc7c7b0404ccbcd1063af026/sql/threadpool_unix.cc#L1175

threadpool_unix.cc, line 1175ff

  if ((thread_group->active_thread_count == 0) && 
     (thread_group->queue.is_empty() || !thread_group->listener))
  {
...
    wake_or_create_thread(thread_group);
  }

thread_group->queue.is_empty() means empty request queue, or that there is no work to do. So wakeup/create thread is done if there is no work to do, but not if there is some work to do.

It should actually be !thread_group->queue.is_empty() in that condition.

Historical note : this condition was initially implemented correctly, until commit 18c9b345b43b62b7c4dbac8ce0289c1c8103c2d1 (Threadpool -address review comments) removed the negation.

See
https://github.com/MariaDB/server/commit/18c9b345b43b62b7c4dbac8ce0289c1c8103c2d1#diff-efffe15be841d5d0bab2a9c92e3e9555L976


Generated at Thu Feb 08 09:06:25 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.