Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

chore: ghost2 (#10157)

Danny Xu319f37b6ce5e
diff --git a/backend/component/ghost/config.go b/backend/component/ghost/config.go
index db3fa5fce1..bdb9a0af02 100644
--- a/backend/component/ghost/config.go
+++ b/backend/component/ghost/config.go
@@ -18,7 +18,7 @@ import (
var defaultConfig = struct {
allowedRunningOnMaster bool
concurrentCountTableRows bool
- timestampAllTable bool
+ timestampOldTable bool
hooksStatusIntervalSec int64
heartbeatIntervalMilliseconds int64
niceRatio float64
@@ -33,7 +33,7 @@ var defaultConfig = struct {
}{
allowedRunningOnMaster: true, // allow-on-master
concurrentCountTableRows: true, // concurrent-rowcount
- timestampAllTable: true, // doesn't have a gh-ost cli flag counterpart
+ timestampOldTable: true, // doesn't have a gh-ost cli flag counterpart
hooksStatusIntervalSec: 60, // hooks-status-interval
heartbeatIntervalMilliseconds: 100, // heartbeat-interval-millis
niceRatio: 0, // nice-ratio
@@ -224,6 +224,7 @@ func NewMigrationContext(taskID int, database *store.DatabaseMessage, dataSource
password = updatedPassword
migrationContext := base.NewMigrationContext()
+ migrationContext.Log = newGhostLogger()
migrationContext.InspectorConnectionConfig.Key.Hostname = dataSource.Host
port := 3306
if dataSource.Port != "" {
@@ -276,7 +277,8 @@ func NewMigrationContext(taskID int, database *store.DatabaseMessage, dataSource
migrationContext.ServeSocketFile = getSocketFilename(taskID, database.UID, database.DatabaseName, tableName)
migrationContext.DropServeSocket = true
migrationContext.PostponeCutOverFlagFile = GetPostponeFlagFilename(taskID, database.UID, database.DatabaseName, tableName)
- migrationContext.TimestampAllTable = defaultConfig.timestampAllTable
+ migrationContext.InitiallyDropGhostTable = true
+ migrationContext.TimestampOldTable = defaultConfig.timestampOldTable
migrationContext.SetHeartbeatIntervalMilliseconds(defaultConfig.heartbeatIntervalMilliseconds)
migrationContext.SetNiceRatio(defaultConfig.niceRatio)
migrationContext.SetChunkSize(defaultConfig.chunkSize)
diff --git a/backend/component/ghost/logger.go b/backend/component/ghost/logger.go
new file mode 100644
index 0000000000..104a533a9b
--- /dev/null
+++ b/backend/component/ghost/logger.go
@@ -0,0 +1,69 @@
+package ghost
+
+import (
+ "fmt"
+ "log/slog"
+
+ "github.com/openark/golib/log"
+ "github.com/pkg/errors"
+)
+
+type ghostLogger struct{}
+
+func newGhostLogger() *ghostLogger {
+ return &ghostLogger{}
+}
+
+func (*ghostLogger) Debug(args ...any) {
+ slog.Debug(fmt.Sprintf(args[0].(string), args[1:]))
+}
+
+func (*ghostLogger) Debugf(format string, args ...any) {
+ slog.Debug(format, args...)
+}
+
+func (*ghostLogger) Info(args ...any) {
+ slog.Info(fmt.Sprintf(args[0].(string), args[1:]))
+}
+
+func (*ghostLogger) Infof(format string, args ...any) {
+ slog.Info(format, args...)
+}
+
+func (*ghostLogger) Warning(args ...any) error {
+ return errors.Errorf(args[0].(string), args[1:])
+}
+
+func (*ghostLogger) Warningf(format string, args ...any) error {
+ return errors.Errorf(format, args...)
+}
+
+func (*ghostLogger) Error(args ...any) error {
+ return errors.Errorf(args[0].(string), args[1:])
+}
+
+func (*ghostLogger) Errorf(format string, args ...any) error {
+ return errors.Errorf(format, args...)
+}
+
+func (*ghostLogger) Errore(err error) error {
+ return err
+}
+
+func (*ghostLogger) Fatal(args ...any) error {
+ return errors.Errorf(args[0].(string), args[1:])
+}
+
+func (*ghostLogger) Fatalf(format string, args ...any) error {
+ return errors.Errorf(format, args...)
+}
+
+func (*ghostLogger) Fatale(err error) error {
+ return err
+}
+
+func (*ghostLogger) SetLevel(_ log.LogLevel) {
+}
+
+func (*ghostLogger) SetPrintStackTrace(_ bool) {
+}
diff --git a/backend/tests/ghost_test.go b/backend/tests/ghost_test.go
index 6379ab5c64..a895b25495 100644
--- a/backend/tests/ghost_test.go
+++ b/backend/tests/ghost_test.go
@@ -41,7 +41,7 @@ var (
//go:embed test-data/ghost_test_schema2.result
wantDBSchema2 string
- deletedRegex = regexp.MustCompile("~book_[0-9]+_del")
+ deletedRegex = regexp.MustCompile("_book_[0-9]+_del")
)
func TestGhostParser(t *testing.T) {
diff --git a/backend/tests/test-data/ghost_test_schema2.result b/backend/tests/test-data/ghost_test_schema2.result
index ed7d7f07e3..397e8f1ab2 100644
--- a/backend/tests/test-data/ghost_test_schema2.result
+++ b/backend/tests/test-data/ghost_test_schema2.result
@@ -1,21 +1,21 @@
SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
--
--- Table structure for `book`
+-- Table structure for `xxx`
--
-CREATE TABLE `book` (
+CREATE TABLE `xxx` (
`id` int NOT NULL AUTO_INCREMENT,
`name` text COLLATE utf8mb4_general_ci,
- `author` varchar(54) COLLATE utf8mb4_general_ci DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
--
--- Table structure for `xxx`
+-- Table structure for `book`
--
-CREATE TABLE `xxx` (
+CREATE TABLE `book` (
`id` int NOT NULL AUTO_INCREMENT,
`name` text COLLATE utf8mb4_general_ci,
+ `author` varchar(54) COLLATE utf8mb4_general_ci DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
diff --git a/go.mod b/go.mod
index a06c928da3..90528c9087 100644
--- a/go.mod
+++ b/go.mod
@@ -247,7 +247,7 @@ require (
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/montanaflynn/stats v0.7.0 // indirect
- github.com/openark/golib v0.0.0-20210531070646-355f37940af8 // indirect
+ github.com/openark/golib v0.0.0-20210531070646-355f37940af8
github.com/opentracing/basictracer-go v1.1.0 // indirect
github.com/opentracing/opentracing-go v1.2.0 // indirect
github.com/pierrec/lz4/v4 v4.1.18 // indirect
@@ -266,7 +266,6 @@ require (
github.com/prometheus/procfs v0.12.0 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
github.com/rs/cors v1.7.0 // indirect
- github.com/satori/go.uuid v1.2.0 // indirect
github.com/segmentio/asm v1.2.0 // indirect
github.com/segmentio/backo-go v1.0.1 // indirect
github.com/shirou/gopsutil/v3 v3.23.10 // indirect
@@ -303,7 +302,7 @@ require (
// fix potential security issue(CVE-2020-26160) introduced by indirect dependency.
replace github.com/dgrijalva/jwt-go => github.com/form3tech-oss/jwt-go v3.2.6-0.20210809144907-32ab6a8243d7+incompatible
-replace github.com/github/gh-ost => github.com/bytebase/gh-ost v1.1.3-0.20230915044519-b37a6525f8f9
+replace github.com/github/gh-ost => github.com/bytebase/gh-ost2 v0.0.0-20231212013517-59fd18dc9096
replace github.com/pingcap/tidb => github.com/bytebase/tidb2 v0.0.0-20231129002249-5bbb6bb83940
diff --git a/go.sum b/go.sum
index 25a05e1345..62edd7e7c0 100644
--- a/go.sum
+++ b/go.sum
@@ -144,8 +144,8 @@ github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA=
github.com/bsm/gomega v1.27.10/go.mod h1:JyEr/xRbxbtgWNi8tIEVPUYZ5Dzef52k01W3YH0H+O0=
github.com/bytebase/antlr/v4 v4.0.0-20231103101006-5fe1a93b199f h1:5O8DZOEloYvnAZIdHb31MT9L1Xn163rWlZqRsKqTEFM=
github.com/bytebase/antlr/v4 v4.0.0-20231103101006-5fe1a93b199f/go.mod h1:pfChB/xh/Unjila75QW7+VU4TSnWnnk9UTnmpPaOR2g=
-github.com/bytebase/gh-ost v1.1.3-0.20230915044519-b37a6525f8f9 h1:Sk8tTyttWhoKj6q5zXu6BcIM1c3B3qFWYSHJZuaf178=
-github.com/bytebase/gh-ost v1.1.3-0.20230915044519-b37a6525f8f9/go.mod h1:/HsnX0+34LXVz3MxtZoW15GiwEOXz/PrEhutjb3icfE=
+github.com/bytebase/gh-ost2 v0.0.0-20231212013517-59fd18dc9096 h1:4orVNvOnBYpgRam8ngXQBOn/tHeqU9Vy1KPUgx6/61Q=
+github.com/bytebase/gh-ost2 v0.0.0-20231212013517-59fd18dc9096/go.mod h1:VRPqaDM7UYxJbcCtQkjBcNkxW17p6LJJdkM/nYwQhqg=
github.com/bytebase/go-obo v0.0.0-20231026081615-705a7fffbfd2 h1:nEHZi8S7PHT4GxP9GfJiuhO8KkYcHmePvy5BfiYxwNk=
github.com/bytebase/go-obo v0.0.0-20231026081615-705a7fffbfd2/go.mod h1:wjDx6Xm9q7dFtHJvIlrI99JytznLw5wQ4R+9mNXJwGI=
github.com/bytebase/mysql-parser v0.0.0-20231208095055-182de2379272 h1:nBidUCDZS6hEIW90zGs4C6skFGqgxDchAgqTTGh6EQM=
@@ -925,7 +925,6 @@ github.com/sasha-s/go-deadlock v0.2.0 h1:lMqc+fUb7RrFS3gQLtoQsJ7/6TV/pAIFvBsqX73
github.com/sasha-s/go-deadlock v0.2.0/go.mod h1:StQn567HiB1fF2yJ44N9au7wOhrPS3iZqiDbRupzT10=
github.com/sashabaranov/go-openai v1.17.9 h1:QEoBiGKWW68W79YIfXWEFZ7l5cEgZBV4/Ow3uy+5hNY=
github.com/sashabaranov/go-openai v1.17.9/go.mod h1:lj5b/K+zjTSFxVLijLSTDZuP7adOgerWeFyZLUhAKRg=
-github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww=
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
github.com/sclevine/agouti v3.0.0+incompatible/go.mod h1:b4WX9W9L1sfQKXeJf1mUTLZKJ48R1S7H23Ji7oFO5Bw=
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=