Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix xa bug12 #561

Merged
merged 3 commits into from
May 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions pkg/datasource/sql/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ import (
"database/sql"
"database/sql/driver"
"fmt"
"github.com/seata/seata-go/pkg/util/log"
"sync"

"github.com/seata/seata-go/pkg/datasource/sql/datasource"
"github.com/seata/seata-go/pkg/datasource/sql/types"
"github.com/seata/seata-go/pkg/datasource/sql/undo"
"github.com/seata/seata-go/pkg/datasource/sql/util"
"github.com/seata/seata-go/pkg/protocol/branch"
"github.com/seata/seata-go/pkg/util/log"
)

type dbOption func(db *DBResource)
Expand Down Expand Up @@ -219,7 +219,9 @@ func (db *DBResource) ConnectionForXA(ctx context.Context, xaXid XAXid) (*XAConn
return nil, fmt.Errorf("get xa new connection failure, xid:%s, err:%v", xaXid.String(), err)
}
xaConn := &XAConn{
Conn: newDriverConn.(*Conn),
Conn: &Conn{
targetConn: newDriverConn,
},
}
return xaConn, nil
}
Expand Down
10 changes: 4 additions & 6 deletions pkg/datasource/sql/xa_resource_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,8 @@ func (xaManager *XAResourceManager) BranchCommit(ctx context.Context, branchReso
return branch.BranchStatusPhasetwoRollbackFailedUnretryable, err
}

if commitErr := connectionProxyXA.XaCommit(ctx, xaID); commitErr != nil {
err := fmt.Errorf("rollback xa, resourceId: %s", branchResource.ResourceId)
log.Errorf(err.Error())
if err := connectionProxyXA.XaCommit(ctx, xaID); err != nil {
log.Errorf("commit xa, resourceId: %s, err %v", branchResource.ResourceId, err)
setBranchStatus(xaID.String(), branch.BranchStatusPhasetwoCommitted)
return branch.BranchStatusPhasetwoCommitFailedUnretryable, err
}
Expand All @@ -185,9 +184,8 @@ func (xaManager *XAResourceManager) BranchRollback(ctx context.Context, branchRe
return branch.BranchStatusPhasetwoRollbackFailedUnretryable, err
}

if rollbackErr := connectionProxyXA.XaRollbackByBranchId(ctx, xaID); rollbackErr != nil {
err := fmt.Errorf("rollback xa, resourceId: %s", branchResource.ResourceId)
log.Errorf(err.Error())
if err = connectionProxyXA.XaRollbackByBranchId(ctx, xaID); err != nil {
log.Errorf("rollback xa, resourceId: %s, err %v", branchResource.ResourceId, err)
setBranchStatus(xaID.String(), branch.BranchStatusPhasetwoRollbacked)
return branch.BranchStatusPhasetwoRollbackFailedUnretryable, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (f *rmBranchCommitProcessor) Process(ctx context.Context, rpcMessage messag
branchID := request.BranchId
resourceID := request.ResourceId
applicationData := request.ApplicationData
log.Infof("Branch committing: xid %s, branchID %s, resourceID %s, applicationData %s", xid, branchID, resourceID, applicationData)
log.Infof("Branch committing: xid %s, branchID %d, resourceID %s, applicationData %s", xid, branchID, resourceID, applicationData)
branchResource := rm.BranchResource{
ResourceId: resourceID,
BranchId: branchID,
Expand Down
3 changes: 2 additions & 1 deletion pkg/tm/transaction_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,11 @@ func WithGlobalTx(ctx context.Context, gc *GtxConfig, business CallbackWithCtx)

defer func() {
var err error
deferErr := recover()
// no need to do second phase if propagation is some type e.g. NotSupported.
if IsGlobalTx(ctx) {
// business maybe to throw panic, so need to recover it here.
if err = commitOrRollback(ctx, recover() == nil && re == nil); err != nil {
if err = commitOrRollback(ctx, deferErr == nil && re == nil); err != nil {
log.Errorf("global transaction xid %s, name %s second phase error", GetXID(ctx), GetTxName(ctx), err)
}
}
Expand Down