Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(backend): add enable tokudb engine pipeline #1034

Merged
merged 1 commit into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 58 additions & 2 deletions .code.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,59 @@
######## Code generated by gonote. DO NOT EDIT. >>>>>

# [!勿修改模板!] 生成了默认值模板,请根据实际情况调整对应的配置值
# [!最高优先级!] 本项目的特殊配置,会覆盖命令行输入的参数
gonote:
split_ch_and_en: false # [选项开关] 修复行注释(//...)中英文词没有空格间隔,但不修复注释块(/*...*/)
without_import: true # [选项开关] 关闭 import 强制分组功能
no_line_break: false # [选项开关] 关闭过长自动换行功能
no_complete_general: false # [选项开关] 关闭补全通用注释,默认填充 ServeHTTP/String/Error 等通用注释
complete_general_config: # 内置了腾讯代码规范中的例外函数,你可以覆盖或添加更多配置
- pattern: "Run()"
annotation: Command Run
limits:
- type_func
- pattern: "Init()"
annotation: prepare run env
limits:
- type_func
- pattern: "Validate()"
annotation: run selfdefine validate function
limits:
- type_func
- pattern: "Example()"
annotation: subcommand example input
limits:
- type_func
- pattern: "PreCheck()"
annotation: pre run pre check
limits:
- type_func
- pattern: "New.*Command"
annotation: create new subcommand
limits:
- func
- pattern: "Install()"
annotation: install
limits:
- type_func
- func
# - pattern: '(.*)Req' # 匹配该正则所有的关键词
# annotation: '函数 $1 入参' # 参考 nginx 的 URL 重写 ListReq =正则匹配并解析group=> (List)Req =取出group=> ($1)Req =group替换=> 函数 List 入参
# limits:
# - func # 函数注释
# - type_func # 类型函数注释,常见结构体函数
# - type # 类型,常见结构体注释
linters:
disable_all: false
enable:
- oversize_func_arg # 函数入参过多,不能超过5个
- large_file # 超大文件检查,普通<800行,单测<1600行
- large_func # 超长函数体检查,普通<80行,单测<160行
- switch_default # switch 需要 default 分支
- bad_name # 不符合规范的命名

######## Code generated by gonote. DO NOT EDIT. <<<<<

source:
# 文件或目录使用绝对路径,绝对路径按代码库根目录计算,以/开头。
# 提供产品代码库中编写的测试代码存放目录或文件名格式,以便后续代码统计环节进行排除等特殊处理
Expand All @@ -8,10 +64,10 @@ source:
filepath_regex: [".*/test.py"]
# 提供产品代码库中工具或框架自动生成的且在代码库中的代码,没有可为空。以便后续代码统计环节进行排除等特殊处理。
auto_generate_source:
# 自动生成代码文件的正则表达式,若无统一标识格式,可以指定具体目录,样例可参考test_source举例
# 自动生成代码文件的正则表达式,若无统一标识格式,可以指定具体目录,样例可参考test_source举例
filepath_regex: [".*/migrations/.*"]
# 提供产品代码库中直接以源码形式存在的第三方代码目录或代码文件名的正则表达。
# 此处备注的第三方代码在后续统计代码量环节会被排除,若代码库中不存在需要排除的第三方代码,该项配置标识可为空
third_party_source:
#第三方代码文件的正则表达式,若无统一标识格式,可以指定具体目录,样例可参考test_source举例
filepath_regex:
filepath_regex:
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,21 @@ package mysqlcmd
import (
"fmt"

"github.com/spf13/cobra"

"dbm-services/bigdata/db-tools/dbactuator/pkg/util"
"dbm-services/common/go-pubpkg/logger"
"dbm-services/mysql/db-tools/dbactuator/internal/subcmd"
"dbm-services/mysql/db-tools/dbactuator/pkg/components/mysql/backupdemand"

"github.com/spf13/cobra"
)

// BackupDemandAct TODO
type BackupDemandAct struct {
*subcmd.BaseOptions
Payload backupdemand.Component
}

// NewBackupDemandCommand create new subcommand
func NewBackupDemandCommand() *cobra.Command {
act := BackupDemandAct{BaseOptions: subcmd.GBaseOptions}
cmd := &cobra.Command{
Expand All @@ -41,6 +43,7 @@ func NewBackupDemandCommand() *cobra.Command {
return cmd
}

// Init prepare run env
func (d *BackupDemandAct) Init() (err error) {
if err = d.BaseOptions.Validate(); err != nil { // @todo 应该在一开始就validate
return err
Expand All @@ -54,10 +57,12 @@ func (d *BackupDemandAct) Init() (err error) {
return
}

// Validate run selfdefine validate function
func (d *BackupDemandAct) Validate() error {
return nil
}

// Run start run command
func (d *BackupDemandAct) Run() (err error) {
defer util.LoggerErrorStack(logger.Error, err)
steps := subcmd.Steps{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ type Mysqld struct {
SpiderAutoIncrementModeValue SpiderAutoIncrModeValue `json:"spider_auto_increment_mode_value"`
}

// Example TODO
// Example subcommand example input
func (i *InstallMySQLComp) Example() interface{} {
comp := InstallMySQLComp{
Params: &InstallMySQLParams{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ import (
"strings"
"sync"

"github.com/pkg/errors"

"dbm-services/common/go-pubpkg/cmutil"
"dbm-services/common/go-pubpkg/logger"
"dbm-services/mysql/db-tools/dbactuator/pkg/components"
Expand All @@ -29,6 +27,8 @@ import (
"dbm-services/mysql/db-tools/dbactuator/pkg/util"
"dbm-services/mysql/db-tools/dbactuator/pkg/util/mysqlutil"
"dbm-services/mysql/db-tools/dbactuator/pkg/util/osutil"

"github.com/pkg/errors"
)

var installTokudbSQL = `
Expand Down Expand Up @@ -68,9 +68,7 @@ func (t *EnableTokudbEngineComp) CloseConn() (err error) {
return nil
}

// Example

// Example TODO
// Example subcommand example input
func (t *EnableTokudbEngineComp) Example() interface{} {
return &EnableTokudbEngineComp{
Params: EnableTokudbParams{
Expand All @@ -85,7 +83,7 @@ func (t *EnableTokudbEngineComp) Example() interface{} {
}
}

// Init TODO
// Init prepare run env
func (t *EnableTokudbEngineComp) Init() (err error) {
t.conns = make(map[Port]*native.DbWorker)
t.sockeMap = make(map[Port]string)
Expand Down Expand Up @@ -202,7 +200,7 @@ func (t *EnableTokudbEngineComp) ReWriteMyCnf() (err error) {
return err
}

// Install TODO
// Install :install
func (t *EnableTokudbEngineComp) Install() (err error) {
wg := sync.WaitGroup{}
mu := sync.Mutex{}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package sysinit
import (
"fmt"
"io/ioutil"
"os"

"dbm-services/common/go-pubpkg/logger"
"dbm-services/mysql/db-tools/dbactuator/pkg/core/staticembed"
Expand Down Expand Up @@ -41,7 +42,7 @@ func ExecSysInitScript() (err error) {
return err
}
tmpScriptName := "/tmp/sysinit.sh"
if err = ioutil.WriteFile(tmpScriptName, data, 07555); err != nil {
if err = os.WriteFile(tmpScriptName, data, 07555); err != nil {
logger.Error("write tmp script failed %s", err.Error())
return err
}
Expand Down
1 change: 1 addition & 0 deletions dbm-ui/backend/flow/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ class DBActuatorActionEnum(str, StructuredEnum):
MysqlOpenAreaImportSchema = EnumField("open_area_importschema", _("Mysql开区导入库表结构"))
MysqlOpenAreaDumpData = EnumField("open_area_dumpdata", _("Mysql开区导出库表数据"))
MysqlOpenAreaImportData = EnumField("open_area_importdata", _("Mysql开区导入库表数据"))
EnableTokudb = EnumField("enable-tokudb-engine", _("MySQL实例安装tokudb引擎"))


class RedisActuatorActionEnum(str, StructuredEnum):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ def __init__(self, root_id: str, data: Optional[Dict]):
# 声明中控实例的端口
self.data["ctl_port"] = self.data["spider_port"] + 1000

# 是否升级成tokudb引擎
if not self.data.__contains__("enable_tokudb"):
self.data["enable_tokudb"] = False

if len(self.data["remote_group"]) * int(self.data["remote_shard_num"]) != int(self.data["cluster_shard_num"]):
raise Exception(_("传入参数有异常,请检查!len(remote_group)*remote_shard_num != cluster_shard_num"))

Expand Down Expand Up @@ -251,6 +255,21 @@ def deploy_cluster(self):
)
deploy_pipeline.add_parallel_acts(acts_list=acts_list)

# 给安装好的mysql实例开启tokudb引擎
if self.data["enable_tokudb"]:
acts_list = []
for mysql_ip in self.data["mysql_ip_list"]:
exec_act_kwargs.exec_ip = mysql_ip["ip"]
exec_act_kwargs.get_mysql_payload_func = MysqlActPayload.enable_tokudb_payload.__name__
acts_list.append(
{
"act_name": _("安装tokudb引擎"),
"act_component_code": ExecuteDBActuatorScriptComponent.code,
"kwargs": asdict(exec_act_kwargs),
}
)
deploy_pipeline.add_parallel_acts(acts_list=acts_list)

acts_list = []
# 定义每个spider节点auto_incr_mode_value值,单调递增
auto_incr_value = 1
Expand Down
16 changes: 16 additions & 0 deletions dbm-ui/backend/flow/utils/mysql/mysql_act_playload.py
Original file line number Diff line number Diff line change
Expand Up @@ -2060,3 +2060,19 @@ def get_open_area_import_data_payload(self, **kwargs):
},
},
}

def enable_tokudb_payload(self, **kwargs):
"""
enable Tokudb engine for mysql instance
"""
return {
"db_type": DBActuatorTypeEnum.MySQL.value,
"action": DBActuatorActionEnum.EnableTokudb.value,
"payload": {
"general": {"runtime_account": self.account},
"extend": {
"host": kwargs["ip"],
"ports": self.ticket_data.get("mysql_ports", []),
},
},
}
Loading