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

同一个线程内读写分离问题 #118

Closed
hzlzz opened this issue Jul 2, 2016 · 4 comments
Closed

同一个线程内读写分离问题 #118

hzlzz opened this issue Jul 2, 2016 · 4 comments

Comments

@hzlzz
Copy link

hzlzz commented Jul 2, 2016

同一个方法内同时有读写操作时 如果读操作在前 方法内的所有读写操作都会走从库 如果写操作在前 之后的所有读写操作都走主库

@hzlzz
Copy link
Author

hzlzz commented Jul 7, 2016

经过测试发现不加事物的时候能正常拿到对应的ds,加入事物后按第一条sql条件取ds,代码如下
@transactional
public Integer updateStatus(Integer orderId) {
Order order = orderMapper.selectByOrderId(orderId);
order.setStatus("UPDATE");
return orderMapper.updateByPrimaryKeySelective(order);
}
不加事物的时候能更新主库记录,加上事物后只有从库记录被更新

@afredlyj
Copy link

这个问题,已经确认是bug了吗?影响应该蛮大的吧

@bwzhang2011
Copy link

@terrymanu, any update with such issue ?

@hanahmily
Copy link
Contributor

这个本身是个bug,但是针对您的这种操作我建议使用HintManager的setMasterRouteOnly,将一些列操作都指向主库。这样才能保证dml操作会被即时查询到。
针对这个bug的修改为,第一次遇到dml操作后,会将之后的所有操作都保持在主库上。dml操作之前如果有dql操作,那么会从从库中进行操作。

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

5 participants