diff --git a/dtmcli/barrier.go b/dtmcli/barrier.go index 497ab630a..a017b640f 100644 --- a/dtmcli/barrier.go +++ b/dtmcli/barrier.go @@ -81,14 +81,20 @@ func (bb *BranchBarrier) Call(tx *sql.Tx, busiCall BarrierBusiFunc) (rerr error) BranchCompensate: BranchAction, }[ti.Op] - originAffected, _ := insertBarrier(tx, ti.TransType, ti.Gid, ti.BranchID, originOp, bid, ti.Op) + originAffected, oerr := insertBarrier(tx, ti.TransType, ti.Gid, ti.BranchID, originOp, bid, ti.Op) currentAffected, rerr := insertBarrier(tx, ti.TransType, ti.Gid, ti.BranchID, ti.Op, bid, ti.Op) logger.Debugf("originAffected: %d currentAffected: %d", originAffected, currentAffected) - if (ti.Op == BranchCancel || ti.Op == BranchCompensate) && originAffected > 0 || // 这个是空补偿 - currentAffected == 0 { // 这个是重复请求或者悬挂 + if rerr == nil { + rerr = oerr + } + + if (ti.Op == BranchCancel || ti.Op == BranchCompensate) && originAffected > 0 || // null compensate + currentAffected == 0 { // repeated request or dangled request return } - rerr = busiCall(tx) + if rerr == nil { + rerr = busiCall(tx) + } return } diff --git a/dtmcli/msg.go b/dtmcli/msg.go index f590df4ef..920f26fcd 100644 --- a/dtmcli/msg.go +++ b/dtmcli/msg.go @@ -41,7 +41,7 @@ func (s *Msg) Submit() error { return dtmimp.TransCallDtm(&s.TransBase, s, "submit") } -// DoAndSubmitDB short method for Do on db type. please see Do +// DoAndSubmitDB short method for Do on db type. please see DoAndSubmit func (s *Msg) DoAndSubmitDB(queryPrepared string, db *sql.DB, busiCall BarrierBusiFunc) error { return s.DoAndSubmit(queryPrepared, func(bb *BranchBarrier) error { return bb.CallWithDB(db, busiCall) @@ -49,6 +49,7 @@ func (s *Msg) DoAndSubmitDB(queryPrepared string, db *sql.DB, busiCall BarrierBu } // DoAndSubmit one method for the entire prepare->busi->submit +// the error returned by busiCall will be returned // if busiCall return ErrFailure, then abort is called directly // if busiCall return not nil error other than ErrFailure, then DoAndSubmit will call queryPrepared to get the result func (s *Msg) DoAndSubmit(queryPrepared string, busiCall func(bb *BranchBarrier) error) error { diff --git a/dtmgrpc/msg.go b/dtmgrpc/msg.go index 2a94a5969..5805c9a78 100644 --- a/dtmgrpc/msg.go +++ b/dtmgrpc/msg.go @@ -44,7 +44,7 @@ func (s *MsgGrpc) Submit() error { return dtmgimp.DtmGrpcCall(&s.TransBase, "Submit") } -// DoAndSubmitDB short method for Do on db type. please see Do +// DoAndSubmitDB short method for Do on db type. please see DoAndSubmit func (s *MsgGrpc) DoAndSubmitDB(queryPrepared string, db *sql.DB, busiCall dtmcli.BarrierBusiFunc) error { return s.DoAndSubmit(queryPrepared, func(bb *dtmcli.BranchBarrier) error { return bb.CallWithDB(db, busiCall) @@ -52,6 +52,7 @@ func (s *MsgGrpc) DoAndSubmitDB(queryPrepared string, db *sql.DB, busiCall dtmcl } // DoAndSubmit one method for the entire prepare->busi->submit +// the error returned by busiCall will be returned // if busiCall return ErrFailure, then abort is called directly // if busiCall return not nil error other than ErrFailure, then DoAndSubmit will call queryPrepared to get the result func (s *MsgGrpc) DoAndSubmit(queryPrepared string, busiCall func(bb *dtmcli.BranchBarrier) error) error { @@ -61,11 +62,11 @@ func (s *MsgGrpc) DoAndSubmit(queryPrepared string, busiCall func(bb *dtmcli.Bra } if err == nil { errb := busiCall(bb) - if errb != nil && !errors.Is(err, dtmcli.ErrFailure) { + if errb != nil && !errors.Is(errb, dtmcli.ErrFailure) { err = dtmgimp.InvokeBranch(&s.TransBase, true, nil, queryPrepared, &[]byte{}, bb.BranchID, bb.Op) err = GrpcError2DtmError(err) } - if errors.Is(err, dtmcli.ErrFailure) || errors.Is(errb, dtmcli.ErrFailure) { + if errors.Is(errb, dtmcli.ErrFailure) || errors.Is(err, dtmcli.ErrFailure) { _ = dtmgimp.DtmGrpcCall(&s.TransBase, "Abort") } else if err == nil { err = s.Submit() diff --git a/helper/Dockerfile-release b/helper/Dockerfile-release index 2b7ed792c..2cf141af1 100644 --- a/helper/Dockerfile-release +++ b/helper/Dockerfile-release @@ -10,6 +10,5 @@ RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go build -ldflags="-s -w" FROM --platform=$TARGETPLATFORM alpine COPY --from=builder /app/dtm/dtm /app/dtm/ -ENV IS_DOCKER=1 WORKDIR /app/dtm ENTRYPOINT ["/app/dtm/dtm"]