Skip to content

Commit

Permalink
fix _ #333-2: drop schema vs session current schema
Browse files Browse the repository at this point in the history
Since non-DML (DDL) is quite rare, it is acceptable to execute 'use <db>'
each time.

#174 related.
  • Loading branch information
ffffwh committed Oct 19, 2018
1 parent cbac3b5 commit ce1c811
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
24 changes: 11 additions & 13 deletions internal/client/driver/mysql/applier.go
Original file line number Diff line number Diff line change
Expand Up @@ -1116,21 +1116,19 @@ func (a *Applier) ApplyBinlogEvent(workerIdx int, binlogEntry *binlog.BinlogEntr
binlogEntry.Coordinates.GNO, i)
switch event.DML {
case binlog.NotDML:
var err error
a.logger.Debugf("mysql.applier: ApplyBinlogEvent: not dml: %v", event.Query)

if event.CurrentSchema != "" && event.CurrentSchema != dbApplier.CurrentSchema {
query := fmt.Sprintf("USE %s", event.CurrentSchema)
a.logger.Debugf("mysql.applier: query: %v", query)
_, err := tx.Exec(query)
if err != nil {
if !sql.IgnoreError(err) {
a.logger.Errorf("mysql.applier: Exec sql error: %v", err)
return err
} else {
a.logger.Warnf("mysql.applier: Ignore error: %v", err)
}
// TODO escape schema name?
query := fmt.Sprintf("USE %s", event.CurrentSchema)
a.logger.Debugf("mysql.applier: query: %v", query)
_, err = tx.Exec(query)
if err != nil {
if !sql.IgnoreError(err) {
a.logger.Errorf("mysql.applier: Exec sql error: %v", err)
return err
} else {
dbApplier.CurrentSchema = event.CurrentSchema
a.logger.Warnf("mysql.applier: Ignore error: %v", err)
}
}

Expand All @@ -1155,7 +1153,7 @@ func (a *Applier) ApplyBinlogEvent(workerIdx int, binlogEntry *binlog.BinlogEntr
}
}

_, err := tx.Exec(event.Query)
_, err = tx.Exec(event.Query)
if err != nil {
if !sql.IgnoreError(err) {
a.logger.Errorf("mysql.applier: Exec sql error: %v", err)
Expand Down
1 change: 0 additions & 1 deletion internal/client/driver/mysql/sql/sqlutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ type Conn struct {
Db *gosql.Conn
Fde string

CurrentSchema string
PsDeleteExecutedGtid *gosql.Stmt
PsInsertExecutedGtid *gosql.Stmt
}
Expand Down

0 comments on commit ce1c811

Please sign in to comment.