Skip to content

Commit

Permalink
Fix: seata panic , attachment to AttachmentKey (apache#148)
Browse files Browse the repository at this point in the history
* fix: seata panic , attachment to AttachmentKey

* update: the standard of import dependency

Co-authored-by: yuefengbo <[email protected]>
  • Loading branch information
PhilYue and yuefengbo authored Jun 20, 2021
1 parent 384c872 commit d113ee8
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 50 deletions.
16 changes: 7 additions & 9 deletions seata/client/app/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,22 @@ import (
)

import (
"github.com/apache/dubbo-go-samples/seata/client/app/svc"
)

import (
_ "dubbo.apache.org/dubbo-go/v3/cluster/cluster_impl"
_ "dubbo.apache.org/dubbo-go/v3/cluster/loadbalance"
"dubbo.apache.org/dubbo-go/v3/common/logger"
_ "dubbo.apache.org/dubbo-go/v3/common/proxy/proxy_factory"
"dubbo.apache.org/dubbo-go/v3/config"
_ "dubbo.apache.org/dubbo-go/v3/filter/filter_impl"
_ "dubbo.apache.org/dubbo-go/v3/protocol/dubbo"
_ "dubbo.apache.org/dubbo-go/v3/registry/nacos"
_ "dubbo.apache.org/dubbo-go/v3/registry/protocol"
"github.com/transaction-wg/seata-golang/pkg/client"
config2 "github.com/transaction-wg/seata-golang/pkg/client/config"
"github.com/transaction-wg/seata-golang/pkg/client/tm"
)

_ "dubbo.apache.org/dubbo-go/v3/filter/filter_impl"

_ "dubbo.apache.org/dubbo-go/v3/cluster/cluster_impl"
_ "dubbo.apache.org/dubbo-go/v3/cluster/loadbalance"
_ "dubbo.apache.org/dubbo-go/v3/registry/nacos"
import (
"github.com/apache/dubbo-go-samples/seata/client/app/svc"
)

const (
Expand Down
18 changes: 9 additions & 9 deletions seata/client/app/svc/svc.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@ package svc

import (
"context"
"dubbo.apache.org/dubbo-go/v3/config"
"github.com/apache/dubbo-go-samples/seata/filter"

"errors"
)

import (
"github.com/apache/dubbo-go-samples/seata/order-svc/app/dao"
dao2 "github.com/apache/dubbo-go-samples/seata/product-svc/app/dao"
"dubbo.apache.org/dubbo-go/v3/common/constant"
"dubbo.apache.org/dubbo-go/v3/config"
context2 "github.com/transaction-wg/seata-golang/pkg/client/context"
"github.com/transaction-wg/seata-golang/pkg/client/tm"
)

import (
context2 "github.com/transaction-wg/seata-golang/pkg/client/context"
"github.com/transaction-wg/seata-golang/pkg/client/tm"
"github.com/apache/dubbo-go-samples/seata/filter"
"github.com/apache/dubbo-go-samples/seata/order-svc/app/dao"
dao2 "github.com/apache/dubbo-go-samples/seata/product-svc/app/dao"
)

type OrderSvc struct {
Expand Down Expand Up @@ -102,15 +102,15 @@ func (svc *Svc) CreateSo(ctx context.Context, rollback bool) ([]uint64, error) {
var allocateInventoryResult = &dao2.AllocateInventoryResult{}

// 通过 attachment 传递 xid
err1 := orderSvc.CreateSo(context.WithValue(ctx, "attachment", map[string]string{
err1 := orderSvc.CreateSo(context.WithValue(ctx, constant.AttachmentKey, map[string]interface{}{
filter.SEATA_XID: rootContext.GetXID(),
}), soMasters, createSoResult)
if err1 != nil {
return nil, err1
}

// 通过 attachment 传递 xid
err2 := productSvc.AllocateInventory(context.WithValue(ctx, "attachment", map[string]string{
err2 := productSvc.AllocateInventory(context.WithValue(ctx, constant.AttachmentKey, map[string]interface{}{
filter.SEATA_XID: rootContext.GetXID(),
}), reqs, allocateInventoryResult)
if err2 != nil {
Expand Down
5 changes: 1 addition & 4 deletions seata/order-svc/app/dao/dao.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,12 @@
package dao

import (
hessian "github.com/apache/dubbo-go-hessian2"
"time"
)

import (
hessian "github.com/apache/dubbo-go-hessian2"
"github.com/bwmarrin/snowflake"
)

import (
"github.com/transaction-wg/seata-golang/pkg/client/at/exec"
"github.com/transaction-wg/seata-golang/pkg/client/context"
)
Expand Down
9 changes: 5 additions & 4 deletions seata/order-svc/app/order_svc.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,21 @@ import (
)

import (
"github.com/apache/dubbo-go-samples/seata/filter"
dao2 "github.com/apache/dubbo-go-samples/seata/order-svc/app/dao"
"dubbo.apache.org/dubbo-go/v3/common/constant"
context2 "github.com/transaction-wg/seata-golang/pkg/client/context"
)

import (
context2 "github.com/transaction-wg/seata-golang/pkg/client/context"
"github.com/apache/dubbo-go-samples/seata/filter"
dao2 "github.com/apache/dubbo-go-samples/seata/order-svc/app/dao"
)

type OrderSvc struct {
dao *dao2.Dao
}

func (svc *OrderSvc) CreateSo(ctx context.Context, reqs []*dao2.SoMaster) (*dao2.CreateSoResult, error) {
attach := ctx.Value("attachment").(map[string]interface{})
attach := ctx.Value(constant.AttachmentKey).(map[string]interface{})
val := attach[filter.SEATA_XID]
xid := val.(string)

Expand Down
18 changes: 8 additions & 10 deletions seata/order-svc/app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,22 @@ import (
)

import (
dao2 "github.com/apache/dubbo-go-samples/seata/order-svc/app/dao"
)

import (
_ "dubbo.apache.org/dubbo-go/v3/cluster/cluster_impl"
_ "dubbo.apache.org/dubbo-go/v3/cluster/loadbalance"
"dubbo.apache.org/dubbo-go/v3/common/logger"
_ "dubbo.apache.org/dubbo-go/v3/common/proxy/proxy_factory"
"dubbo.apache.org/dubbo-go/v3/config"
_ "dubbo.apache.org/dubbo-go/v3/filter/filter_impl"
_ "dubbo.apache.org/dubbo-go/v3/protocol/dubbo"
_ "dubbo.apache.org/dubbo-go/v3/registry/nacos"
_ "dubbo.apache.org/dubbo-go/v3/registry/protocol"
"github.com/transaction-wg/seata-golang/pkg/client"
"github.com/transaction-wg/seata-golang/pkg/client/at/exec"
config2 "github.com/transaction-wg/seata-golang/pkg/client/config"
)

_ "dubbo.apache.org/dubbo-go/v3/common/proxy/proxy_factory"
_ "dubbo.apache.org/dubbo-go/v3/filter/filter_impl"

_ "dubbo.apache.org/dubbo-go/v3/cluster/cluster_impl"
_ "dubbo.apache.org/dubbo-go/v3/cluster/loadbalance"
_ "dubbo.apache.org/dubbo-go/v3/registry/nacos"
import (
dao2 "github.com/apache/dubbo-go-samples/seata/order-svc/app/dao"
)

const (
Expand Down
9 changes: 5 additions & 4 deletions seata/product-svc/app/product_svc.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,21 @@ import (
)

import (
"github.com/apache/dubbo-go-samples/seata/filter"
dao2 "github.com/apache/dubbo-go-samples/seata/product-svc/app/dao"
"dubbo.apache.org/dubbo-go/v3/common/constant"
context2 "github.com/transaction-wg/seata-golang/pkg/client/context"
)

import (
context2 "github.com/transaction-wg/seata-golang/pkg/client/context"
"github.com/apache/dubbo-go-samples/seata/filter"
dao2 "github.com/apache/dubbo-go-samples/seata/product-svc/app/dao"
)

type ProductSvc struct {
dao *dao2.Dao
}

func (svc *ProductSvc) AllocateInventory(ctx context.Context, reqs []*dao2.AllocateInventoryReq) (*dao2.AllocateInventoryResult, error) {
attach := ctx.Value("attachment").(map[string]interface{})
attach := ctx.Value(constant.AttachmentKey).(map[string]interface{})
val := attach[filter.SEATA_XID]
xid := val.(string)

Expand Down
18 changes: 8 additions & 10 deletions seata/product-svc/app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,22 @@ import (
)

import (
dao2 "github.com/apache/dubbo-go-samples/seata/product-svc/app/dao"
)

import (
_ "dubbo.apache.org/dubbo-go/v3/cluster/cluster_impl"
_ "dubbo.apache.org/dubbo-go/v3/cluster/loadbalance"
"dubbo.apache.org/dubbo-go/v3/common/logger"
_ "dubbo.apache.org/dubbo-go/v3/common/proxy/proxy_factory"
"dubbo.apache.org/dubbo-go/v3/config"
_ "dubbo.apache.org/dubbo-go/v3/filter/filter_impl"
_ "dubbo.apache.org/dubbo-go/v3/protocol/dubbo"
_ "dubbo.apache.org/dubbo-go/v3/registry/nacos"
_ "dubbo.apache.org/dubbo-go/v3/registry/protocol"
"github.com/transaction-wg/seata-golang/pkg/client"
"github.com/transaction-wg/seata-golang/pkg/client/at/exec"
config2 "github.com/transaction-wg/seata-golang/pkg/client/config"
)

_ "dubbo.apache.org/dubbo-go/v3/common/proxy/proxy_factory"
_ "dubbo.apache.org/dubbo-go/v3/filter/filter_impl"

_ "dubbo.apache.org/dubbo-go/v3/cluster/cluster_impl"
_ "dubbo.apache.org/dubbo-go/v3/cluster/loadbalance"
_ "dubbo.apache.org/dubbo-go/v3/registry/nacos"
import (
dao2 "github.com/apache/dubbo-go-samples/seata/product-svc/app/dao"
)

const (
Expand Down

0 comments on commit d113ee8

Please sign in to comment.