apache / apache/incubator-seata-samples

transfer-tcc-sample 子项目中 冻结金额的操作是不是多余的

Open
#615 6 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
2.4k
Forks
2k
PR merge metrics
No merged PRs in 30d

Description

```
public boolean prepareMinus(BusinessActionContext businessActionContext, final String accountNo,
final double amount) {
//分布式事务ID
final String xid = businessActionContext.getXid();

return fromDsTransactionTemplate.execute(new TransactionCallback() {

@Override
public Boolean doInTransaction(TransactionStatus status) {
try {
//校验账户余额
Account account = fromAccountDAO.getAccountForUpdate(accountNo);
if (account == null) {
throw new RuntimeException("账户不存在");
}
if (account.getAmount() - amount < 0) {
throw new RuntimeException("余额不足");
}
//冻结转账金额
double freezedAmount = account.getFreezedAmount() + amount;
account.setFreezedAmount(freezedAmount);
fromAccountDAO.updateFreezedAmount(account);
System.out.println(String
.format("prepareMinus account[%s] amount[%f], dtx transaction id: %s.", accountNo, amount,
xid));
return true;
} catch (Throwable t) {
t.printStackTrace();
status.setRollbackOnly();
return false;
}
}
});
}
```

这段代码中对FreezedAmount的操作有何意义?

Contributor guide

Open the contributing guide

Research direction

Start at the prepareMinus method shown in the issue and trace the surrounding transfer-tcc-sample TCC transaction flow, especially the account lookup and updateFreezedAmount call. Read the existing comment thread for context about FreezedAmount. Done means the purpose of the freeze operation is documented or a clearly scoped follow-up change is identified.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
distributed-systems
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.