Skip to content

Commit 825341d

Browse files
committed
adding code to applier.go
1 parent 1962c8a commit 825341d

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

go/logic/applier.go

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"strings"
1212
"sync/atomic"
1313
"time"
14+
"context"
1415

1516
"github.com/github/gh-ost/go/base"
1617
"github.com/github/gh-ost/go/binlog"
@@ -634,7 +635,18 @@ func (this *Applier) ApplyIterationInsertQuery() (chunkSize int64, rowsAffected
634635
}
635636

636637
sqlResult, err := func() (gosql.Result, error) {
637-
tx, err := this.db.Begin()
638+
/*tx, err := this.db.Begin()*/
639+
var conn *gosql.Conn
640+
conn, err = this.db.Conn(context.Background())
641+
if (conn == nil || err != nil) {
642+
fmt.Sprintf("failed to get connection")
643+
return nil, err
644+
}
645+
if _, err := conn.ExecContext(context.Background(), "SET @@SESSION.sql_log_bin=0"); err != nil {
646+
fmt.Sprintf("failed to disable binary logs")
647+
return nil, err
648+
}
649+
tx, err := conn.BeginTx(context.Background(), nil)
638650
if err != nil {
639651
return nil, err
640652
}
@@ -643,16 +655,21 @@ func (this *Applier) ApplyIterationInsertQuery() (chunkSize int64, rowsAffected
643655
sessionQuery := fmt.Sprintf(`SET SESSION time_zone = '%s'`, this.migrationContext.ApplierTimeZone)
644656
sessionQuery = fmt.Sprintf("%s, %s", sessionQuery, this.generateSqlModeQuery())
645657

646-
if _, err := tx.Exec(sessionQuery); err != nil {
658+
if _, err := tx.ExecContext(context.Background(), sessionQuery); err != nil {
647659
return nil, err
648660
}
649-
result, err := tx.Exec(query, explodedArgs...)
661+
result, err := tx.ExecContext(context.Background(), query, explodedArgs...)
650662
if err != nil {
651663
return nil, err
652664
}
653665
if err := tx.Commit(); err != nil {
654666
return nil, err
655667
}
668+
if _, err := conn.ExecContext(context.Background(), "SET @@SESSION.sql_log_bin=1"); err != nil {
669+
fmt.Sprintf("failed to enable binary logs")
670+
return nil, err
671+
}
672+
conn.Close()
656673
return result, nil
657674
}()
658675

0 commit comments

Comments
 (0)