Skip to content

Commit

Permalink
add log
Browse files Browse the repository at this point in the history
  • Loading branch information
luky116 committed Nov 19, 2022
1 parent 89caeda commit dae38e4
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions pkg/datasource/sql/undo/base/undo.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ func (m *BaseUndoLogManager) Undo(ctx context.Context, dbType types.DBType, xid
defer func() {
if err != nil {
if err = tx.Rollback(); err != nil {
log.Errorf("[RunUndo] rollback fail, xid: %s, branchID:%s err:%v", xid, branchID, err)
log.Errorf("rollback fail, xid: %s, branchID:%s err:%v", xid, branchID, err)
return
}
}
Expand All @@ -231,17 +231,27 @@ func (m *BaseUndoLogManager) Undo(ctx context.Context, dbType types.DBType, xid
}
stmt, err := conn.PrepareContext(ctx, selectUndoLogSql)
if err != nil {
log.Errorf("[Undo] prepare sql fail, err: %v", err)
log.Errorf("prepare sql fail, err: %v", err)
return err
}
defer stmt.Close()
defer func() {
if err = stmt.Close(); err != nil {
log.Errorf("stmt close fail, xid: %s, branchID:%s err:%v", xid, branchID, err)
return
}
}()

rows, err := stmt.Query(branchID, xid)
if err != nil {
log.Errorf("[Undo] query sql fail, err: %v", err)
log.Errorf("query sql fail, err: %v", err)
return err
}
defer rows.Close()
defer func() {
if err = rows.Close(); err != nil {
log.Errorf("rows close fail, xid: %s, branchID:%s err:%v", xid, branchID, err)
return
}
}()

var undoLogRecords []undo.UndologRecord
for rows.Next() {
Expand Down Expand Up @@ -274,20 +284,20 @@ func (m *BaseUndoLogManager) Undo(ctx context.Context, dbType types.DBType, xid
for _, undoLog := range sqlUndoLogs {
tableMeta, err := datasource.GetTableCache(types.DBTypeMySQL).GetTableMeta(ctx, dbName, undoLog.TableName)
if err != nil {
log.Errorf("[Undo] get table meta fail, err: %v", err)
log.Errorf("get table meta fail, err: %v", err)
return err
}

undoLog.SetTableMeta(*tableMeta)

undoExecutor, err := factor.GetUndoExecutor(dbType, undoLog)
if err != nil {
log.Errorf("[Undo] get undo executor, err: %v", err)
log.Errorf("get undo executor, err: %v", err)
return err
}

if err = undoExecutor.ExecuteOn(ctx, dbType, undoLog, conn); err != nil {
log.Errorf("[Undo] execute on fail, err: %v", err)
log.Errorf("execute on fail, err: %v", err)
return err
}
}
Expand Down

0 comments on commit dae38e4

Please sign in to comment.