项目是老项目了,没什么改动,前两天客户返回产品保存,排查发现是查询产品属性数据时没有查到,sql语句复制出来,navicat直接查有数据。
开始怀疑项目代码有问题,排查mapper映射,class属性,都没问题,还没解决,客服反映产品正常了,再查日志,相同sql又查到数据了;
本来以为是偶发问题,结果第二天又出现同样问题,服务器管理员排查发现数据库坏了2块硬盘,好嘛,还以为就这原因,结果今天新硬盘换好,数据复建完,还同样出问题,实在没法了,来这里问下有没有同僚,碰到过一样的问题,求解!
你这什么细节都没有,只有现象
那别人也只能靠猜了
我猜是你数据库里没有建立索引
当数据量少的时候没有问题,查询都很快
数据量大了之后就开始超时
偶尔访问量小,cpu不忙的时候,可能又不超时了
-=-=-=
看日志不能只看查到没查到,看从查询到查到数据到底用了多少时间
1.修改查询语句条件,定位是否是某个条件有问题,特别是时间等字段
2.是否是中文引起的,试试修改连接字符串的编码
我截取了部分问题日志,不存在超时情况,就单表数据量也不多
[DEBUG] 2021-09-17 19:25:44,643 method:org.apache.ibatis.logging.jdbc.BaseJdbcLogger.debug(BaseJdbcLogger.java:145)
==> Preparing: select * from studio_product_class_specifications where id = ?
[DEBUG] 2021-09-17 19:25:44,644 method:org.apache.ibatis.logging.jdbc.BaseJdbcLogger.debug(BaseJdbcLogger.java:145)
==> Parameters: 76(Long)
[DEBUG] 2021-09-17 19:25:44,645 method:org.apache.ibatis.logging.jdbc.BaseJdbcLogger.debug(BaseJdbcLogger.java:145)
<== Total: 0
[DEBUG] 2021-09-17 19:25:44,646 method:org.apache.ibatis.logging.jdbc.BaseJdbcLogger.debug(BaseJdbcLogger.java:145)
==> Preparing: select * from studio_product_class_specifications where id = ?
[DEBUG] 2021-09-17 19:25:44,646 method:org.apache.ibatis.logging.jdbc.BaseJdbcLogger.debug(BaseJdbcLogger.java:145)
==> Parameters: 81(Long)
[DEBUG] 2021-09-17 19:25:44,647 method:org.apache.ibatis.logging.jdbc.BaseJdbcLogger.debug(BaseJdbcLogger.java:145)
<== Total: 0
而且同时期,管理后台项目出问题,销售前台项目正常查询,下面是正常的日志,同一个产品
==> Preparing: select * from studio_product_class_specifications where id = ?
2021-09-17 19:29:57 [http-nio-9092-exec-1] DEBUG c.s.p.d.S.selectStudioProductClassSpecificationsById fcbf406669964e1d9ce844ef3e41df3d - ==> Parameters: 76(Long)
2021-09-17 19:29:57 [http-nio-9092-exec-1] DEBUG c.s.p.d.S.selectStudioProductClassSpecificationsById fcbf406669964e1d9ce844ef3e41df3d - <== Total: 1
2021-09-17 19:29:57 [http-nio-9092-exec-1] DEBUG c.s.p.d.S.selectStudioProductClassSpecificationsById fcbf406669964e1d9ce844ef3e41df3d - ==> Preparing: select * from studio_product_class_specifications where id = ?
2021-09-17 19:29:57 [http-nio-9092-exec-1] DEBUG c.s.p.d.S.selectStudioProductClassSpecificationsById fcbf406669964e1d9ce844ef3e41df3d - ==> Parameters: 81(Long)
2021-09-17 19:29:57 [http-nio-9092-exec-1] DEBUG c.s.p.d.S.selectStudioProductClassSpecificationsById fcbf406669964e1d9ce844ef3e41df3d - <== Total: 1
就是时好时坏,根据日志,已经执行了sql,也不存在缓存问题,mapper映射,我直接returnType了,属性字段一个一个对了,这些应该都可以排除,因为他大多数时间是正常的
简单的主键查询,就一个Long类型ID,我脑袋炸了,找不到问题啊