Skip to content

Commit e012d93

Browse files
committed
feat(backend): clone-mysql-priv-in-actor #12601
1 parent 9d2a4ec commit e012d93

File tree

74 files changed

+185391
-111
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+185391
-111
lines changed

dbm-services/gen/MariaDBLexer.interp

Lines changed: 3593 additions & 0 deletions
Large diffs are not rendered by default.

dbm-services/gen/MariaDBLexer.java

Lines changed: 10341 additions & 0 deletions
Large diffs are not rendered by default.

dbm-services/gen/MariaDBLexer.tokens

Lines changed: 2351 additions & 0 deletions
Large diffs are not rendered by default.

dbm-services/go.work.sum

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3536,6 +3536,7 @@ golang.org/x/exp v0.0.0-20220827204233-334a2380cb91/go.mod h1:cyybsKvd6eL0RnXn6p
35363536
golang.org/x/exp v0.0.0-20230321023759-10a507213a29/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc=
35373537
golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63/go.mod h1:0v4NqG35kSWCMzLaMeX+IQrlSnVE/bqGSyC2cz/9Le8=
35383538
golang.org/x/exp v0.0.0-20231108232855-2478ac86f678/go.mod h1:zk2irFbV9DP96SEBUUAy67IdHUaZuSnrz1n472HUCLE=
3539+
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842/go.mod h1:XtvwrStGgqGPLc4cjQfWqZHG1YFdYs6swckp8vpsjnc=
35393540
golang.org/x/image v0.0.0-20210216034530-4410531fe030 h1:lP9pYkih3DUSC641giIXa2XqfTIbbbRr0w2EOTA7wHA=
35403541
golang.org/x/image v0.0.0-20210607152325-775e3b0c77b9/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM=
35413542
golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM=

dbm-services/mysql/db-tools/dbactuator/go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ require (
99
github.com/BurntSushi/toml v1.3.2
1010
github.com/IBM/sarama v1.42.1
1111
github.com/TylerBrock/colorjson v0.0.0-20200706003622-8a50f05110d2
12+
github.com/antlr4-go/antlr/v4 v4.13.1
1213
github.com/cloudfoundry/gosigar v1.3.59
1314
github.com/dustin/go-humanize v1.0.1
1415
github.com/github/gh-ost v1.1.6

dbm-services/mysql/db-tools/dbactuator/go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ github.com/TylerBrock/colorjson v0.0.0-20200706003622-8a50f05110d2 h1:ZBbLwSJqkH
1515
github.com/TylerBrock/colorjson v0.0.0-20200706003622-8a50f05110d2/go.mod h1:VSw57q4QFiWDbRnjdX8Cb3Ow0SFncRw+bA/ofY6Q83w=
1616
github.com/agext/levenshtein v1.2.3 h1:YB2fHEn0UJagG8T1rrWknE3ZQzWM06O8AMAatNn7lmo=
1717
github.com/agext/levenshtein v1.2.3/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558=
18+
github.com/antlr4-go/antlr/v4 v4.13.1 h1:SqQKkuVZ+zWkMMNkjy5FZe5mr5WURWnlpmOuzYWrPrQ=
19+
github.com/antlr4-go/antlr/v4 v4.13.1/go.mod h1:GKmUxMtwp6ZgGwZSva4eWPC5mS6vUAmOABFgjdkM7Nw=
1820
github.com/apparentlymart/go-textseg/v15 v15.0.0 h1:uYvfpb3DyLSCGWnctWKGj857c6ew1u1fNQOlOtuGxQY=
1921
github.com/apparentlymart/go-textseg/v15 v15.0.0/go.mod h1:K8XmNZdhEBkdlyDdvbmmsvpAG721bKi0joRfFdHIWJ4=
2022
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package mysqlcmd
2+
3+
import (
4+
"dbm-services/common/go-pubpkg/logger"
5+
"dbm-services/mysql/db-tools/dbactuator/internal/subcmd"
6+
7+
"dbm-services/mysql/db-tools/dbactuator/pkg/components/mysql/grant/import_grants_file"
8+
"dbm-services/mysql/db-tools/dbactuator/pkg/util"
9+
"fmt"
10+
11+
"github.com/spf13/cobra"
12+
)
13+
14+
const ImportGrantsFileCmd = "import-grants-file"
15+
16+
type ImportGrantsFileAct struct {
17+
*subcmd.BaseOptions
18+
Service import_grants_file.ImportGrantsFile
19+
}
20+
21+
func NewImportGrantsFileCommand() *cobra.Command {
22+
act := ImportGrantsFileAct{
23+
BaseOptions: subcmd.GBaseOptions,
24+
}
25+
cmd := &cobra.Command{
26+
Use: ImportGrantsFileCmd,
27+
Short: "clone db grants",
28+
Example: fmt.Sprintf(
29+
`dbactuator mysql %s %s %s`,
30+
ImportGrantsFileCmd, subcmd.CmdBaseExampleStr, subcmd.ToPrettyJson(act.Service.Example()),
31+
),
32+
Run: func(cmd *cobra.Command, args []string) {
33+
util.CheckErr(act.Validate())
34+
util.CheckErr(act.Init())
35+
util.CheckErr(act.Run())
36+
},
37+
}
38+
return cmd
39+
}
40+
41+
func (c *ImportGrantsFileAct) Validate() error {
42+
return c.BaseOptions.Validate()
43+
}
44+
45+
func (c *ImportGrantsFileAct) Init() error {
46+
if err := c.Deserialize(&c.Service.Params); err != nil {
47+
logger.Error("DeserializeAndValidate err %s", err.Error())
48+
return err
49+
}
50+
c.Service.GeneralParam = subcmd.GeneralRuntimeParam
51+
logger.Info("extend params: %s", c.Service.Params)
52+
return nil
53+
}
54+
55+
func (c *ImportGrantsFileAct) Run() (err error) {
56+
defer util.LoggerErrorStack(logger.Error, err)
57+
steps := subcmd.Steps{
58+
{
59+
FunName: "初始化",
60+
Func: c.Service.Init,
61+
},
62+
{
63+
FunName: "修改原始权限",
64+
Func: c.Service.ModifyPrivs,
65+
},
66+
{
67+
FunName: "写入最终权限文件",
68+
Func: c.Service.GenerateFinalFile,
69+
},
70+
{
71+
FunName: "执行导入",
72+
Func: c.Service.Import,
73+
},
74+
}
75+
76+
if err = steps.Run(); err != nil {
77+
return err
78+
}
79+
80+
logger.Info("import grants file completed")
81+
return nil
82+
}

dbm-services/mysql/db-tools/dbactuator/internal/subcmd/mysqlcmd/mysqlcmd.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ func NewMysqlCommand() *cobra.Command {
7676
v2.NewGenPeripheralToolsConfigCommand(),
7777
v2.NewReloadPeripheralToolsConfigCommand(),
7878
v2.NewInitCommonConfigCommand(),
79+
NewImportGrantsFileCommand(),
7980
},
8081
},
8182
{

dbm-services/mysql/db-tools/dbactuator/internal/subcmd/proxycmd/clone_proxy_user.go

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,16 @@
66
package proxycmd
77

88
import (
9-
"fmt"
10-
119
"dbm-services/common/go-pubpkg/logger"
1210
"dbm-services/mysql/db-tools/dbactuator/internal/subcmd"
1311
"dbm-services/mysql/db-tools/dbactuator/pkg/components/mysql_proxy"
1412
"dbm-services/mysql/db-tools/dbactuator/pkg/util"
13+
"fmt"
1514

1615
"github.com/spf13/cobra"
1716
)
1817

1918
// CloneProxyUserAct TODO
20-
// extend payload
21-
/*
22-
{
23-
"source_proxy_host": "1.1.1.1",
24-
"source_proxy_port" 10000,
25-
"target_proxy_host" "2.2.2.2",
26-
"target_proxy_port" 10000
27-
28-
}
29-
*/
3019
type CloneProxyUserAct struct {
3120
*subcmd.BaseOptions
3221
Service mysql_proxy.CloneProxyUserComp
@@ -74,10 +63,6 @@ func (c *CloneProxyUserAct) Validate() (err error) {
7463
// Run TODO
7564
func (c *CloneProxyUserAct) Run() (err error) {
7665
steps := subcmd.Steps{
77-
{
78-
FunName: "初始化",
79-
Func: c.Service.Init,
80-
},
8166
{
8267
FunName: "Clone proxy user",
8368
Func: c.Service.CloneProxyUser,

dbm-services/mysql/db-tools/dbactuator/pkg/components/mysql/backupdemand/backup_demand.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ func (c *Component) DoBackup() error {
265265
func (c *Component) generateReport() (report *Report, indexFile string, err error) {
266266
report = &Report{}
267267

268-
indexFileSearch := filepath.Join(c.backupDir, "*.index")
268+
indexFileSearch := filepath.Join(c.backupDir, fmt.Sprintf("*%d*.index", c.Params.Port))
269269
if files, err := filepath.Glob(indexFileSearch); err != nil {
270270
return nil, indexFile, err
271271
} else {
@@ -281,7 +281,7 @@ func (c *Component) generateReport() (report *Report, indexFile string, err erro
281281
continue
282282
//return nil, err
283283
}
284-
if result.BillId == c.Params.BillId && c.Params.BillId != "" {
284+
if result.BillId == c.Params.BillId && c.Params.BillId != "" && result.BackupId == c.Params.BackupId {
285285
report.Result = &result
286286
indexFile = f
287287
break

0 commit comments

Comments
 (0)