Skip to content

Commit

Permalink
Update CompensateServiceImpl.java
Browse files Browse the repository at this point in the history
解决issue#50那个问题,同模块同方法不同实例,在一个事务中被多次调用,补偿时提交和回滚匹配不正确。
  • Loading branch information
drakelee1221 authored Jan 24, 2018
1 parent e26082e commit 72fa2a2
Showing 1 changed file with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.codingapi.tm.model.ModelName;
import com.codingapi.tm.netty.model.TxGroup;
import com.codingapi.tm.netty.model.TxInfo;
import com.google.common.collect.Lists;
import com.lorne.core.framework.exception.ServiceException;
import com.lorne.core.framework.utils.DateUtil;
import com.lorne.core.framework.utils.encode.Base64Utils;
Expand Down Expand Up @@ -121,7 +122,7 @@ public void run() {

}


@Override
public void autoCompensate(final String compensateKey, TransactionCompensateMsg transactionCompensateMsg) {
final String json = JSON.toJSONString(transactionCompensateMsg);
logger.info("Auto Compensate->" + json);
Expand Down Expand Up @@ -258,27 +259,28 @@ public boolean delCompensate(String path) {
@Override
public void reloadCompensate(TxGroup txGroup) {
TxGroup compensateGroup = getCompensateByGroupId(txGroup.getGroupId());
if (compensateGroup != null) {
if (compensateGroup != null && compensateGroup.getList() != null && !compensateGroup.getList().isEmpty()) {
//引用集合 iterator,方便匹配后剔除列表
Iterator<TxInfo> iterator = Lists.newArrayList(compensateGroup.getList()).iterator();
for (TxInfo txInfo : txGroup.getList()) {

for (TxInfo cinfo : compensateGroup.getList()) {
while (iterator.hasNext()){
TxInfo cinfo = iterator.next();
if (cinfo.getModel().equals(txInfo.getModel()) && cinfo.getMethodStr().equals(txInfo.getMethodStr())) {

//根据之前的数据补偿现在的事务

int oldNotify = cinfo.getNotify();

if (oldNotify == 1) {
txInfo.setIsCommit(0);
} else {
txInfo.setIsCommit(1);
}
//匹配后剔除列表
iterator.remove();
break;
}
}

}
}

logger.info("Compensate Loaded->"+JSON.toJSONString(txGroup));
}

Expand Down

0 comments on commit 72fa2a2

Please sign in to comment.