From 5159f95f2cc8495caf925069e40b9b7ae2c2e432 Mon Sep 17 00:00:00 2001 From: Tim Vaillancourt Date: Fri, 8 Jul 2022 01:59:49 +0200 Subject: [PATCH 1/4] Enable more `golang-ci` linters --- .golangci.yml | 16 ++++++++++++++-- go/cmd/gh-ost/main.go | 7 +++---- go/logic/applier.go | 1 - go/logic/migrator.go | 4 ++-- go/logic/server.go | 4 +--- go/logic/streamer.go | 1 - go/logic/throttler.go | 1 - go/mysql/instance_key.go | 2 +- go/sql/builder.go | 2 +- go/sql/parser.go | 3 +-- go/sql/parser_test.go | 6 +----- 11 files changed, 24 insertions(+), 23 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 4e0bc4fa5..e5bd47b86 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,13 +1,25 @@ run: timeout: 5m modules-download-mode: readonly - linters: disable: - errcheck enable: + - contextcheck + - durationcheck + - errname + - execinquery + - gofmt + - ifshort + - misspell + - nilerr - noctx + - nolintlint + - nosprintfhostport + - prealloc - rowserrcheck - sqlclosecheck + - unconvert - unused - + - wastedassign + - whitespace diff --git a/go/cmd/gh-ost/main.go b/go/cmd/gh-ost/main.go index 9dc5702c6..cc807cf23 100644 --- a/go/cmd/gh-ost/main.go +++ b/go/cmd/gh-ost/main.go @@ -270,7 +270,7 @@ func main() { } if *askPass { fmt.Println("Password:") - bytePassword, err := term.ReadPassword(int(syscall.Stdin)) + bytePassword, err := term.ReadPassword(syscall.Stdin) if err != nil { migrationContext.Log.Fatale(err) } @@ -300,10 +300,9 @@ func main() { acceptSignals(migrationContext) migrator := logic.NewMigrator(migrationContext, AppVersion) - err := migrator.Migrate() - if err != nil { + if err := migrator.Migrate(); err != nil { migrator.ExecOnFailureHook() migrationContext.Log.Fatale(err) } - fmt.Fprintf(os.Stdout, "# Done\n") + fmt.Fprintln(os.Stdout, "# Done") } diff --git a/go/logic/applier.go b/go/logic/applier.go index 0fbf9f382..79d9083c4 100644 --- a/go/logic/applier.go +++ b/go/logic/applier.go @@ -1042,7 +1042,6 @@ func (this *Applier) buildDMLEventQuery(dmlEvent *binlog.BinlogDMLEvent) (result // ApplyDMLEventQueries applies multiple DML queries onto the _ghost_ table func (this *Applier) ApplyDMLEventQueries(dmlEvents [](*binlog.BinlogDMLEvent)) error { - var totalDelta int64 err := func() error { diff --git a/go/logic/migrator.go b/go/logic/migrator.go index 1f949067a..002f4bf02 100644 --- a/go/logic/migrator.go +++ b/go/logic/migrator.go @@ -977,7 +977,7 @@ func (this *Migrator) printStatus(rule PrintStatusRule, writers ...io.Writer) { state = fmt.Sprintf("throttled, %s", throttleReason) } - shouldPrintStatus := false + var shouldPrintStatus bool if rule == HeuristicPrintStatusRule { if elapsedSeconds <= 60 { shouldPrintStatus = true @@ -1291,7 +1291,7 @@ func (this *Migrator) executeWriteFuncs() error { if niceRatio := this.migrationContext.GetNiceRatio(); niceRatio > 0 { copyRowsDuration := time.Since(copyRowsStartTime) sleepTimeNanosecondFloat64 := niceRatio * float64(copyRowsDuration.Nanoseconds()) - sleepTime := time.Duration(time.Duration(int64(sleepTimeNanosecondFloat64)) * time.Nanosecond) + sleepTime := time.Duration(sleepTimeNanosecondFloat64) * time.Nanosecond time.Sleep(sleepTime) } } diff --git a/go/logic/server.go b/go/logic/server.go index 5356a8227..4b1b87023 100644 --- a/go/logic/server.go +++ b/go/logic/server.go @@ -1,5 +1,5 @@ /* - Copyright 2021 GitHub Inc. + Copyright 2022 GitHub Inc. See https://github.com/github/gh-ost/blob/master/LICENSE */ @@ -122,8 +122,6 @@ func (this *Server) onServerCommand(command string, writer *bufio.Writer) (err e // applyServerCommand parses and executes commands by user func (this *Server) applyServerCommand(command string, writer *bufio.Writer) (printStatusRule PrintStatusRule, err error) { - printStatusRule = NoPrintStatusRule - tokens := strings.SplitN(command, "=", 2) command = strings.TrimSpace(tokens[0]) arg := "" diff --git a/go/logic/streamer.go b/go/logic/streamer.go index 3041d7bf6..dc40ca3b2 100644 --- a/go/logic/streamer.go +++ b/go/logic/streamer.go @@ -59,7 +59,6 @@ func NewEventsStreamer(migrationContext *base.MigrationContext) *EventsStreamer // AddListener registers a new listener for binlog events, on a per-table basis func (this *EventsStreamer) AddListener( async bool, databaseName string, tableName string, onDmlEvent func(event *binlog.BinlogDMLEvent) error) (err error) { - this.listenersMutex.Lock() defer this.listenersMutex.Unlock() diff --git a/go/logic/throttler.go b/go/logic/throttler.go index 849f40fc2..1e7bc972f 100644 --- a/go/logic/throttler.go +++ b/go/logic/throttler.go @@ -180,7 +180,6 @@ func (this *Throttler) collectReplicationLag(firstThrottlingCollected chan<- boo // collectControlReplicasLag polls all the control replicas to get maximum lag value func (this *Throttler) collectControlReplicasLag() { - if atomic.LoadInt64(&this.migrationContext.HibernateUntil) > 0 { return } diff --git a/go/mysql/instance_key.go b/go/mysql/instance_key.go index 679bdc9f0..923725c76 100644 --- a/go/mysql/instance_key.go +++ b/go/mysql/instance_key.go @@ -35,7 +35,7 @@ const detachHint = "//" // ParseInstanceKey will parse an InstanceKey from a string representation such as 127.0.0.1:3306 func NewRawInstanceKey(hostPort string) (*InstanceKey, error) { - hostname := "" + var hostname string port := "" if submatch := ipv4HostPortRegexp.FindStringSubmatch(hostPort); len(submatch) > 0 { hostname = submatch[1] diff --git a/go/sql/builder.go b/go/sql/builder.go index b24a848d1..025d4a8ea 100644 --- a/go/sql/builder.go +++ b/go/sql/builder.go @@ -167,7 +167,7 @@ func BuildRangeComparison(columns []string, values []string, args []interface{}, if includeEquals { comparison, err := BuildEqualsComparison(columns, values) if err != nil { - return "", explodedArgs, nil + return "", explodedArgs, err } comparisons = append(comparisons, comparison) explodedArgs = append(explodedArgs, args...) diff --git a/go/sql/parser.go b/go/sql/parser.go index eac0bdce3..a72af332e 100644 --- a/go/sql/parser.go +++ b/go/sql/parser.go @@ -1,5 +1,5 @@ /* - Copyright 2016 GitHub Inc. + Copyright 2022 GitHub Inc. See https://github.com/github/gh-ost/blob/master/LICENSE */ @@ -135,7 +135,6 @@ func (this *AlterTableParser) parseAlterToken(alterToken string) (err error) { } func (this *AlterTableParser) ParseAlterStatement(alterStatement string) (err error) { - this.alterStatementOptions = alterStatement for _, alterTableRegexp := range alterTableExplicitSchemaTableRegexps { if submatch := alterTableRegexp.FindStringSubmatch(this.alterStatementOptions); len(submatch) > 0 { diff --git a/go/sql/parser_test.go b/go/sql/parser_test.go index 645989d76..79a9b7bdd 100644 --- a/go/sql/parser_test.go +++ b/go/sql/parser_test.go @@ -1,5 +1,5 @@ /* - Copyright 2016 GitHub Inc. + Copyright 2022 GitHub Inc. See https://github.com/github/gh-ost/blob/master/LICENSE */ @@ -40,7 +40,6 @@ func TestParseAlterStatementTrivialRename(t *testing.T) { } func TestParseAlterStatementWithAutoIncrement(t *testing.T) { - statements := []string{ "auto_increment=7", "auto_increment = 7", @@ -150,7 +149,6 @@ func TestSanitizeQuotesFromAlterStatement(t *testing.T) { } func TestParseAlterStatementDroppedColumns(t *testing.T) { - { parser := NewAlterTableParser() statement := "drop column b" @@ -190,7 +188,6 @@ func TestParseAlterStatementDroppedColumns(t *testing.T) { } func TestParseAlterStatementRenameTable(t *testing.T) { - { parser := NewAlterTableParser() statement := "drop column b" @@ -230,7 +227,6 @@ func TestParseAlterStatementRenameTable(t *testing.T) { } func TestParseAlterStatementExplicitTable(t *testing.T) { - { parser := NewAlterTableParser() statement := "drop column b" From 576124cdd247cb0fac78c2aabf3b11df8065ba3d Mon Sep 17 00:00:00 2001 From: Tim Vaillancourt Date: Sat, 9 Jul 2022 03:16:34 +0200 Subject: [PATCH 2/4] simplify --- go/mysql/instance_key.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/go/mysql/instance_key.go b/go/mysql/instance_key.go index 923725c76..3d2bff114 100644 --- a/go/mysql/instance_key.go +++ b/go/mysql/instance_key.go @@ -35,8 +35,7 @@ const detachHint = "//" // ParseInstanceKey will parse an InstanceKey from a string representation such as 127.0.0.1:3306 func NewRawInstanceKey(hostPort string) (*InstanceKey, error) { - var hostname string - port := "" + var hostname, port string if submatch := ipv4HostPortRegexp.FindStringSubmatch(hostPort); len(submatch) > 0 { hostname = submatch[1] port = submatch[2] From a474f62483a29f29ba0fdf81a346a7a4bdfece1f Mon Sep 17 00:00:00 2001 From: Tim Vaillancourt Date: Wed, 13 Jul 2022 02:47:08 +0200 Subject: [PATCH 3/4] restore int64() assertion --- go/logic/migrator.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go/logic/migrator.go b/go/logic/migrator.go index 002f4bf02..5a5803688 100644 --- a/go/logic/migrator.go +++ b/go/logic/migrator.go @@ -1291,7 +1291,7 @@ func (this *Migrator) executeWriteFuncs() error { if niceRatio := this.migrationContext.GetNiceRatio(); niceRatio > 0 { copyRowsDuration := time.Since(copyRowsStartTime) sleepTimeNanosecondFloat64 := niceRatio * float64(copyRowsDuration.Nanoseconds()) - sleepTime := time.Duration(sleepTimeNanosecondFloat64) * time.Nanosecond + sleepTime := time.Duration(int64(sleepTimeNanosecondFloat64)) * time.Nanosecond time.Sleep(sleepTime) } } From 2027c3fe0824e05774aa2e4b7ada4515104e740b Mon Sep 17 00:00:00 2001 From: Tim Vaillancourt Date: Thu, 14 Jul 2022 02:10:29 +0200 Subject: [PATCH 4/4] Dont make modules readonly --- .golangci.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.golangci.yml b/.golangci.yml index e5bd47b86..4621e5cf6 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,6 +1,5 @@ run: timeout: 5m - modules-download-mode: readonly linters: disable: - errcheck