Skip to content
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

Unexpected slave datasource routing result when using Round-robin load-balance algorithm in Mybatis #735

Closed
shulyLi opened this issue Apr 17, 2018 · 14 comments

Comments

@shulyLi
Copy link

shulyLi commented Apr 17, 2018

org.apache.ibatis.executor.statement.PreparedStatementHandler.query
image

ps.execute(); 会调用一次 MasterSlaveLoadBalanceAlgorithm.getDataSource

这是函数调用栈
image

return resultSetHandler. handleResultSets(ps); 也会调用 MasterSlaveLoadBalanceAlgorithm.getDataSource
这是函数调用栈

image

就是 一次 数据操作 会让 RoundBin 的 计数 增加2
一般都是 用 id & ((1<< x) - 1) 就会 ~~

这问题 怕是修复不了吧~

@shulyLi shulyLi changed the title 结合 ibits 用 random 做随机会有温通 结合 ibits 用 RoundBin 做随机会有温通 Apr 17, 2018
@shulyLi shulyLi closed this as completed Apr 17, 2018
@shulyLi shulyLi reopened this Apr 17, 2018
@shulyLi shulyLi changed the title 结合 ibits 用 RoundBin 做随机会有温通 结合 ibits 用 RoundBin 做随机会有问题 Apr 17, 2018
@terrymanu
Copy link
Member

Please provide version

@pg-yang
Copy link
Member

pg-yang commented Apr 20, 2018

我也发现有同样的问题,我的版本号是 sharding-jdbc-spring-boot-starter 2.0.0.M3

@haocao
Copy link
Member

haocao commented Apr 20, 2018

Could you please provide the problem sample code which based on https://github.com/shardingjdbc/sharding-jdbc-example and put it on github?
Just put your complete project codes inside of sharding-jdbc-spring-boot-example/sharding-jdbc-spring-boot-data-mybatis-example, and we can run it to reproduce the problem. Thanks for your helps.
@shulyLi @ypg521

@pg-yang
Copy link
Member

pg-yang commented Apr 20, 2018

OK,At Weekend. I must BanZhuan today

@haocao
Copy link
Member

haocao commented Apr 20, 2018

@ypg521 Thanks, just remind that don't push any sensitive data or codes into github.

@shulyLi
Copy link
Author

shulyLi commented Apr 20, 2018

我不认为 这算一个bug, 只不过在一次的操作内进行了多次 getDataSource,
roundbin : atomic.increase 次数多。且影响 轮训的效果, 且cas 毕竟是一个CPU支持的原子操作。
random : new Random().nextInt(slaveDataSourceNames.size()) 要System.nanoTime()的
都不是 频繁友好的操作。

@shulyLi
Copy link
Author

shulyLi commented Apr 20, 2018

Forgive me for not using English

@pg-yang
Copy link
Member

pg-yang commented Apr 20, 2018

But The result is always hit a same DB If you have 2 slave DB

@shulyLi
Copy link
Author

shulyLi commented Apr 20, 2018

@ypg521 The amount of concurrency is too low

@pg-yang
Copy link
Member

pg-yang commented Apr 20, 2018

@shulyLi mybatis在第二次获取connection的时候,使用的是Statement.getConnection(); 我理解的是Statement在第二次获取connection的时候,是不需要getDataSource的; 抱歉我英语不好。

@shulyLi
Copy link
Author

shulyLi commented Apr 20, 2018

@ypg521 说的也对,尽管 不能说是bug 但是在一次 原子查询里就要进行多次的 get 也不太合理

@pg-yang
Copy link
Member

pg-yang commented Apr 22, 2018

@terrymanu
Copy link
Member

terrymanu commented Apr 22, 2018

master slave module is coupling with JDBC, we plan to split it from JDBC layer, and will fix this issue at that time.

@haocao haocao changed the title 结合 ibits 用 RoundBin 做随机会有问题 在Mybatis中使用RoundRobinMasterSlaveLoadBalanceAlgorithm算法路由存在问题 May 11, 2018
@haocao
Copy link
Member

haocao commented May 11, 2018

Fixed in 3.0.0.M1

@haocao haocao closed this as completed May 11, 2018
@terrymanu terrymanu changed the title 在Mybatis中使用RoundRobinMasterSlaveLoadBalanceAlgorithm算法路由存在问题 Unexpected slave datasource routing result when using Round-robin load-balance algorithm in Mybatis Aug 8, 2018
@terrymanu terrymanu changed the title Unexpected slave datasource routing result when using Round-robin load-balance algorithm in Mybatis Unexpected slave datasource routing result when using Round-robin load-balance algorithm in Mybatis Aug 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants