diff --git a/dtmcli/barrier.go b/dtmcli/barrier.go index f04caa6..4749256 100644 --- a/dtmcli/barrier.go +++ b/dtmcli/barrier.go @@ -1,7 +1,6 @@ package dtmcli import ( - "database/sql" "fmt" "net/url" ) @@ -76,17 +75,8 @@ func (bb *BranchBarrier) Call(tx Tx, busiCall BusiFunc) (rerr error) { originAffected, _ := insertBarrier(tx, ti.TransType, ti.Gid, ti.BranchID, originType, bid, ti.BranchType) currentAffected, rerr := insertBarrier(tx, ti.TransType, ti.Gid, ti.BranchID, ti.BranchType, bid, ti.BranchType) Logf("originAffected: %d currentAffected: %d", originAffected, currentAffected) - if (ti.BranchType == BranchCancel || ti.BranchType == BranchCompensate) && originAffected > 0 { // 这个是空补偿,返回成功 - return - } else if currentAffected == 0 { // 插入不成功 - var result sql.NullString - err := DBQueryRow(tx, "select 1 from dtm_barrier.barrier where trans_type=? and gid=? and branch_id=? and branch_type=? and barrier_id=? and reason=?", - ti.TransType, ti.Gid, ti.BranchID, ti.BranchType, bid, ti.BranchType).Scan(&result) - if err == sql.ErrNoRows { // 不是当前分支插入的,那么是cancel插入的,因此是悬挂操作,返回失败,AP收到这个返回,会尽快回滚 - rerr = ErrFailure - return - } - rerr = err //幂等和空补偿,直接返回 + if (ti.BranchType == BranchCancel || ti.BranchType == BranchCompensate) && originAffected > 0 || // 这个是空补偿 + currentAffected == 0 { // 这个是重复请求或者悬挂 return } rerr = busiCall(tx) diff --git a/test/barrier_tcc_test.go b/test/barrier_tcc_test.go index d936495..b864373 100644 --- a/test/barrier_tcc_test.go +++ b/test/barrier_tcc_test.go @@ -96,7 +96,7 @@ func tccBarrierDisorder(t *testing.T) { "branch_type": dtmcli.BranchTry, }). Post(tryURL) - assert.True(t, strings.Contains(r.String(), dtmcli.ResultFailure)) + assert.True(t, strings.Contains(r.String(), dtmcli.ResultSuccess)) // 这个是悬挂操作,为了简单起见,依旧让他返回成功 finishedChan <- "1" }() dtmcli.Logf("cron to timeout and then call cancel")