From 74593ec0109c2041b46838fa5487d6b2a5f6fa5b Mon Sep 17 00:00:00 2001 From: Shlomi Noach Date: Thu, 18 Aug 2016 13:31:53 +0200 Subject: [PATCH 1/2] DML write wrapped in transaction - solving the golang problem: 'sql: converting Exec argument #2's type: uint64 values with high bit set are not supported' --- go/logic/applier.go | 35 ++++++++++++++++++----------------- go/sql/builder.go | 2 +- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/go/logic/applier.go b/go/logic/applier.go index 951addb6a..7e526b95a 100644 --- a/go/logic/applier.go +++ b/go/logic/applier.go @@ -854,31 +854,32 @@ func (this *Applier) ApplyDMLEventQuery(dmlEvent *binlog.BinlogDMLEvent) error { return err } - // TODO The below is commented, and is in preparation for transactional writes on the ghost tables. + // TODO The below is in preparation for transactional writes on the ghost tables. // Such writes would be, for example: // - prepended with sql_mode setup + // - prepended with time zone setup // - prepended with SET SQL_LOG_BIN=0 // - prepended with SET FK_CHECKS=0 // etc. // - // Current known problem: https://github.com/golang/go/issues/9373 -- bitint unsigned values, not supported in database/sql + // a known problem: https://github.com/golang/go/issues/9373 -- bitint unsigned values, not supported in database/sql + // is solved by silently converting unsigned bigints to string values. // - // err = func() error { - // tx, err := this.db.Begin() - // if err != nil { - // return err - // } - // if _, err := tx.Exec(query, args...); err != nil { - // return err - // } - // if err := tx.Commit(); err != nil { - // return err - // } - // return nil - // }() - - _, err = sqlutils.Exec(this.db, query, args...) + err = func() error { + tx, err := this.db.Begin() + if err != nil { + return err + } + if _, err := tx.Exec(query, args...); err != nil { + return err + } + if err := tx.Commit(); err != nil { + return err + } + return nil + }() + if err == nil { atomic.AddInt64(&this.migrationContext.TotalDMLEventsApplied, 1) } diff --git a/go/sql/builder.go b/go/sql/builder.go index 6c2e4b2d2..7c670a9ac 100644 --- a/go/sql/builder.go +++ b/go/sql/builder.go @@ -47,7 +47,7 @@ func fixArgType(arg interface{}, isUnsigned bool) interface{} { return uint32(i) } if i, ok := arg.(int64); ok { - return uint64(i) + return strconv.FormatUint(uint64(i), 10) } if i, ok := arg.(int); ok { return uint(i) From 75e0d123027b2a8fda1100eee1b624a404d081e6 Mon Sep 17 00:00:00 2001 From: Shlomi Noach Date: Thu, 18 Aug 2016 13:38:23 +0200 Subject: [PATCH 2/2] simplified error logic; fixed incorrect RowsEstimate handling on error --- go/logic/applier.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/go/logic/applier.go b/go/logic/applier.go index 7e526b95a..10da785b8 100644 --- a/go/logic/applier.go +++ b/go/logic/applier.go @@ -880,15 +880,14 @@ func (this *Applier) ApplyDMLEventQuery(dmlEvent *binlog.BinlogDMLEvent) error { return nil }() - if err == nil { - atomic.AddInt64(&this.migrationContext.TotalDMLEventsApplied, 1) + if err != nil { + err = fmt.Errorf("%s; query=%s; args=%+v", err.Error(), query, args) + return log.Errore(err) } + // no error + atomic.AddInt64(&this.migrationContext.TotalDMLEventsApplied, 1) if this.migrationContext.CountTableRows { atomic.AddInt64(&this.migrationContext.RowsEstimate, rowDelta) } - if err != nil { - err = fmt.Errorf("%s; query=%s; args=%+v", err.Error(), query, args) - log.Errore(err) - } - return err + return nil }