Skip to content

Commit

Permalink
Merge pull request dtm-labs#197 from dtm-labs/alpha
Browse files Browse the repository at this point in the history
fix msg DoAndSubmit
  • Loading branch information
yedf2 authored Jan 27, 2022
2 parents 56aea32 + 7b4ca28 commit 1d3a5f4
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
14 changes: 10 additions & 4 deletions dtmcli/barrier.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
3 changes: 2 additions & 1 deletion dtmcli/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,15 @@ 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)
})
}

// 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 {
Expand Down
7 changes: 4 additions & 3 deletions dtmgrpc/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,15 @@ 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)
})
}

// 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 {
Expand All @@ -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()
Expand Down
1 change: 0 additions & 1 deletion helper/Dockerfile-release
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

0 comments on commit 1d3a5f4

Please sign in to comment.