Skip to content

Commit

Permalink
feat(dbm-services): 增加mysql本地升级command close #1457
Browse files Browse the repository at this point in the history
  • Loading branch information
ymakedaq committed Oct 31, 2023
1 parent cf35c51 commit 11652b8
Show file tree
Hide file tree
Showing 11 changed files with 2,066 additions and 7 deletions.
13 changes: 13 additions & 0 deletions dbm-services/common/go-pubpkg/cmutil/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,19 @@ func GetGcsSystemDatabasesIgnoreTest(version string) []string {
return DBs
}

// TmysqlVersionParse TODO
/*
input: select version() 获取到的string
output: 获取tmysql带的版本号
example:
5.7.20-tmysql-3.1.5-log ==> 3*1000000 + 1*1000 + 5 ==> 3001005
返回0,表示非tmysql
*/
func TmysqlVersionParse(version string) uint64 {
re := regexp.MustCompile(`tmysql-([\d]+).?([\d]+)?.?([\d]+)?`)
return mysqlVersionParse(re, version)
}

// MySQLVersionParse ():
// input: select version() 获取到的string
// output: 获取tmysql中的mysql前缀版本
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
// Package mysqlcmd TODO
/*
* TencentBlueKing is pleased to support the open source community by making 蓝鲸智云-DB管理系统(BlueKing-BK-DBM) available.
* Copyright (C) 2017-2023 THL A29 Limited, a Tencent company. All rights reserved.
* Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at https://opensource.org/licenses/MIT
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
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"
)

// UpgradeMySQLAct TODO
type UpgradeMySQLAct struct {
*subcmd.BaseOptions
Service mysql.MysqlUpgradeComp
}

// NewUpgradeMySQLCommand create new subcommand
func NewUpgradeMySQLCommand() *cobra.Command {
act := UpgradeMySQLAct{
BaseOptions: subcmd.GBaseOptions,
}
cmd := &cobra.Command{
Use: "upgrade",
Short: "MySQL版本本地升级",
Example: fmt.Sprintf(
`dbactuator mysql upgrade %s %s`, subcmd.CmdBaseExampleStr,
subcmd.ToPrettyJson(act.Service.Example()),
),
Run: func(cmd *cobra.Command, args []string) {
util.CheckErr(act.Validate())
if act.RollBack {
util.CheckErr(act.Rollback())
return
}
util.CheckErr(act.Init())
util.CheckErr(act.Run())
},
}
return cmd
}

// Init prepare run env
func (d *UpgradeMySQLAct) Init() (err error) {
if err = d.Deserialize(&d.Service.Params); err != nil {
logger.Error("DeserializeAndValidate err %s", err.Error())
return err
}
d.Service.GeneralParam = subcmd.GeneralRuntimeParam
return
}

// Run Command Run
func (d *UpgradeMySQLAct) Run() (err error) {
steps := subcmd.Steps{
{
FunName: "Init",
Func: d.Service.Init,
},
{
FunName: "前置检查",
Func: d.Service.PreCheck,
},
{
FunName: "升级检查",
Func: d.Service.MysqlUpgradeCheck,
},
}
if d.Service.Params.Run {
steps = append(steps, subcmd.StepFunc{
FunName: "升级MySQL",
Func: d.Service.Upgrade,
})
}

if err := steps.Run(); err != nil {
return err
}
logger.Info("upgrade mysql or mysql upgrade check successfully")
return nil
}

// Rollback TODO
func (d *UpgradeMySQLAct) Rollback() (err error) {
return
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func NewMysqlCommand() *cobra.Command {
NewExecSQLFileCommand(),
CloneClientGrantCommand(),
NewBackupTruncateDatabaseCommand(),
NewUpgradeMySQLCommand(),
// NewBackupDatabaseTableCommand(),
MycnfChangeCommand(),
FindLocalBackupCommand(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (p *StartMySQLParam) StartMysqlInstance() (pid int, err error) {
myCnfName = p.MyCnfName
startCmd = fmt.Sprintf(
`ulimit -n 204800;
cd %s && %s ./bin/mysqld_safe --defaults-file=%s --user=mysql `, mediaDir, numaStr, myCnfName,
cd %s && %s ./bin/mysqld_safe --defaults-file=%s --user=mysql `, mediaDir, numaStr, myCnfName,
)
)
if p.SkipSlaveFlag {
Expand Down
Loading

0 comments on commit 11652b8

Please sign in to comment.