Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add undo log manager-flush undo log func #269 #307

Merged
merged 10 commits into from
Oct 29, 2022
21 changes: 19 additions & 2 deletions pkg/datasource/sql/undo/base/undo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BranchUndoLog 加上json tag,确保undolog 转json后是这个格式,和java保持一致

{
    "branchId":2828558179596595558,
    "sqlUndoLogs":[
        {
            "afterImage":{
                "rows":[
                    {
                        "fields":[
                            {
                                "keyType":"PRIMARY_KEY",
                                "name":"id",
                                "type":4,
                                "value":3
                            },
                            {
                                "keyType":"NULL",
                                "name":"count",
                                "type":4,
                                "value":70
                            }
                        ]
                    },
                    {
                        "fields":[
                            {
                                "keyType":"PRIMARY_KEY",
                                "name":"id",
                                "type":4,
                                "value":5
                            },
                            {
                                "keyType":"NULL",
                                "name":"count",
                                "type":4,
                                "value":70
                            }
                        ]
                    }
                ],
                "tableName":"stock_tbl"
            },
            "beforeImage":{
                "rows":[
                    {
                        "fields":[
                            {
                                "keyType":"PRIMARY_KEY",
                                "name":"id",
                                "type":4,
                                "value":3
                            },
                            {
                                "keyType":"NULL",
                                "name":"count",
                                "type":4,
                                "value":100
                            }
                        ]
                    },
                    {
                        "fields":[
                            {
                                "keyType":"PRIMARY_KEY",
                                "name":"id",
                                "type":4,
                                "value":5
                            },
                            {
                                "keyType":"NULL",
                                "name":"count",
                                "type":4,
                                "value":100
                            }
                        ]
                    }
                ],
                "tableName":"stock_tbl"
            },
            "sqlType":"UPDATE",
            "tableName":"stock_tbl"
        }
    ],
    "xid":"192.168.51.102:8091:2828558179596595550"
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已添加json tag

{
Xid: txCtx.XaID,
BranchID: strconv.FormatUint(txCtx.BranchID, 10),
Logs: logs,
},
}
return m.InsertUndoLog(branchUndoLogs, tx)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

InsertUndoLog 方法好像没有实现,可以再本次PR中一起提交了

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

InsertUndoLog 这个方法已经在 #297 这个PR上实现了

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

InsertUndoLog 这个方法已经在 #297 这个PR上实现了

好的,这个先忽略哈

}

// RunUndo
Expand Down
12 changes: 6 additions & 6 deletions pkg/datasource/sql/undo/undo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down