压力测试时发现生成了相同的序号,根据日志分析发现select ... for update没有锁住某一行的数据,从而导致序号重复
public abstract class BaseController {
private ScBaseController succNext = null;
private ScBaseController failNext = null;
public DataMessage process(DataMessage msg) throws ScBaseException {
DataMessage respMsg = this.doProcess(msg);
// 执行成功
if (ExecuteResultEnum.SUCCESS.equals(respMsg.getExecuteResult())) {
if (this.succNext != null) {
return this.succNext.process(respMsg);
} else {
return respMsg;
}
}
// 执行失败
else {
if (this.failNext != null) {
return this.failNext.process(respMsg);
} else {
return respMsg;
}
}
}
@Transactional // 这里的事务注解没有作用
public abstract DataMessage doProcess(DataMessage msg);
复制代码
看过很多文章都说过不能在 同一个类 中使用没有@Transactional的方法调起有@Transactional的方法,这个是Spring动态AOP的机制决定的,必须紧记这个教训.至于为什么动态AOP会这样,后续如果写到这方面的文章再详细说明.
幸好在压力测试中发现这个问题,并没有造成线上故障.有些问题不是做几笔交易就能说明清楚,必须在高并发高压力的测试下才能验证系统的健壮性.