Scheduler
scheduler特性是在ProxySQL v1.2.0引入的。
scheduler是一个类似cron的调度器,已经被集成到ProxySQL中了,粒度可以达到毫秒级。通过admin即可配置:目前不支持配置文件配置,将来也没这个打算
Motivation
scheduler可以以规定的间隔执行你自定义的脚本,其主要目的是这个脚本能够监控到外部异常事件的发生从而能够重新配置ProxySQL
Implementation
通过两个表来实现这个功能
1 Admin> SHOW TABLES LIKE '%scheduler%';2 +-------------------+3 | tables |4 +-------------------+5 | scheduler |6 | runtime_scheduler |7 +-------------------+8 2 rows in set (0.00 sec)
具体细节:
- 通过scheduler表配置调度器
- runtime_scheduler表示调度器在runtime状态的表现形式
scheduler表结构:
1 Admin> SHOW CREATE TABLE scheduler\G 2 *************************** 1. row *************************** 3 table: scheduler 4 Create Table: CREATE TABLE scheduler ( 5 id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, 6 active INT CHECK (active IN (0,1)) NOT NULL DEFAULT 1, 7 interval_ms INTEGER CHECK (interval_ms>=100 AND interval_ms<=100000000) NOT NULL, 8 filename VARCHAR NOT NULL, 9 arg1 VARCHAR,10 arg2 VARCHAR,11 arg3 VARCHAR,12 arg4 VARCHAR,13 arg5 VARCHAR,14 comment VARCHAR NOT NULL DEFAULT '')15 1 row in set (0.00 sec)
字段描述:
- id:调度器唯一标识
- active:如果是1,那么调度器是生效的,否则不生效
- interval_ms:间隔多少毫秒执行。最小值是100毫秒
- filename:可执行文件全路径
- arg1~arg5:传递到job的参数,最多5个
- comment:解释job功能的comment
runtime_scheduler有着相同的表结构:
1 Admin> SHOW CREATE TABLE runtime_scheduler\G 2 *************************** 1. row *************************** 3 table: runtime_scheduler 4 Create Table: CREATE TABLE runtime_scheduler ( 5 id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, 6 active INT CHECK (active IN (0,1)) NOT NULL DEFAULT 1, 7 interval_ms INTEGER CHECK (interval_ms>=100 AND interval_ms<=100000000) NOT NULL, 8 filename VARCHAR NOT NULL, 9 arg1 VARCHAR,10 arg2 VARCHAR,11 arg3 VARCHAR,12 arg4 VARCHAR,13 arg5 VARCHAR,14 comment VARCHAR NOT NULL DEFAULT '')15 1 row in set (0.00 sec)
至于其他的配置表,配置后都需要load到runtime或者持久化到磁盘,所以针对schedule也有一些新命令:
LOAD SCHEDULER TO RUNTIME
或者LOAD SCHEDULER FROM MEMORY
: load the configuration frommain
.scheduler
to runtime, and becomes effective;LOAD SCHEDULER TO MEMORY
或者LOAD SCHEDULER FROM DISK
:load the configuration fromdisk
.scheduler
tomain
.scheduler
;SAVE SCHEDULER FROM RUNTIME
或者SAVE SCHEDULER TO MEMORY
: save the configuration from runtime tomain
.scheduler
;SAVE SCHEDULER FROM MEMORY
或者SAVE SCHEDULER TO DISK
:save the configuration frommain
.scheduler
todisk
.scheduler
, and becomes persistent across restart.
调度器是通过调用fork(),然后调用execve()来实现的,如果执行execve()失败,错误日志将会记录到error log中。