From f527d63c86e66fc9c89a37968b070c45053758b3 Mon Sep 17 00:00:00 2001 From: Tim Vaillancourt Date: Mon, 11 Jul 2022 11:02:04 +0200 Subject: [PATCH] Move `.Kill()` func from inspector to `go/mysql` (#1148) --- go/logic/inspect.go | 10 +--------- go/mysql/utils.go | 6 ++++++ 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/go/logic/inspect.go b/go/logic/inspect.go index becda18..a562102 100644 --- a/go/logic/inspect.go +++ b/go/logic/inspect.go @@ -533,14 +533,6 @@ func (this *Inspector) estimateTableRowsViaExplain() error { return nil } -// Kill kills a query for connectionID. -// - @amason: this should go somewhere _other_ than `logic`, but I couldn't decide -// between `base`, `sql`, or `mysql`. -func Kill(db *gosql.DB, connectionID string) error { - _, err := db.Exec(`KILL QUERY %s`, connectionID) - return err -} - // CountTableRows counts exact number of rows on the original table func (this *Inspector) CountTableRows(ctx context.Context) error { atomic.StoreInt64(&this.migrationContext.CountingRowsFlag, 1) @@ -565,7 +557,7 @@ func (this *Inspector) CountTableRows(ctx context.Context) error { switch err { case context.Canceled, context.DeadlineExceeded: this.migrationContext.Log.Infof("exact row count cancelled (%s), likely because I'm about to cut over. I'm going to kill that query.", ctx.Err()) - return Kill(this.db, connectionID) + return mysql.Kill(this.db, connectionID) default: return err } diff --git a/go/mysql/utils.go b/go/mysql/utils.go index e429dc3..c69a3f2 100644 --- a/go/mysql/utils.go +++ b/go/mysql/utils.go @@ -205,3 +205,9 @@ func GetTableColumns(db *gosql.DB, databaseName, tableName string) (*sql.ColumnL } return sql.NewColumnList(columnNames), sql.NewColumnList(virtualColumnNames), nil } + +// Kill executes a KILL QUERY by connection id +func Kill(db *gosql.DB, connectionID string) error { + _, err := db.Exec(`KILL QUERY %s`, connectionID) + return err +}