《OceanBase 配置項&系統變量實現及應用詳解》專題導讀
在使用OceanBase的過程中,看到大家經常會遇到“參數”、“配置項”、“系統變量”等概念,卻不太清楚它們是不是同一個東西,以及應該如何使用。一些對數據庫開發感興趣的朋友,也想知道它們的實現原理是怎樣的,并且想嘗試自己增加一些配置項或者變量。
目前已經有一些文檔和博客介紹過了相關概念和基本的用法(見“參考文檔”),并且也有少量的源碼解析文章,但總的來說相關資料還不太完整。
《OceanBase 配置項&系統變量實現及應用詳解》專題基于大家的常見問題,通過基礎篇、開發篇以及應用篇的內容,給大家介紹 OceanBase 配置項以及系統變量的實現原理、使用方法、開發流程、問題排查等知識,希望能夠幫助大家解決各種應用問題。
這是專題的第一篇,主要為大家介紹配置項的基本概念和使用方法。
什么是配置項(參數)?
參數(parameter)的概念來源于Oracle,在 OceanBase 中,參數也叫做配置項,它對集群或租戶的硬件規格、部署形式、行為方式進行了定義。
在部署 OceanBase 集群時,首先就會用到配置文件。如果是白屏工具,至少也需要設置cpu數量、內存大小、磁盤大小等參數,這些參數就是“配置項”。
集群配置項示例:
// 集群cpu總數
cpu_count=8
// 系統租戶內存大小
system_memory=1G
// 集群內存總大小
memory_limit=16G
// 網絡線程數量
net_thread_count=4
配置項分為集群級別和租戶級別兩種,集群配置項對整個集群生效,只能通過系統租戶修改。租戶配置項只對當前租戶生效,可以通過當前租戶或系統租戶修改。
租戶配置項示例:
// 是否開啟負載均衡功能
enable_rebalance=true
// 是否開啟提前解行鎖功能
enable_early_lock_release=true
// 觸發凍結的內存使用比例
freeze_trigger_percentage=20
配置項會持久化到安裝目錄下的 etc/observer.config.bin 文件中,包括集群和租戶配置項,但是只存儲和默認值不同的配置項,剩下的通過默認值即可恢復。
配置項的生效方式分為動態和靜態,大部分配置項都是動態生效的,通過sql命令修改即可生效。少數配置項是靜態生效的,修改后需要重啟集群才能生效,比如 net_thread_count、enable_cgroup。
查詢配置項
配置項可以通過“show parameters”命令查詢,這種方式比較推薦。另外也可以通過視圖或內部表進行查詢,前提是需要對視圖或內部表的內容有所了解。
使用 show parameters 命令查詢配置項
- 系統租戶
1. 查詢集群配置項:
show parameters where name = 'xxx';
mysql> show parameters where name = 'cpu_count';
+-------+----------+----------------+----------+-----------+-----------+-------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------+---------+---------+-------------------+
| zone | svr_type | svr_ip | svr_port | name | data_type | value | info | section | scope | source | edit_level |
+-------+----------+----------------+----------+-----------+-----------+-------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------+---------+---------+-------------------+
| zone3 | observer | 192.168.10.3 | 12805 | cpu_count | NULL | 32 | the number of CPU\'s in the system. If this parameter is set to zero, the number will be set according to sysconf; otherwise, this parameter is used. Range: [0,+∞) in integer | OBSERVER | CLUSTER | DEFAULT | DYNAMIC_EFFECTIVE |
| zone1 | observer | 192.168.10.1 | 12801 | cpu_count | NULL | 32 | the number of CPU\'s in the system. If this parameter is set to zero, the number will be set according to sysconf; otherwise, this parameter is used. Range: [0,+∞) in integer | OBSERVER | CLUSTER | DEFAULT | DYNAMIC_EFFECTIVE |
| zone2 | observer | 192.168.10.2 | 12803 | cpu_count | NULL | 32 | the number of CPU\'s in the system. If this parameter is set to zero, the number will be set according to sysconf; otherwise, this parameter is used. Range: [0,+∞) in integer | OBSERVER | CLUSTER | DEFAULT | DYNAMIC_EFFECTIVE |
+-------+----------+----------------+----------+-----------+-----------+-------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------+---------+---------+-------------------+
3 rows in set (0.06 sec)
可以看到,一個配置項在每個節點都有一個副本,他們的值是一致的。其中 name 是配置項名;value是配置項的值;scope 表示作用域,也就是集群級別(CLUSTER)或租戶級別(TENANT);edit_level 表示生效方式,分為動態生效(DYNAMIC_EFFECTIVE)和靜態生效(STATIC_EFFECTIVE)。
2. 查詢當前租戶的配置項:
show parameters where name = 'xxx';
3. 查詢指定租戶的配置項;
show parameters where name = 'xxx' tenant = xxx;
- 普通租戶
1. 查詢集群配置項:
show parameters where name = 'xxx';
2. 查詢當前租戶的配置項:
show parameters where name = 'xxx';
mysql> show parameters where name = 'freeze_trigger_percentage';
+-------+----------+----------------+----------+---------------------------+-----------+-------+----------------------------------------------------------------------------------------+---------+--------+---------+-------------------+
| zone | svr_type | svr_ip | svr_port | name | data_type | value | info | section | scope | source | edit_level |
+-------+----------+----------------+----------+---------------------------+-----------+-------+----------------------------------------------------------------------------------------+---------+--------+---------+-------------------+
| zone1 | observer | 192.168.10.1 | 12801 | freeze_trigger_percentage | NULL | 20 | the threshold of the size of the mem store when freeze will be triggered. Rang:(0,100) | TENANT | TENANT | DEFAULT | DYNAMIC_EFFECTIVE |
| zone2 | observer | 192.168.10.2 | 12803 | freeze_trigger_percentage | NULL | 20 | the threshold of the size of the mem store when freeze will be triggered. Rang:(0,100) | TENANT | TENANT | DEFAULT | DYNAMIC_EFFECTIVE |
| zone3 | observer | 192.168.10.3 | 12805 | freeze_trigger_percentage | NULL | 20 | the threshold of the size of the mem store when freeze will be triggered. Rang:(0,100) | TENANT | TENANT | DEFAULT | DYNAMIC_EFFECTIVE |
+-------+----------+----------------+----------+---------------------------+-----------+-------+----------------------------------------------------------------------------------------+---------+--------+---------+-------------------+
3 rows in set (0.02 sec)
通過內部表與視圖查詢配置項
集群配置項和租戶配置項存在于不同的表中,通過執行“select * from xxx; ”命令即可查詢所有配置項,增加where參數也可查找指定配置項。
- __all_virtual_sys_parameter_stat
集群配置項和系統租戶的租戶配置項。
- __all_virtual_tenant_parameter_info
所有租戶的租戶配置項。
- __all_virtual_tenant_parameter_stat
集群配置項和所有租戶配置項。
- GV$OB_PARAMETERS
集群配置項和所有租戶配置項,即 __all_virtual_tenant_parameter_stat 的視圖。
mysql> select * from GV$OB_PARAMETERS where name like '%weak_read%' and zone = 'zone1';
+---------------+----------+-------+---------+-----------+------------------------------------+-----------+-------+----------------------------------------------------------------------------+----------+-------------------+
| SVR_IP | SVR_PORT | ZONE | SCOPE | TENANT_ID | NAME | DATA_TYPE | VALUE | INFO | SECTION | EDIT_LEVEL |
+---------------+----------+-------+---------+-----------+------------------------------------+-----------+-------+----------------------------------------------------------------------------+----------+-------------------+
| 192.168.10.1 | 12801 | zone1 | CLUSTER | NULL | weak_read_version_refresh_interval | NULL | 100ms | the time interval to refresh cluster weak read version Range: [50ms, +∞) | OBSERVER | DYNAMIC_EFFECTIVE |
| 192.168.10.1 | 12801 | zone1 | TENANT | 1 | enable_monotonic_weak_read | NULL | False | specifies observer supportting atomicity and monotonic order read | TENANT | DYNAMIC_EFFECTIVE |
| 192.168.10.1 | 12801 | zone1 | TENANT | 1001 | enable_monotonic_weak_read | NULL | False | specifies observer supportting atomicity and monotonic order read | TENANT | DYNAMIC_EFFECTIVE |
| 192.168.10.1 | 12801 | zone1 | TENANT | 1002 | enable_monotonic_weak_read | NULL | False | specifies observer supportting atomicity and monotonic order read | TENANT | DYNAMIC_EFFECTIVE |
+---------------+----------+-------+---------+-----------+------------------------------------+-----------+-------+----------------------------------------------------------------------------+----------+-------------------+
4 rows in set (0.00 sec)
查詢該視圖,可以同時看到集群配置項和租戶配置項,集群配置項全局唯一,租戶配置項每個租戶各有一個。
- V$OB_PARAMETERS
當前節點下所有集群配置項和租戶配置項。
- __tenant_parameter
增量租戶配置項內部表。修改租戶配置項時,會將新值寫到租戶對應的該表中,每個租戶各有一張該表。
- __all_sys_parameter
增量集群配置項內部表。系統租戶修改集群配置項時,會將新值寫到全局唯一的該表中。
修改配置項
配置項可以通過4種方式進行修改和設置:
- 部署配置文件(xxx.yaml);
- 啟動參數(./bin/observer -o xxx=xx);
- 持久化配置文件(etc/observer.config.bin);
- SQL命令(alter system set xxx=xx):
通過部署配置文件設置配置項
在使用obd工具或腳本部署 OceanBase 集群時,一般都會用到一個部署配置文件(single.yaml、distributed.yaml 等),里面的參數就是集群配置項,它們指定了集群部署的節點地址、安裝目錄、硬件規格等參數。
其中 observer.include.yaml 文件是部署工具自帶的默認配置,包含了安裝部署所需要的配置項,其中的值和代碼中配置項的默認值可能有所不同。在部署時會優先選擇用戶編寫的 xxx.yaml 中的值,然后再去 observer.include.yaml 文件中尋找配置項的值,最后才會從代碼中獲取默認值。
部署配置文件示例:
oceanbase:servers:- name: server1ip: 127.0.0.1server1:mysql_port: 23410rpc_port: 23411home_path: /data/observer1zone: zone1data_dir: /data/observer1/dataredo_dir: /data/observer1/redotag: latestinclude: /data/oceanbase/tools/deploy/obd/observer.include.yamlglobal: devname: lomemory_limit: '8G'system_memory: '1G'datafile_size: '40G'log_disk_size: '40G'cpu_count: '4'
在部署過程中,這些配置會以參數的形式出現在observer進程的啟動命令中,最終和“通過啟動參數設置配置項”殊途同歸。
通過啟動參數設置配置項
通過在 observer 的啟動命令中增加參數,可以在部署集群時直接設置配置項的值。這種方式一般很少手動使用,但在重啟observer時也是一種可行的方法。
在啟動命令中設置參數:
./observer -o xxx=xx,yyy=yy
observer啟動命令示例:
/data/user/observer1/bin/observer -p 23400 -P 23401 -z zone1 -c 1 -d /data/user/observer1/store -i lo -r 127.0.0.1:23401:23400 -o __min_full_resource_pool_memory=268435456,major_freeze_duty_time=Disable,datafile_size=20G,memory_limit=10G,system_memory=5G,cpu_count=24,stack_size=512K,cache_wash_threshold=1G,workers_per_cpu_quota=10,schema_history_expire_time=1d,net_thread_count=4,minor_freeze_times=10,enable_separate_sys_clog=False,enable_merge_by_turn=False,syslog_io_bandwidth_limit=10G,enable_async_syslog=False
通過持久化配置文件修改配置項
前面說過,配置項會持久化到文件 etc/observer.config.bin 中。如果直接修改該文件,然后再啟動集群,也可以達到修改配置項的效果。不過這種方式并不推薦,有一定風險。
持久化配置文件示例:
^A?<8d><80><80>^@?T^@ ^@^A?8^@^@^@^@^@^@^@^@^@^@^F?^@^@^F?^@^@^@^@,^L<90>4^A<9d><85><80><80>^@observer_id=1
local_ip=xxx.xxx.xxx.1
all_server_list=xxx.xxx.xxx.1:23401,xxx.xxx.xxx.2:23403,xxx.xxx.xxx.3:23405
__min_full_resource_pool_memory=1073741824
log_disk_size=100G
min_observer_version=4.2.0.0
workers_per_cpu_quota=10
cache_wash_threshold=1G
enable_syslog_wf=False
syslog_io_bandwidth_limit=10G
syslog_level=WDIAG
cluster_id=1
rootservice_list=xxx.xxx.xxx.1:23401:23400;xxx.xxx.xxx.2:23403:23402;xxx.xxx.xxx.3:23405:23404
schema_history_expire_time=1d
cpu_count=11
system_memory=2G
memory_limit=32G
net_thread_count=4
zone=zone1
devname=eth0
mysql_port=23400
rpc_port=23401
datafile_maxsize=8G
datafile_next=2G
datafile_size=80G
data_dir=/data/1/user/observer1/store
^A2<88><80><80>^@^Aí<81><80><80>^@[1]
^A?<81><80><80>^@enable_sql_extension=True
ob_compaction_schedule_interval=10s
_enable_adaptive_compaction=False
merger_check_interval=10s
partition_balance_schedule_interval=0
balancer_idle_time=10s
compatible=4.2.0.0
cpu_quota_concurrency=10
^Aà<81><80><80>^@[1001]
^A3<81><80><80>^@enable_sql_extension=True
ob_compaction_schedule_interval=10s
_enable_adaptive_compaction=False
merger_check_interval=10s
partition_balance_schedule_interval=0
compatible=4.2.0.0
^Aà<81><80><80>^@[1002]
^A3<81><80><80>^@enable_sql_extension=True
ob_compaction_schedule_interval=10s
_enable_adaptive_compaction=False
merger_check_interval=10s
partition_balance_schedule_interval=0
compatible=4.2.0.0
通過SQL命令修改配置項
用命令修改配置項是最常用的一種方式。
- 系統租戶
1. 修改集群配置項:
alter system set xxx = 'xxx';
2. 修改當前租戶的配置項:
alter system set xxx = 'xxx';
3. 修改指定租戶的配置項:
alter system set xxx = 'xxx' tenant = xxx;
4. 修改所有租戶的配置項:
alter system set xxx = 'xxx' tenant = all;
- 普通租戶
修改當前租戶的配置項:
alter system set xxx = 'xxx';
小結
本期博客介紹了配置項(參數)的概念和使用方法,相信大家只要注意區分作用域和生效方式,在使用配置項時就不會有太大問題。如果大家在部署集群或者創建租戶時遇到問題,建議看看集群或租戶配置項設置是否合理。如果測試性能不符合預期,有可能是因為租戶規格不太合適,可以試著調整下相關配置項。
下一篇博客將會介紹“系統變量”的概念和用法,并對配置項和系統變量進行對比,感興趣的同學不妨關注一下。
參考文檔
- 配置項和系統變量概述
- 配置項總覽
- OB有問必答 | 參數和變量的區別是什么?
- ???????調整 OceanBase 配置項參數???????