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

Tinyid-Server查询db最新号段的事务使用方式存在疑问 #39

Open
max-24 opened this issue Jan 18, 2022 · 1 comment
Open

Comments

@max-24
Copy link

max-24 commented Jan 18, 2022

DbSegmentIdServiceImpl类查询db最新号段
@Transactional(isolation = Isolation.READ_COMMITTED) public SegmentId getNextSegmentId(String bizType) { // 获取nextTinyId的时候,有可能存在version冲突,需要重试 for (int i = 0; i < Constants.RETRY; i++) { TinyIdInfo tinyIdInfo = tinyIdInfoDAO.queryByBizType(bizType); ...... int row = tinyIdInfoDAO.updateMaxId(tinyIdInfo.getId(), newMaxId, oldMaxId, tinyIdInfo.getVersion(), tinyIdInfo.getBizType()); ..... } throw new TinyIdSysException("get next segmentId conflict"); }
1、查询db获取最新号段的确需要做容错重试,重试的逻辑应该是在更上层service业务做的,这里service只做单一的更新号段逻辑。
2、如果在上层service做重试,这里查询和更新操作可以不放在同一个事务中,如果考虑到同一个事务使用同一个mysql连接成本更低,这里就不用使用读已提交的隔离级别了。

@hackeryutu
Copy link

#10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants