baomidou / mybatis-plus

An powerful enhanced toolkit of MyBatis for simplify development
https://baomidou.com
Apache License 2.0
16.41k stars 4.31k forks source link

请教多租户插件在频繁访问的情况下,导致SQL中租户条件没有拼接的情况 #5431

Closed zhang141650 closed 1 year ago

zhang141650 commented 1 year ago

当前使用版本(必填,否则不予处理)

3.5.3

该问题是如何引起的?(确定最新版也有问题再提!!!)

频繁访问某一个接口的时候,租户条件没有拼接上,导致数据错乱

重现步骤(如果有就写完整)

报错信息

正常的情况

c.r.f.c.BxcMybatisInterceptor - [intercept,65] - 拦截器数量:3 c.r.f.c.BxcMybatisInterceptor - [intercept,70] - boundSql start -> class com.ruoyi.framework.platform.PlatLineInnerInterceptor c.r.f.p.PlatLineInnerInterceptor - [parserSingle,46] - original SQL: select name from nqi_dict where code = ? c.r.f.p.PlatLineInnerInterceptor - [processParser,86] - SQL to parse, SQL: select name from nqi_dict where code = ? c.r.f.p.PlatLineInnerInterceptor - [processParser,99] - parse the finished SQL: SELECT name FROM nqi_dict WHERE code = ? AND nqi_dict.pf_code = '1122' c.r.f.c.BxcMybatisInterceptor - [intercept,70] - boundSql start -> class com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor c.r.f.c.BxcMybatisInterceptor - [intercept,70] - boundSql start -> class com.baomidou.mybatisplus.extension.plugins.inner.BlockAttackInnerInterceptor c.r.s.m.s.c.S.getNqiDictName - [debug,137] - ==> Preparing: SELECT name FROM nqi_dict WHERE code = ? AND nqi_dict.pf_code = '1122' c.r.s.m.s.c.S.getNqiDictName - [debug,137] - ==> Parameters: B603(String) c.r.s.m.s.c.S.getNqiDictName - [debug,137] - <== Total: 1

异常情况,发现并没有进入BxcMybatisInterceptor中parserSingle相关逻辑

c.r.f.c.BxcMybatisInterceptor - [intercept,65] - 拦截器数量:3 c.r.f.c.BxcMybatisInterceptor - [intercept,70] - boundSql start -> class com.ruoyi.framework.platform.PlatLineInnerInterceptor c.r.f.c.BxcMybatisInterceptor - [intercept,70] - boundSql start -> class com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor c.r.f.c.BxcMybatisInterceptor - [intercept,70] - boundSql start -> class com.baomidou.mybatisplus.extension.plugins.inner.BlockAttackInnerInterceptor c.r.s.m.s.c.S.getNqiDictName - [debug,137] - ==> Preparing: select name from nqi_dict where code = ? c.r.s.m.s.c.S.getNqiDictName - [debug,137] - ==> Parameters: B301(String) c.r.s.m.s.c.S.getNqiDictName - [debug,137] - <== Total: 5

miemieYaho commented 1 year ago

BxcMybatisInterceptor 不是你自己写的吗?

zhang141650 commented 1 year ago

处理好了,原因是因为在忽略租户的时候忘记clear了,所以一定要清除一下 f21a7e1b2e43377f41c01119b85e4b2

TOP-LH commented 10 months ago

处理好了,原因是因为在忽略租户的时候忘记clear了,所以一定要清除一下 f21a7e1b2e43377f41c01119b85e4b2

调用这个方法需要try fianlly吗,我没加fianlly,只不过把取消的方法写在代码最后一行了,现在也会偶尔异常,不知道是不是这个问题

zhang141650 commented 6 months ago

处理好了,原因是因为在忽略租户的时候忘记clear了,所以一定要清除一下 f21a7e1b2e43377f41c01119b85e4b2

调用这个方法需要try fianlly吗,我没加fianlly,只不过把取消的方法写在代码最后一行了,现在也会偶尔异常,不知道是不是这个问题

一定要加上finally,不然如果出现异常了,就不走finally逻辑了

TOP-LH commented 5 months ago

处理好了,原因是因为在忽略租户的时候忘记clear了,所以一定要清除一下 f21a7e1b2e43377f41c01119b85e4b2

调用这个方法需要try fianlly吗,我没加fianlly,只不过把取消的方法写在代码最后一行了,现在也会偶尔异常,不知道是不是这个问题

一定要加上finally,不然如果出现异常了,就不走finally逻辑了

@miemieYaho 这种mp可以优化一下吗, 或者说在帮助文档上说明这个, 我已经写了很多代码了, 现在再去改try, finally, 入侵性太强了