File tree 1 file changed +6
-1
lines changed
tinyid-server/src/main/java/com/xiaoju/uemc/tinyid/server/service/impl
1 file changed +6
-1
lines changed Original file line number Diff line number Diff line change 10
10
import org .slf4j .LoggerFactory ;
11
11
import org .springframework .beans .factory .annotation .Autowired ;
12
12
import org .springframework .stereotype .Component ;
13
+ import org .springframework .transaction .annotation .Isolation ;
13
14
import org .springframework .transaction .annotation .Transactional ;
14
15
15
16
import java .util .concurrent .atomic .AtomicLong ;
@@ -28,12 +29,16 @@ public class DbSegmentIdServiceImpl implements SegmentIdService {
28
29
29
30
/**
30
31
* Transactional标记保证query和update使用的是同一连接
32
+ * 事务隔离级别应该为READ_COMMITTED,Spring默认是DEFAULT(取决于底层使用的数据库,mysql的默认隔离级别为REPEATABLE_READ)
33
+ * <p>
34
+ * 如果是REPEATABLE_READ,那么在本次事务中循环调用tinyIdInfoDAO.queryByBizType(bizType)获取的结果是没有变化的,也就是查询不到别的事务提交的内容
35
+ * 所以多次调用tinyIdInfoDAO.updateMaxId也就不会成功
31
36
*
32
37
* @param bizType
33
38
* @return
34
39
*/
35
40
@ Override
36
- @ Transactional
41
+ @ Transactional ( isolation = Isolation . READ_COMMITTED )
37
42
public SegmentId getNextSegmentId (String bizType ) {
38
43
// 获取nextTinyId的时候,有可能存在version冲突,需要重试
39
44
for (int i = 0 ; i < Constants .RETRY ; i ++) {
You can’t perform that action at this time.
0 commit comments