Bug #99274 Resource Groups are not usable inside Container with CPU limited
Submitted: 16 Apr 2020 6:33 Modified: 29 Apr 2020 17:41
Reporter: Adun Chan Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Optimizer Severity:S4 (Feature request)
Version:8.0.19 OS:Linux
Assigned to: CPU Architecture:Any

[16 Apr 2020 6:33] Adun Chan
Description:
Host machine have 40 CPUS, from 0 to 39.
build a LXC Container and give CPU 3, 4, 7, 8 to this Container.

MySQL Server will detect that it have 4 CPUS, and set default resource group URS_default and SYS_default's VPU_IDS to 0-3, such as:

```
mysql> select * from information_schema.resource_groups\G
*************************** 1. row ***************************
   RESOURCE_GROUP_NAME: USR_default
   RESOURCE_GROUP_TYPE: USER
RESOURCE_GROUP_ENABLED: 1
              VCPU_IDS: 0-3
       THREAD_PRIORITY: 0
```

1. when we try to create/alter a Resource Group with real CPU ID, such as 3,4, error occured:

```
mysql> ALTER RESOURCE GROUP low VCPU=3,4;
ERROR 3652 (HY000): Invalid cpu id 4 
```

2. we can create Resource Group with CPU ID below 4(because mysql detect 4 cpus), such as CPU 0, but we can not set this resource group to a thread. Because Host OS didn't give this CPU ID to Container:

```
ERROR 3661 (HY000): Unable to bind resource group rg with thread id (308485).(Failed to apply thread resource controls).
```

3. If I create a resource group with cpu ID 3, I can bind this rg to thread, but I can not bind this thread to default rg, because default rg have CPU IDS 0-3. Because the mysql server's cpu IDS are 3,4,7,8 

How to repeat:
1. create a container with LXC, set cpu limit, you can reproduce this situation;
2. or start mysql-server with taskset, i think it can be repprduce too.

Suggested fix:
1. validate_vcpu_range_vector: do not check valid cpu id by num_cpus, but check if the CPU ID is owned by mysql-server
2. resource_group_mgr: except get cpu numbers, CPU IDS owned by mysql-server should be stored too.
[29 Apr 2020 17:07] MySQL Verification Team
Hi,

Thanks for the report. I need to check this a bit more. Not sure if we at all support this real/virtual CPU detection.

thanks
Bogdan
[29 Apr 2020 17:41] MySQL Verification Team
Hi,

I verified this with LXC.

LXC is not a supported platform so I changed the Severity from a bug to a Feature Request. 

thanks for the report
Bogdan