Commit 674d6973 authored by duanruiming's avatar duanruiming

[add] 事件修改逻辑添加死锁重试

parent 90f35b99
...@@ -12,6 +12,7 @@ import net.wanji.datacenter.kafka.KafkaProducerServiceHandler; ...@@ -12,6 +12,7 @@ import net.wanji.datacenter.kafka.KafkaProducerServiceHandler;
import net.wanji.datacenter.mapper.EventInfoMapper; import net.wanji.datacenter.mapper.EventInfoMapper;
import net.wanji.datacenter.pojo.dto.EventDataDTO; import net.wanji.datacenter.pojo.dto.EventDataDTO;
import net.wanji.datacenter.pojo.po.EventInfoPO; import net.wanji.datacenter.pojo.po.EventInfoPO;
import org.apache.ignite.transactions.TransactionRollbackException;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
...@@ -54,7 +55,23 @@ public class EventDataServiceImpl implements EventDataService { ...@@ -54,7 +55,23 @@ public class EventDataServiceImpl implements EventDataService {
eventInfoPO4DB.setOptStatus(1); eventInfoPO4DB.setOptStatus(1);
} }
setGreenId(crossIdGreenIdMap, eventInfoPO4DB, eventInfoPO4DB.getCrossId()); setGreenId(crossIdGreenIdMap, eventInfoPO4DB, eventInfoPO4DB.getCrossId());
int retryCount = 0;
while (retryCount < 3) {
try {
eventInfoMapper.updateOne(eventInfoPO4DB); eventInfoMapper.updateOne(eventInfoPO4DB);
return;
} catch (TransactionRollbackException e) {
retryCount++;
log.warn("检测到死锁,进行第 {} 次重试", retryCount);
try {
// 等待一会,避免立刻冲突
Thread.sleep(100);
} catch (InterruptedException ignored) {
log.warn("检测到死锁, Thread.sleep 100ms,异常:{}", ignored);
}
}
}
} else { } else {
EventInfoPO eventInfoPO = getEventInfoPO(eventDataDTO); EventInfoPO eventInfoPO = getEventInfoPO(eventDataDTO);
eventInfoMapper.insertOne(eventInfoPO); eventInfoMapper.insertOne(eventInfoPO);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment