本文介绍进行租户缩容时减少 Unit 配置,执行修改 resource unit 语句操作报 1235 错误的处理方法。
适用版本
OceanBase 数据库所有版本。
问题描述
进行租户缩容时,减少 Unit 配置,执行修改 resource unit 语句操作报错,错误信息如下。
obclient> ALTER RESOURCE UNIT u1 MAX_CPU 31, MIN_CPU 28.97, MAX_MEMORY '214748364800B', MIN_MEMORY '214748364800B';
ERROR 1235 (0A000): requested min_memory over 90 percent of total available memory not supported
可能原因
根据错误信息可知是由于所需的内存超过了 memory_limit_percentage 参数设置的上限。此时减少 Unit 配置出现错误,说明已使用内存超过了调整后的内存上限。
sys 租户在执行 Unit 内存变更时,按以下公式计算缩容后使用内存。
old_max_memory/100 * memstore_limit_percentage * (new_min_memory/old_min_memory) * 0.9
其中 old_max_memory、old_min_memory 分别为修改前 Unit 的 MAX_MEMORY 与 MIN_MEMORY 配置,new_min_memory 为修改后 Unit 的 MIN_MEMORY 配置。
如果上式计算结果小于系统表 gv$memstore 中 active 列的值,则 OceanBase 数据库会认为租户在缩容后存在内存不足的风险,导致执行失败。
例如,要进行缩容的租户 tenant_id 为 1024,zone_list 为 zone2,执行以下语句。
obclient> SELECT IP,tenant_id,concat(cast(active/1024/1024/1024 as unsigned),' GB') as total FROM gv$memstore WHERE TENANT_ID = 1002;
+----------------+-----------+--------+
| IP | tenant_id | active |
+----------------+-----------+--------+
| xxx.xx.xxx.xxx | 1002 | 120 GB |
+----------------+-----------+--------+
1 rows in set (0.00 sec)
查询 zone2 的 memstore_limit_percentage,可见该参数为 50。
obclient> show parameters like '%memstore_limit_percentage%';
+-------+----------+----------------+----------+---------------------------+-----------+-------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+---------+---------+---------+-------------------+
| zone | svr_type | svr_ip | svr_port | name | data_type | value | info | section | scope | source | edit_level |
+-------+----------+----------------+----------+---------------------------+-----------+-------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+---------+---------+---------+-------------------+
| zone2 | observer | xxx.xx.xxx.xxx | 2882 | memstore_limit_percentage | NULL | 50 | used in calculating the value of MEMSTORE_LIMIT parameter: memstore_limit_percentage = memstore_limit / max_memory,where MAX_MEMORY is determined when the tenant is created. Range: (0, 100) | TENANT | CLUSTER | DEFAULT | DYNAMIC_EFFECTIVE |
+-------+----------+----------------+----------+---------------------------+-----------+-------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+---------+---------+---------+-------------------+
1 rows in set (0.00 sec)
代入公式,400/100 * 50 * ( 200/400 ) * 0.9 = 90 GB,小于 gv$memstore 中 active 的值 120 GB,因此执行失败。
解决方法
执行合并释放内存后,再尝试缩容。步骤如下:
开启手动合并。
obclient> ALTER SYSTEM SET ENABLE_MANUAL_MEREG='True';指定 Zone 发起手动合并。
obclient> ALTER SYSTEM START MERGE ZONE='zone2';再次尝试缩容。
obclient> ALTER RESOURCE UNIT u1 MAX_CPU 31, MIN_CPU 28.97, MAX_MEMORY '214748364800B', MIN_MEMORY '214748364800B';