-
Notifications
You must be signed in to change notification settings - Fork 283
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
Feature add has undo log table #245
Changes from 5 commits
15e054e
4759c79
9203368
50a185e
07f8d5f
50a5944
af00cc5
437f55d
cea0b62
c88a9f5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -112,6 +112,22 @@ func (m *BaseUndoLogManager) DBType() types.DBType { | |
panic("implement me") | ||
} | ||
|
||
// HasUndoLogTable check undo log table if exist | ||
func (m *BaseUndoLogManager) HasUndoLogTable(ctx context.Context, conn *sql.Conn) (res bool, err error) { | ||
_, err = conn.QueryContext(ctx, constant.CheckUndoLogTableExistSql) | ||
// 1146 mysql table not exist fault code | ||
if err != nil && strings.Contains(err.Error(), constant.ErrCodeTableNotExist) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use errors.Is instead There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 看了一下,data/sql 包里没有定义err对象的类型,所以只能这样判断一下了。 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这样写是否好点 if err != nil {
if e, ok := err.(*mysql.SQLError);ok &&e.Code == mysql.ErrNoSuchTable {
return false, nil
}
return
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 确实,已更改。 |
||
return false, nil | ||
} | ||
|
||
if err != nil { | ||
log.Errorf("[HasUndoLogTable] query sql fail, err: %v", err) | ||
return | ||
} | ||
|
||
return true, nil | ||
} | ||
|
||
// getBatchDeleteUndoLogSql build batch delete undo log | ||
func (m *BaseUndoLogManager) getBatchDeleteUndoLogSql(xid []string, branchID []int64) (string, error) { | ||
if len(xid) == 0 || len(branchID) == 0 { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,3 +71,28 @@ func TestDeleteUndoLogs(t *testing.T) { | |
testDeleteUndoLogs() | ||
}) | ||
} | ||
|
||
// TestHasUndoLogTable | ||
func TestHasUndoLogTable(t *testing.T) { | ||
// local test can annotation t.SkipNow() | ||
t.SkipNow() | ||
|
||
testHasUndoLogTable := func() { | ||
db, err := sql.Open(SeataMySQLDriver, "root:12345678@tcp(127.0.0.1:3306)/seata_order?multiStatements=true") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe the db operation need to mock? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 嗯,可以 mock,后面可以考虑做个优化什么的,现在的写法主要是为了能看出来实际效果才这样写。 |
||
assert.Nil(t, err) | ||
|
||
ctx := context.Background() | ||
sqlConn, err := db.Conn(ctx) | ||
assert.Nil(t, err) | ||
|
||
undoLogManager := new(base.BaseUndoLogManager) | ||
|
||
res, err := undoLogManager.HasUndoLogTable(ctx, sqlConn) | ||
assert.Nil(t, err) | ||
assert.True(t, res) | ||
} | ||
|
||
t.Run("test_has_undo_log_table", func(t *testing.T) { | ||
testHasUndoLogTable() | ||
}) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sql put with data model
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix done