diff --git a/pkg/datasource/sql/undo/base/undo.go b/pkg/datasource/sql/undo/base/undo.go index c38bf4af2..8f358ebce 100644 --- a/pkg/datasource/sql/undo/base/undo.go +++ b/pkg/datasource/sql/undo/base/undo.go @@ -102,9 +102,26 @@ func (m *BaseUndoLogManager) BatchDeleteUndoLog(xid []string, branchID []int64, return nil } -// FlushUndoLog +// FlushUndoLog flush undo log func (m *BaseUndoLogManager) FlushUndoLog(txCtx *types.TransactionContext, tx driver.Conn) error { - return nil + if !txCtx.HasUndoLog() { + return nil + } + logs := []undo.SQLUndoLog{ + { + SQLType: types.SQLTypeInsert, + TableName: constant.UndoLogTableName, + Images: *txCtx.RoundImages, + }, + } + branchUndoLogs := []undo.BranchUndoLog{ + { + Xid: txCtx.XaID, + BranchID: strconv.FormatUint(txCtx.BranchID, 10), + Logs: logs, + }, + } + return m.InsertUndoLog(branchUndoLogs, tx) } // RunUndo diff --git a/pkg/datasource/sql/undo/undo.go b/pkg/datasource/sql/undo/undo.go index 7abbca2da..376f3c1fd 100644 --- a/pkg/datasource/sql/undo/undo.go +++ b/pkg/datasource/sql/undo/undo.go @@ -99,11 +99,11 @@ func GetUndoLogManager(d types.DBType) (UndoLogManager, error) { // BranchUndoLog type BranchUndoLog struct { // Xid - Xid string + Xid string `json:"xid"` // BranchID - BranchID string + BranchID string `json:"branchId"` // Logs - Logs []SQLUndoLog + Logs []SQLUndoLog `json:"sqlUndoLogs"` } // Marshal @@ -113,9 +113,9 @@ func (b *BranchUndoLog) Marshal() []byte { // SQLUndoLog type SQLUndoLog struct { - SQLType types.SQLType - TableName string - Images types.RoundRecordImage + SQLType types.SQLType `json:"sqlType"` + TableName string `json:"tableName"` + Images types.RoundRecordImage `json:"images"` } // UndoLogParser