sharding-core-3.1.0 shardingsphere和pagehelper分页功能不生效问题

背景

最近定位生产环境一个GC卡顿问题,这个卡顿导致k8s心跳服务检查超时触发了docker容器重启;卡顿截图如下:

在这里插入图片描述
在这里插入图片描述

问题分析(省略过程…)

通过参考jprofiler分析内存使用情况,发现有一个接口返回内容太多,最终找到原因是这个接口分页失效导致返回内容有64MB。

sharding-core-3.1.0分页代码有问题

简单来说,当sql查询语句存在group by or order by则返回所有记录;导致代码中使用的pagehelper分页不生效

io.shardingsphere.core.routing.router.sharding.ParsingSQLRouter#processLimit

private void processLimit(final List<Object> parameters, final SelectStatement selectStatement) {
    boolean isNeedFetchAll = (!selectStatement.getGroupByItems().isEmpty() || !selectStatement.getAggregationSelectItems().isEmpty()) && !selectStatement.isSameGroupByAndOrderByItems();
    selectStatement.getLimit().processParameters(parameters, isNeedFetchAll, databaseType);
}

io.shardingsphere.core.parsing.parser.context.limit.Limit#rewrite

private void rewrite(final List<Object> parameters, final boolean isFetchAll, final DatabaseType databaseType) {
    int rewriteOffset = 0;
    int rewriteRowCount;
    if (isFetchAll) {
        rewriteRowCount = Integer.MAX_VALUE;
    } else if (isNeedRewriteRowCount(databaseType)) {
        rewriteRowCount = null == rowCount ? -1 : getOffsetValue() + rowCount.getValue();
    } else {
        rewriteRowCount = rowCount.getValue();
    }
    if (null != offset && offset.getIndex() > -1) {
        parameters.set(offset.getIndex(), rewriteOffset);
    }
    if (null != rowCount && rowCount.getIndex() > -1) {
        parameters.set(rowCount.getIndex(), rewriteRowCount);
    }
}

代码优化

  1. 代码逻辑允许情况下,不使用 group by 或 order by
  2. 修改源代码实现
  3. 官网有issue意见解决 https://github.com/apache/shardingsphere/pull/1736

其他方法还在研究

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值