@@ -11,6 +11,7 @@ import (
11
11
"strings"
12
12
"sync/atomic"
13
13
"time"
14
+ "context"
14
15
15
16
"github.com/github/gh-ost/go/base"
16
17
"github.com/github/gh-ost/go/binlog"
@@ -634,7 +635,18 @@ func (this *Applier) ApplyIterationInsertQuery() (chunkSize int64, rowsAffected
634
635
}
635
636
636
637
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 )
638
650
if err != nil {
639
651
return nil , err
640
652
}
@@ -643,16 +655,21 @@ func (this *Applier) ApplyIterationInsertQuery() (chunkSize int64, rowsAffected
643
655
sessionQuery := fmt .Sprintf (`SET SESSION time_zone = '%s'` , this .migrationContext .ApplierTimeZone )
644
656
sessionQuery = fmt .Sprintf ("%s, %s" , sessionQuery , this .generateSqlModeQuery ())
645
657
646
- if _ , err := tx .Exec ( sessionQuery ); err != nil {
658
+ if _ , err := tx .ExecContext ( context . Background (), sessionQuery ); err != nil {
647
659
return nil , err
648
660
}
649
- result , err := tx .Exec ( query , explodedArgs ... )
661
+ result , err := tx .ExecContext ( context . Background (), query , explodedArgs ... )
650
662
if err != nil {
651
663
return nil , err
652
664
}
653
665
if err := tx .Commit (); err != nil {
654
666
return nil , err
655
667
}
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 ()
656
673
return result , nil
657
674
}()
658
675
0 commit comments