From 2311df412dea20efdb1075ca2fe804c88f107dd7 Mon Sep 17 00:00:00 2001 From: Shlomi Noach Date: Mon, 12 Mar 2018 16:17:53 +0200 Subject: [PATCH] gbk support, simplified --- go/base/context.go | 1 - go/cmd/gh-ost/main.go | 1 - go/logic/applier.go | 2 +- go/logic/inspect.go | 4 ++-- go/logic/streamer.go | 2 +- go/logic/throttler.go | 2 +- go/mysql/connection.go | 9 ++------- go/mysql/connection_test.go | 4 ++-- go/mysql/utils.go | 2 +- 9 files changed, 10 insertions(+), 17 deletions(-) diff --git a/go/base/context.go b/go/base/context.go index 78402c6..23fe6f6 100644 --- a/go/base/context.go +++ b/go/base/context.go @@ -91,7 +91,6 @@ type MigrationContext struct { SkipRenamedColumns bool IsTungsten bool DiscardForeignKeys bool - IncludeRiskyCharsets bool config ContextConfig configMutex *sync.Mutex diff --git a/go/cmd/gh-ost/main.go b/go/cmd/gh-ost/main.go index a75bc0a..6d29fc4 100644 --- a/go/cmd/gh-ost/main.go +++ b/go/cmd/gh-ost/main.go @@ -120,7 +120,6 @@ func main() { version := flag.Bool("version", false, "Print version & exit") checkFlag := flag.Bool("check-flag", false, "Check if another flag exists/supported. This allows for cross-version scripting. Exits with 0 when all additional provided flags exist, nonzero otherwise. You must provide (dummy) values for flags that require a value. Example: gh-ost --check-flag --cut-over-lock-timeout-seconds --nice-ratio 0") flag.StringVar(&migrationContext.ForceTmpTableName, "force-table-names", "", "table name prefix to be used on the temporary tables") - flag.BoolVar(&migrationContext.IncludeRiskyCharsets, "include-risk-charset", false, "charset includes risk encoding, e.g. gbk, gb2312, big5, cp932, sjis") flag.CommandLine.SetOutput(os.Stdout) flag.Parse() diff --git a/go/logic/applier.go b/go/logic/applier.go index 2f47a77..227b59e 100644 --- a/go/logic/applier.go +++ b/go/logic/applier.go @@ -69,7 +69,7 @@ func NewApplier(migrationContext *base.MigrationContext) *Applier { func (this *Applier) InitDBConnections() (err error) { - applierUri := this.connectionConfig.GetDBUri(this.migrationContext.DatabaseName, this.migrationContext.IncludeRiskyCharsets) + applierUri := this.connectionConfig.GetDBUri(this.migrationContext.DatabaseName) if this.db, _, err = mysql.GetDB(this.migrationContext.Uuid, applierUri); err != nil { return err } diff --git a/go/logic/inspect.go b/go/logic/inspect.go index 8924d2f..31c81dc 100644 --- a/go/logic/inspect.go +++ b/go/logic/inspect.go @@ -40,12 +40,12 @@ func NewInspector(migrationContext *base.MigrationContext) *Inspector { } func (this *Inspector) InitDBConnections() (err error) { - inspectorUri := this.connectionConfig.GetDBUri(this.migrationContext.DatabaseName, this.migrationContext.IncludeRiskyCharsets) + inspectorUri := this.connectionConfig.GetDBUri(this.migrationContext.DatabaseName) if this.db, _, err = mysql.GetDB(this.migrationContext.Uuid, inspectorUri); err != nil { return err } - informationSchemaUri := this.connectionConfig.GetDBUri("information_schema", false) + informationSchemaUri := this.connectionConfig.GetDBUri("information_schema") if this.informationSchemaDb, _, err = mysql.GetDB(this.migrationContext.Uuid, informationSchemaUri); err != nil { return err } diff --git a/go/logic/streamer.go b/go/logic/streamer.go index a4ac9c3..37e7195 100644 --- a/go/logic/streamer.go +++ b/go/logic/streamer.go @@ -103,7 +103,7 @@ func (this *EventsStreamer) notifyListeners(binlogEvent *binlog.BinlogDMLEvent) } func (this *EventsStreamer) InitDBConnections() (err error) { - EventsStreamerUri := this.connectionConfig.GetDBUri(this.migrationContext.DatabaseName, this.migrationContext.IncludeRiskyCharsets) + EventsStreamerUri := this.connectionConfig.GetDBUri(this.migrationContext.DatabaseName) if this.db, _, err = mysql.GetDB(this.migrationContext.Uuid, EventsStreamerUri); err != nil { return err } diff --git a/go/logic/throttler.go b/go/logic/throttler.go index 5bb7b07..624956a 100644 --- a/go/logic/throttler.go +++ b/go/logic/throttler.go @@ -183,7 +183,7 @@ func (this *Throttler) collectControlReplicasLag() { ) readReplicaLag := func(connectionConfig *mysql.ConnectionConfig) (lag time.Duration, err error) { - dbUri := connectionConfig.GetDBUri("information_schema", false) + dbUri := connectionConfig.GetDBUri("information_schema") var heartbeatValue string if db, _, err := mysql.GetDB(this.migrationContext.Uuid, dbUri); err != nil { diff --git a/go/mysql/connection.go b/go/mysql/connection.go index 41978ac..c9c75f2 100644 --- a/go/mysql/connection.go +++ b/go/mysql/connection.go @@ -49,18 +49,13 @@ func (this *ConnectionConfig) Equals(other *ConnectionConfig) bool { return this.Key.Equals(&other.Key) || this.ImpliedKey.Equals(other.ImpliedKey) } -func (this *ConnectionConfig) GetDBUri(databaseName string, IncludeRiskyCharsets bool) string { +func (this *ConnectionConfig) GetDBUri(databaseName string) string { hostname := this.Key.Hostname var ip = net.ParseIP(hostname) if (ip != nil) && (ip.To4() == nil) { // Wrap IPv6 literals in square brackets hostname = fmt.Sprintf("[%s]", hostname) } - riskyCharsets := "" interpolateParams := true - if IncludeRiskyCharsets { - interpolateParams = false - riskyCharsets = ",gbk,gb2312,big5,cp932,sjis" - } - return fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?interpolateParams=%t&autocommit=true&charset=utf8mb4,utf8,latin1%s", this.User, this.Password, hostname, this.Key.Port, databaseName, interpolateParams, riskyCharsets) + return fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?interpolateParams=%t&autocommit=true&charset=utf8mb4,utf8,latin1", this.User, this.Password, hostname, this.Key.Port, databaseName, interpolateParams) } diff --git a/go/mysql/connection_test.go b/go/mysql/connection_test.go index da4b825..ae7d17b 100644 --- a/go/mysql/connection_test.go +++ b/go/mysql/connection_test.go @@ -61,8 +61,8 @@ func TestGetDBUri(t *testing.T) { c.User = "gromit" c.Password = "penguin" - uri := c.GetDBUri("test", true) + uri := c.GetDBUri("test") test.S(t).ExpectEquals(uri, "gromit:penguin@tcp(myhost:3306)/test?interpolateParams=false&autocommit=true&charset=utf8mb4,utf8,latin1,gbk,gb2312,big5,cp932,sjis") - uri = c.GetDBUri("test", false) + uri = c.GetDBUri("test") test.S(t).ExpectEquals(uri, "gromit:penguin@tcp(myhost:3306)/test?interpolateParams=true&autocommit=true&charset=utf8mb4,utf8,latin1") } diff --git a/go/mysql/utils.go b/go/mysql/utils.go index 23c4fa6..532cbb4 100644 --- a/go/mysql/utils.go +++ b/go/mysql/utils.go @@ -75,7 +75,7 @@ func GetReplicationLag(informationSchemaDb *gosql.DB, connectionConfig *Connecti } func GetMasterKeyFromSlaveStatus(connectionConfig *ConnectionConfig) (masterKey *InstanceKey, err error) { - currentUri := connectionConfig.GetDBUri("information_schema", false) + currentUri := connectionConfig.GetDBUri("information_schema") // This function is only called once, okay to not have a cached connection pool db, err := gosql.Open("mysql", currentUri) if err != nil {