Skip to content

Commit

Permalink
Adjust project directory
Browse files Browse the repository at this point in the history
  • Loading branch information
luky116 committed Jun 17, 2022
1 parent a8612de commit de61553
Show file tree
Hide file tree
Showing 28 changed files with 339 additions and 400 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ require (
github.com/fagongzi/goetty v1.3.1
github.com/fagongzi/util v0.0.0-20181102105153-fd38e0f42a4f
github.com/golang/snappy v0.0.4 // indirect
github.com/incu6us/goimports-reviser v0.1.6 // indirect
github.com/kr/pretty v0.3.0 // indirect
github.com/natefinch/lumberjack v2.0.0+incompatible
github.com/pkg/errors v0.9.1
Expand Down
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/J
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/hudl/fargo v1.3.0/go.mod h1:y3CKSmjA+wD2gak7sUSXTAoopbhU08POFhmITJgmKTg=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/incu6us/goimports-reviser v0.1.6 h1:KgSvPzI5VRnsVHBJEyIy0so+1thtYhLpLTfhloAQoiA=
github.com/incu6us/goimports-reviser v0.1.6/go.mod h1:Y85VqadcOjTzAbVLbjasX2qSxmHGaZYYOWdlIq7U28I=
github.com/influxdata/influxdb1-client v0.0.0-20191209144304-8bf82d3c094d/go.mod h1:qj24IKcXYK6Iy9ceXlo3Tc+vtHo9lIhSX5JddghvEPo=
github.com/jehiah/go-strftime v0.0.0-20171201141054-1d33003b3869/go.mod h1:cJ6Cj7dQo+O6GJNiMx+Pa94qKj+TG8ONdKHgMNIyyag=
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
Expand Down Expand Up @@ -612,6 +614,7 @@ golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtn
golang.org/x/tools v0.0.0-20200103221440-774c71fcf114/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
golang.org/x/tools v0.0.0-20200207183749-b753a1ba74fa/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
golang.org/x/tools v0.0.0-20200407143752-a3568bac92ae/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
golang.org/x/tools v0.0.0-20201014170642-d1624618ad65/go.mod h1:z6u4i615ZeAfBE4XtMziQW1fSVJXACjjbWkB/mvPzlU=
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
Expand Down
117 changes: 109 additions & 8 deletions pkg/common/error/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,118 @@

package error

import (
"github.com/pkg/errors"
import "github.com/pkg/errors"

var (
Error_TooManySessions = errors.New("too many seeessions")
Error_HeartBeatTimeOut = errors.New("heart beat time out")
)

type ErrorCode int32
type TransactionExceptionCode byte

const (
ErrorCode_IllegalState ErrorCode = 40001
)
/**
* Unknown transaction exception code.
*/
TransactionExceptionCodeUnknown TransactionExceptionCode = iota

var (
Error_TooManySessions = errors.New("too many seeessions")
Error_HeartBeatTimeOut = errors.New("heart beat time out")
/**
* BeginFailed
*/
TransactionExceptionCodeBeginFailed

/**
* Lock key conflict transaction exception code.
*/
TransactionExceptionCodeLockKeyConflict

/**
* Io transaction exception code.
*/
IO

/**
* Branch rollback failed retriable transaction exception code.
*/
TransactionExceptionCodeBranchRollbackFailedRetriable

/**
* Branch rollback failed unretriable transaction exception code.
*/
TransactionExceptionCodeBranchRollbackFailedUnretriable

/**
* Branch register failed transaction exception code.
*/
TransactionExceptionCodeBranchRegisterFailed

/**
* Branch report failed transaction exception code.
*/
TransactionExceptionCodeBranchReportFailed

/**
* Lockable check failed transaction exception code.
*/
TransactionExceptionCodeLockableCheckFailed

/**
* Branch transaction not exist transaction exception code.
*/
TransactionExceptionCodeBranchTransactionNotExist

/**
* Global transaction not exist transaction exception code.
*/
TransactionExceptionCodeGlobalTransactionNotExist

/**
* Global transaction not active transaction exception code.
*/
TransactionExceptionCodeGlobalTransactionNotActive

/**
* Global transaction status invalid transaction exception code.
*/
TransactionExceptionCodeGlobalTransactionStatusInvalid

/**
* Failed to send branch commit request transaction exception code.
*/
TransactionExceptionCodeFailedToSendBranchCommitRequest

/**
* Failed to send branch rollback request transaction exception code.
*/
TransactionExceptionCodeFailedToSendBranchRollbackRequest

/**
* Failed to add branch transaction exception code.
*/
TransactionExceptionCodeFailedToAddBranch

/**
* Failed to lock global transaction exception code.
*/
TransactionExceptionCodeFailedLockGlobalTranscation

/**
* FailedWriteSession
*/
TransactionExceptionCodeFailedWriteSession

/**
* Failed to holder exception code
*/
FailedStore
)

type TransactionException struct {
Code TransactionExceptionCode
Message string
}

//Error 隐式继承 builtin.error 接口
func (e TransactionException) Error() string {
return "TransactionException: " + e.Message
}
4 changes: 2 additions & 2 deletions pkg/protocol/codec/branch_register_response_codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ package codec

import (
"github.com/fagongzi/goetty"
error2 "github.com/seata/seata-go/pkg/common/error"
"github.com/seata/seata-go/pkg/protocol/message"
"github.com/seata/seata-go/pkg/protocol/transaction"
)

func init() {
Expand All @@ -46,7 +46,7 @@ func (g *BranchRegisterResponseCodec) Decode(in []byte) interface{} {
}

exceptionCode := ReadByte(buf)
msg.TransactionExceptionCode = transaction.TransactionExceptionCode(exceptionCode)
msg.TransactionExceptionCode = error2.TransactionExceptionCode(exceptionCode)
msg.BranchId = int64(ReadUInt64(buf))

return msg
Expand Down
4 changes: 2 additions & 2 deletions pkg/protocol/codec/branch_register_response_codec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
package codec

import (
error2 "github.com/seata/seata-go/pkg/common/error"
"testing"

"github.com/seata/seata-go/pkg/protocol/message"
"github.com/seata/seata-go/pkg/protocol/transaction"
"github.com/stretchr/testify/assert"
)

Expand All @@ -32,7 +32,7 @@ func TestBranchRegisterResponseCodec(t *testing.T) {
ResultCode: message.ResultCodeFailed,
Msg: "FAILED",
},
TransactionExceptionCode: transaction.TransactionExceptionCodeUnknown,
TransactionExceptionCode: error2.TransactionExceptionCodeUnknown,
},
BranchId: 124356567,
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/protocol/codec/common_global_end_response_codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ package codec

import (
"github.com/fagongzi/goetty"
transaction2 "github.com/seata/seata-go/pkg/common/error"
"github.com/seata/seata-go/pkg/protocol/message"
"github.com/seata/seata-go/pkg/protocol/transaction"
)

type CommonGlobalEndResponseCodec struct {
Expand Down Expand Up @@ -63,10 +63,10 @@ func (c *CommonGlobalEndResponseCodec) Decode(in []byte) interface{} {
}

exceptionCode := ReadByte(buf)
msg.TransactionExceptionCode = transaction.TransactionExceptionCode(exceptionCode)
msg.TransactionExceptionCode = transaction2.TransactionExceptionCode(exceptionCode)

globalStatus := ReadByte(buf)
msg.GlobalStatus = transaction.GlobalStatus(globalStatus)
msg.GlobalStatus = message.GlobalStatus(globalStatus)

return msg
}
4 changes: 2 additions & 2 deletions pkg/protocol/codec/global_begin_response_codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ package codec

import (
"github.com/fagongzi/goetty"
error2 "github.com/seata/seata-go/pkg/common/error"
"github.com/seata/seata-go/pkg/protocol/message"
"github.com/seata/seata-go/pkg/protocol/transaction"
)

func init() {
Expand Down Expand Up @@ -68,7 +68,7 @@ func (g *GlobalBeginResponseCodec) Decode(in []byte) interface{} {
}

exceptionCode := ReadByte(buf)
msg.TransactionExceptionCode = transaction.TransactionExceptionCode(exceptionCode)
msg.TransactionExceptionCode = error2.TransactionExceptionCode(exceptionCode)

lenth = ReadUInt16(buf)
if lenth > 0 {
Expand Down
4 changes: 2 additions & 2 deletions pkg/protocol/codec/global_begin_response_codec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
package codec

import (
error2 "github.com/seata/seata-go/pkg/common/error"
"testing"

"github.com/seata/seata-go/pkg/protocol/message"
"github.com/seata/seata-go/pkg/protocol/transaction"
"github.com/stretchr/testify/assert"
)

Expand All @@ -32,7 +32,7 @@ func TestGlobalBeginResponseCodec(t *testing.T) {
ResultCode: message.ResultCodeFailed,
Msg: "FAILED",
},
TransactionExceptionCode: transaction.TransactionExceptionCodeBeginFailed,
TransactionExceptionCode: error2.TransactionExceptionCodeBeginFailed,
},

Xid: "test-transaction-id",
Expand Down
3 changes: 1 addition & 2 deletions pkg/protocol/codec/global_commit_response_codec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"testing"

"github.com/seata/seata-go/pkg/protocol/message"
"github.com/seata/seata-go/pkg/protocol/transaction"
"github.com/stretchr/testify/assert"
)

Expand All @@ -34,7 +33,7 @@ func TestGlobalCommitResponseCodec(t *testing.T) {
Msg: "ResultCodeFailed message",
},
},
GlobalStatus: transaction.GlobalStatusCommitted,
GlobalStatus: message.GlobalStatusCommitted,
},
}

Expand Down
3 changes: 1 addition & 2 deletions pkg/protocol/codec/global_report_response_codec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"testing"

"github.com/seata/seata-go/pkg/protocol/message"
"github.com/seata/seata-go/pkg/protocol/transaction"
"github.com/stretchr/testify/assert"
)

Expand All @@ -34,7 +33,7 @@ func TestGlobalReportResponseCodec(t *testing.T) {
Msg: "ResultCodeFailed message",
},
},
GlobalStatus: transaction.GlobalStatusCommitted,
GlobalStatus: message.GlobalStatusCommitted,
},
}

Expand Down
3 changes: 1 addition & 2 deletions pkg/protocol/codec/global_rollback_response_codec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"testing"

"github.com/seata/seata-go/pkg/protocol/message"
"github.com/seata/seata-go/pkg/protocol/transaction"
"github.com/stretchr/testify/assert"
)

Expand All @@ -34,7 +33,7 @@ func TestGlobalRollbackResponseCodec(t *testing.T) {
Msg: "ResultCodeFailed message",
},
},
GlobalStatus: transaction.GlobalStatusCommitted,
GlobalStatus: message.GlobalStatusCommitted,
},
}

Expand Down
3 changes: 1 addition & 2 deletions pkg/protocol/codec/global_status_response_codec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"testing"

"github.com/seata/seata-go/pkg/protocol/message"
"github.com/seata/seata-go/pkg/protocol/transaction"
"github.com/stretchr/testify/assert"
)

Expand All @@ -34,7 +33,7 @@ func TestGlobalStatusResponseCodec(t *testing.T) {
Msg: "ResultCodeFailed message",
},
},
GlobalStatus: transaction.GlobalStatusCommitted,
GlobalStatus: message.GlobalStatusCommitted,
},
}

Expand Down
Loading

0 comments on commit de61553

Please sign in to comment.