Skip to content

Commit 0ed5a60

Browse files
committed
feat(mysql): table-checksum-deprecate-job-context #14464
1 parent f970aed commit 0ed5a60

File tree

19 files changed

+395
-130
lines changed

19 files changed

+395
-130
lines changed

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

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ import (
44
"bytes"
55
"dbm-services/mysql/db-tools/dbactuator/pkg/components/peripheraltools/v2/checksum"
66
"dbm-services/mysql/db-tools/mysql-table-checksum/pkg/config"
7+
"encoding/json"
78
"fmt"
89
"os"
910
"os/exec"
1011
"path"
11-
"strings"
1212
"time"
1313

1414
"dbm-services/common/go-pubpkg/logger"
@@ -138,17 +138,20 @@ func (c *PtTableChecksumComp) GenerateConfigFile() (err error) {
138138
c.Params.BkBizId, c.Params.ClusterId, c.Params.MasterPort,
139139
c.Params.InnerRole, "", c.Params.ImmuteDomain, c.Params.MasterIp,
140140
c.GeneralParam.RuntimeAccountParam.MonitorUser, c.GeneralParam.RuntimeAccountParam.MonitorPwd,
141-
"http://127.0.0.1:9999", logDir, c.Params.RuntimeHour, c.tools)
141+
"http://127.0.0.1:9999", logDir, c.Params.RuntimeHour, c.tools,
142+
)
142143

143144
cfg.PtChecksum.Replicate = c.Params.ReplicateTable
144145

145146
var ignoreDbs []string
146147
ignoreDbs = append(ignoreDbs, c.Params.SystemDbs...)
147-
ignoreDbs = append(ignoreDbs, []string{
148-
fmt.Sprintf(`%s%%`, c.Params.StageDBHeader),
149-
`bak_%`,
150-
fmt.Sprintf(`%%%s`, c.Params.RollbackDBTail),
151-
}...)
148+
ignoreDbs = append(
149+
ignoreDbs, []string{
150+
fmt.Sprintf(`%s%%`, c.Params.StageDBHeader),
151+
`bak_%`,
152+
fmt.Sprintf(`%%%s`, c.Params.RollbackDBTail),
153+
}...,
154+
)
152155

153156
cfg.SetFilter(c.Params.DbPatterns, ignoreDbs, c.Params.TablePatterns, c.Params.IgnoreTables)
154157

@@ -249,7 +252,11 @@ func (c *PtTableChecksumComp) doChecksum() (err error) {
249252
return err
250253
}
251254

252-
fmt.Println(components.WrapperOutputString(strings.TrimSpace(stdout.String())))
255+
o := make(map[string]string)
256+
o["raw_checksum_report"] = stdout.String()
257+
b, _ := json.Marshal(o)
258+
259+
fmt.Println(components.WrapperOutputString(string(b)))
253260
return nil
254261
}
255262

dbm-services/mysql/db-tools/mysql-crond/start.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ pgrep -x 'mysql-crond' && echo "mysql-crond process already running" && exit 1
1010
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
1111
if [ $# -eq 0 ];then
1212
# echo "run default ./mysql-crond -c runtime.yaml"
13-
START_CMD="cd $SCRIPT_DIR && nohup ./mysql-crond -c runtime.yaml 1>/dev/null 2>start-crond.err &"
13+
START_CMD="cd $SCRIPT_DIR && rm -f start-crond.err && nohup ./mysql-crond -c runtime.yaml 1>/dev/null 2>start-crond.err &"
1414
else
15-
START_CMD="cd $SCRIPT_DIR && nohup ./mysql-crond ${@:1} 1>/dev/null 2>start-crond.err &"
15+
START_CMD="cd $SCRIPT_DIR && rm -f start-crond.err && nohup ./mysql-crond ${@:1} 1>/dev/null 2>start-crond.err &"
1616
fi
1717

1818

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
checksum.sqlite
22
.idea
33
*.log
4-
build
4+
build
5+
test

dbm-services/mysql/db-tools/mysql-table-checksum/pkg/checker/define.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
package checker
22

33
import (
4+
"bytes"
5+
"compress/gzip"
46
"context"
7+
"encoding/base64"
58
"encoding/json"
9+
"log/slog"
610
"time"
711

812
"dbm-services/mysql/db-tools/mysql-table-checksum/pkg/config"
@@ -58,3 +62,38 @@ func (c *Output) String() string {
5862
b, _ := json.Marshal(*c)
5963
return string(b)
6064
}
65+
66+
func (c *Output) ZipString() (string, error) {
67+
b, _ := json.Marshal(*c)
68+
slog.Info("run checksum", slog.String("raw report", string(b)))
69+
70+
var zb bytes.Buffer
71+
gz, err := gzip.NewWriterLevel(&zb, gzip.BestCompression)
72+
if err != nil {
73+
return "", err
74+
}
75+
defer func() {
76+
_ = gz.Close()
77+
}()
78+
79+
_, err = gz.Write(b)
80+
if err != nil {
81+
return "", err
82+
}
83+
84+
err = gz.Flush()
85+
if err != nil {
86+
return "", err
87+
}
88+
89+
err = gz.Close()
90+
if err != nil {
91+
return "", err
92+
}
93+
94+
slog.Info("run checksum", slog.Any("zipped report", zb.Bytes()))
95+
96+
encodeReport := base64.StdEncoding.EncodeToString(zb.Bytes())
97+
slog.Info("run checksum", slog.String("encoded report", encodeReport))
98+
return encodeReport, nil
99+
}

0 commit comments

Comments
 (0)