From 67c5997b3e1509644364cbd6631c53d954a0c182 Mon Sep 17 00:00:00 2001 From: lxfeng1997 <824141436@qq.com> Date: Mon, 2 Jan 2023 21:44:04 +0800 Subject: [PATCH 1/2] bugfix: at model execution failed --- pkg/datasource/sql/exec/at/delete_executor.go | 1 + pkg/datasource/sql/exec/at/insert_executor.go | 1 + pkg/datasource/sql/exec/at/update_executor.go | 2 ++ testdata/sql/undo_log.sql | 15 +++++++++++++++ 4 files changed, 19 insertions(+) create mode 100644 testdata/sql/undo_log.sql diff --git a/pkg/datasource/sql/exec/at/delete_executor.go b/pkg/datasource/sql/exec/at/delete_executor.go index 589f8b5b9..5111acd29 100644 --- a/pkg/datasource/sql/exec/at/delete_executor.go +++ b/pkg/datasource/sql/exec/at/delete_executor.go @@ -87,6 +87,7 @@ func (d *deleteExecutor) beforeImage(ctx context.Context) (*types.RecordImage, e } if ok { rowsi, err = util.CtxDriverQuery(ctx, queryerCtx, queryer, selectSQL, selectArgs) + defer rowsi.Close() if err != nil { log.Errorf("ctx driver query: %+v", err) return nil, err diff --git a/pkg/datasource/sql/exec/at/insert_executor.go b/pkg/datasource/sql/exec/at/insert_executor.go index 14d731356..0e2d83b59 100644 --- a/pkg/datasource/sql/exec/at/insert_executor.go +++ b/pkg/datasource/sql/exec/at/insert_executor.go @@ -110,6 +110,7 @@ func (i *insertExecutor) afterImage(ctx context.Context) (*types.RecordImage, er } if ok { rowsi, err = util.CtxDriverQuery(ctx, queryerCtx, queryer, selectSQL, selectArgs) + defer rowsi.Close() if err != nil { log.Errorf("ctx driver query: %+v", err) return nil, err diff --git a/pkg/datasource/sql/exec/at/update_executor.go b/pkg/datasource/sql/exec/at/update_executor.go index 46b927fa8..f56e09377 100644 --- a/pkg/datasource/sql/exec/at/update_executor.go +++ b/pkg/datasource/sql/exec/at/update_executor.go @@ -108,6 +108,7 @@ func (u *updateExecutor) beforeImage(ctx context.Context) (*types.RecordImage, e } if ok { rowsi, err = util.CtxDriverQuery(ctx, queryerCtx, queryer, selectSQL, selectArgs) + defer rowsi.Close() if err != nil { log.Errorf("ctx driver query: %+v", err) return nil, err @@ -153,6 +154,7 @@ func (u *updateExecutor) afterImage(ctx context.Context, beforeImage types.Recor } if ok { rowsi, err = util.CtxDriverQuery(ctx, queryerCtx, queryer, selectSQL, selectArgs) + defer rowsi.Close() if err != nil { log.Errorf("ctx driver query: %+v", err) return nil, err diff --git a/testdata/sql/undo_log.sql b/testdata/sql/undo_log.sql new file mode 100644 index 000000000..7a00b709d --- /dev/null +++ b/testdata/sql/undo_log.sql @@ -0,0 +1,15 @@ +DROP TABLE IF EXISTS `undo_log`; +CREATE TABLE `undo_log` +( + `id` bigint(20) NOT NULL AUTO_INCREMENT, + `branch_id` bigint(20) NOT NULL, + `xid` varchar(100) NOT NULL, + `context` varchar(128) NOT NULL, + `rollback_info` longblob NOT NULL, + `log_status` int(11) NOT NULL, + `log_created` datetime NOT NULL, + `log_modified` datetime NOT NULL, + `ext` varchar(100) DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `ux_undo_log` (`xid`,`branch_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; \ No newline at end of file From 8e0ddfb0b67aa5bdaa981a0948ab0b983b8f2dc2 Mon Sep 17 00:00:00 2001 From: lxfeng1997 <824141436@qq.com> Date: Mon, 2 Jan 2023 21:57:38 +0800 Subject: [PATCH 2/2] add test nil --- pkg/datasource/sql/exec/at/delete_executor.go | 6 +++++- pkg/datasource/sql/exec/at/insert_executor.go | 6 +++++- pkg/datasource/sql/exec/at/update_executor.go | 12 ++++++++++-- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/pkg/datasource/sql/exec/at/delete_executor.go b/pkg/datasource/sql/exec/at/delete_executor.go index 5111acd29..9179acb72 100644 --- a/pkg/datasource/sql/exec/at/delete_executor.go +++ b/pkg/datasource/sql/exec/at/delete_executor.go @@ -87,7 +87,11 @@ func (d *deleteExecutor) beforeImage(ctx context.Context) (*types.RecordImage, e } if ok { rowsi, err = util.CtxDriverQuery(ctx, queryerCtx, queryer, selectSQL, selectArgs) - defer rowsi.Close() + defer func() { + if rowsi != nil { + rowsi.Close() + } + }() if err != nil { log.Errorf("ctx driver query: %+v", err) return nil, err diff --git a/pkg/datasource/sql/exec/at/insert_executor.go b/pkg/datasource/sql/exec/at/insert_executor.go index 0e2d83b59..3fb67e1c5 100644 --- a/pkg/datasource/sql/exec/at/insert_executor.go +++ b/pkg/datasource/sql/exec/at/insert_executor.go @@ -110,7 +110,11 @@ func (i *insertExecutor) afterImage(ctx context.Context) (*types.RecordImage, er } if ok { rowsi, err = util.CtxDriverQuery(ctx, queryerCtx, queryer, selectSQL, selectArgs) - defer rowsi.Close() + defer func() { + if rowsi != nil { + rowsi.Close() + } + }() if err != nil { log.Errorf("ctx driver query: %+v", err) return nil, err diff --git a/pkg/datasource/sql/exec/at/update_executor.go b/pkg/datasource/sql/exec/at/update_executor.go index f56e09377..645a7f474 100644 --- a/pkg/datasource/sql/exec/at/update_executor.go +++ b/pkg/datasource/sql/exec/at/update_executor.go @@ -108,7 +108,11 @@ func (u *updateExecutor) beforeImage(ctx context.Context) (*types.RecordImage, e } if ok { rowsi, err = util.CtxDriverQuery(ctx, queryerCtx, queryer, selectSQL, selectArgs) - defer rowsi.Close() + defer func() { + if rowsi != nil { + rowsi.Close() + } + }() if err != nil { log.Errorf("ctx driver query: %+v", err) return nil, err @@ -154,7 +158,11 @@ func (u *updateExecutor) afterImage(ctx context.Context, beforeImage types.Recor } if ok { rowsi, err = util.CtxDriverQuery(ctx, queryerCtx, queryer, selectSQL, selectArgs) - defer rowsi.Close() + defer func() { + if rowsi != nil { + rowsi.Close() + } + }() if err != nil { log.Errorf("ctx driver query: %+v", err) return nil, err