OceanBase 源码学习: 5.1 参数配置系统
OceanBase 源码学习: 5.1 参数配置系统
本文介绍 OceanBase 的分层参数配置系统,该系统管理集群级别和租户级别的数据库设置。该系统提供类型安全的参数定义、验证框架、动态配置更新和持久化机制。
架构概述
OceanBase 实现了一套多级参数配置系统,既支持集群范围的配置,也支持租户级的配置。该系统基于类型安全的参数定义框架构建,具备可验证、持久化和动态更新功能。
参数配置架构
源文件:
https://github.com/oceanbase/oceanbase/blob/8e2580cf/src/share/parameter/ob_parameter_seed.ipp#L1-L2000 https://github.com/oceanbase/oceanbase/blob/8e2580cf/src/share/config/ob_server_config.h#L82-L165 https://github.com/oceanbase/oceanbase/blob/8e2580cf/src/observer/omt/ob_tenant_config_mgr.h#L106-L200 https://github.com/oceanbase/oceanbase/blob/8e2580cf/src/observer/omt/ob_tenant_config.h#L34-L125 https://github.com/oceanbase/oceanbase/blob/8e2580cf/src/share/config/ob_config.h#L91-L243
参数层级和范围
配置系统在两个主要层级上运行:影响所有租户的集群范围参数,以及租户级的特定租户参数。
参数范围层次结构
源文件:
https://github.com/oceanbase/oceanbase/blob/8e2580cf/src/share/parameter/ob_parameter_seed.ipp#L15-L21 https://github.com/oceanbase/oceanbase/blob/8e2580cf/src/share/parameter/ob_parameter_seed.ipp#L152-L183 https://github.com/oceanbase/oceanbase/blob/8e2580cf/src/share/parameter/ob_parameter_attr.h#L1-L200
集群参数
集群参数使用 OB_CLUSTER_PARAMETER 宏定义,全局应用于所有租户。主要类别包括:
data_dirdatafile_size,memory_limit | ||
rpc_portdevname,mysql_port | ||
syslog_leveltrace_log_slow_query_watermark,enable_sql_audit | ||
ssl_external_kms_infotde_method |
租户参数
租户参数使用 OB_TENANT_PARAMETER 宏,可以根据指定租户进行配置:
memstore_limit_percentagefreeze_trigger_percentage | ||
cpu_quota_concurrencypx_workers_per_cpu_quota | ||
compatibleenable_monotonic_weak_read | ||
storage_rowsets_sizedefault_table_store_format |
源文件:
https://github.com/oceanbase/oceanbase/blob/8e2580cf/src/share/parameter/ob_parameter_seed.ipp#L26-L60 https://github.com/oceanbase/oceanbase/blob/8e2580cf/src/share/parameter/ob_parameter_seed.ipp#L354-L520
参数类型和验证
配置系统支持多种参数类型及其相关的验证框架。每种参数类型都提供专门的解析、验证和存储功能。
参数类型系统
源文件:
https://github.com/oceanbase/oceanbase/blob/8e2580cf/src/share/config/ob_config.h#L91-L243 https://github.com/oceanbase/oceanbase/blob/8e2580cf/src/share/config/ob_config_helper.h#L36-L500 https://github.com/oceanbase/oceanbase/blob/8e2580cf/src/share/config/ob_config_helper.cpp#L34-L700
参数类型定义
系统使用位于 ob_parameter_seed.ipp 的特定类型的宏定义参数:
DEF_STR:带有可选验证约束的字符串参数DEF_INT:带范围检查的整数参数DEF_BOOL:布尔参数(true/false)DEF_CAP:容量参数(内存/磁盘大小)DEF_TIME:时间间隔参数DEF_LOG_LEVEL:日志记录级别参数
每个参数定义包括:
默认值 值范围或验证约束 参数属性(范围、可编辑级别、section) 文档字符串(参数的描述?)
验证框架
ObConfigChecker 层次结构提供了可扩展的验证:
ObConfigIpChecker | ||
ObConfigCompressFuncChecker | default_compress_funclog_transport_compress_func | |
ObConfigMemoryLimitChecker | memory_limitsystem_memory | |
ObConfigFreezeTriggerIntChecker | freeze_trigger_percentage |
源文件:
https://github.com/oceanbase/oceanbase/blob/8e2580cf/src/share/parameter/ob_parameter_macro.h#L43-L150 https://github.com/oceanbase/oceanbase/blob/8e2580cf/src/share/config/ob_config_helper.cpp#L68-L300
配置管理生命周期
配置系统支持参数更新的“持久性、验证和动态更改”全生命周期管理。
参数更新流程
源文件:
https://github.com/oceanbase/oceanbase/blob/8e2580cf/src/share/config/ob_server_config.cpp#L93-L122 https://github.com/oceanbase/oceanbase/blob/8e2580cf/src/observer/omt/ob_tenant_config_mgr.cpp#L270-L291 https://github.com/oceanbase/oceanbase/blob/8e2580cf/src/observer/omt/ob_tenant_config.cpp#L199-L279
参数配置持久化
参数配置数据存储在 OceanBase 内部表中:
__all_sys_parameter:集群级参数__tenant_parameter:租户特定参数
ObSystemConfig 类管理数据库持久性并提供读取和写入配置数据的方法。
动态配置更新
租户配置通过 TenantConfigUpdateTask 支持动态更新:
版本检测:通过 ObTenantConfig::got_version()检测配置变化任务调度:异步调度更新以避免阻塞 批处理:多个参数更改被批处理为单个更新操作 验证:所有更改在应用前均经过验证
源文件:
https://github.com/oceanbase/oceanbase/blob/8e2580cf/src/share/config/ob_system_config.cpp#L35-L100 https://github.com/oceanbase/oceanbase/blob/8e2580cf/src/observer/omt/ob_tenant_config.cpp#L106-L193
关键代码实体
核心配置类
ObServerConfig | read_config()add_extra_config(),check_all() | |
ObTenantConfigMgr | refresh_tenants()get_lease_response(),add_tenant_config() | |
ObTenantConfig | got_version()read_config(),update_local() | |
ObConfigItem | set_value()str(),check() | |
ObSystemConfig | update()find(),read_config() |
配置访问模式
系统通过以下方式提供线程安全的配置访问:
GCONF:全局宏, 用于访问集群配置TENANT_CONF(tenant_id):用于特定租户配置访问的宏ObTenantConfigGuard:用于租户配置访问的 RAII 包装器(wrapper)
// Cluster parameter access
int64_t port = GCONF.mysql_port;
// Tenant parameter access
omt::ObTenantConfigGuard tenant_config(TENANT_CONF(tenant_id));
if (tenant_config.is_valid()) {
int64_t cpu_quota = tenant_config->cpu_quota_concurrency;
}
虚拟表集成
系统通过虚拟表公开配置(SQL接口可访问数据库配置):
__all_virtual_sys_parameter_stat:当前参数值和元数据__all_virtual_tenant_parameter_info:租户特定参数信息
这些虚拟表提供了对配置数据的 SQL 访问,方便用户进行监控和管理。
源文件:
https://github.com/oceanbase/oceanbase/blob/8e2580cf/src/share/config/ob_server_config.h#L208-L209 https://github.com/oceanbase/oceanbase/blob/8e2580cf/src/observer/omt/ob_tenant_config_mgr.h#L36-L54 https://github.com/oceanbase/oceanbase/blob/8e2580cf/src/observer/virtual_table/ob_all_virtual_tenant_parameter_info.cpp#L23-L100
更多详细内容请关注我的github: https://github.com/digoal/blog