diff --git a/client/README.md b/client/README.md new file mode 100644 index 0000000..4ab597e --- /dev/null +++ b/client/README.md @@ -0,0 +1,31 @@ +# Go Client for DTM + +There are there packages: + +## workflow +Workflow is a new client for DTM. It support the mixed usage of patterns saga, tcc, xa. And it also support the mixed usage of http, grpc and local transactions. + +This pattern offers maximum flexibility and can handle a wide range of scenarios. This pattern is highly recommended for transactions that need to be rolled back + +Quick start for workflow using http can be found here: [https://github.com/dtm-labs/quick-start-sample/tree/main/workflow-http](https://github.com/dtm-labs/quick-start-sample/tree/main/workflow-http) + +Quick start for workflow using grpc can be found here: [https://github.com/dtm-labs/quick-start-sample/tree/main/workflow-grpc](https://github.com/dtm-labs/quick-start-sample/tree/main/workflow-grpc) + +Detailed examples can be found here: [https://github.com/dtm-labs/dtm-examples](https://github.com/dtm-labs/dtm-examples) + + +## dtmcli +dtmcli is the http client for patterns: saga, tcc, msg, xa + +Quick start for dtmcli can be found here: [https://github.com/dtm-labs/quick-start-sample/tree/main/dtmcli-qs](https://github.com/dtm-labs/quick-start-sample/tree/main/dtmcli-qs) + +Detailed examples can be found here: [https://github.com/dtm-labs/dtm-examples](https://github.com/dtm-labs/dtm-examples) + +## dtmgrpc +dtmcli is the grpc client for patterns: saga, tcc, msg, xa + +Quick start for dtmgrpc can be found here: [https://github.com/dtm-labs/quick-start-sample/tree/main/dtmgrpc-qs](https://github.com/dtm-labs/quick-start-sample/tree/main/dtmgrpc-qs) + +Detailed examples can be found here: [https://github.com/dtm-labs/dtm-examples](https://github.com/dtm-labs/dtm-examples) + + diff --git a/dtmcli/barrier.go b/client/dtmcli/barrier.go similarity index 90% rename from dtmcli/barrier.go rename to client/dtmcli/barrier.go index 0b136cb..7c1224d 100644 --- a/dtmcli/barrier.go +++ b/client/dtmcli/barrier.go @@ -11,8 +11,8 @@ import ( "fmt" "net/url" - "github.com/dtm-labs/dtm/dtmcli/dtmimp" - "github.com/dtm-labs/dtm/dtmcli/logger" + "github.com/dtm-labs/dtm/client/dtmcli/dtmimp" + "github.com/dtm-labs/dtm/client/dtmcli/logger" ) // BarrierBusiFunc type for busi func @@ -68,8 +68,9 @@ func (bb *BranchBarrier) Call(tx *sql.Tx, busiCall BarrierBusiFunc) (rerr error) return tx.Rollback() }) originOp := map[string]string{ - dtmimp.OpCancel: dtmimp.OpTry, - dtmimp.OpCompensate: dtmimp.OpAction, + dtmimp.OpCancel: dtmimp.OpTry, // tcc + dtmimp.OpCompensate: dtmimp.OpAction, // saga + dtmimp.OpRollback: dtmimp.OpAction, // workflow }[bb.Op] originAffected, oerr := dtmimp.InsertBarrier(tx, bb.TransType, bb.Gid, bb.BranchID, originOp, bid, bb.Op, bb.DBType, bb.BarrierTableName) @@ -84,7 +85,7 @@ func (bb *BranchBarrier) Call(tx *sql.Tx, busiCall BarrierBusiFunc) (rerr error) rerr = oerr } - if (bb.Op == dtmimp.OpCancel || bb.Op == dtmimp.OpCompensate) && originAffected > 0 || // null compensate + if (bb.Op == dtmimp.OpCancel || bb.Op == dtmimp.OpCompensate || bb.Op == dtmimp.OpRollback) && originAffected > 0 || // null compensate currentAffected == 0 { // repeated request or dangled request return } diff --git a/dtmcli/barrier_mongo.go b/client/dtmcli/barrier_mongo.go similarity index 97% rename from dtmcli/barrier_mongo.go rename to client/dtmcli/barrier_mongo.go index d6c7f9b..b2d2668 100644 --- a/dtmcli/barrier_mongo.go +++ b/client/dtmcli/barrier_mongo.go @@ -4,8 +4,8 @@ import ( "context" "strings" - "github.com/dtm-labs/dtm/dtmcli/dtmimp" - "github.com/dtm-labs/dtm/dtmcli/logger" + "github.com/dtm-labs/dtm/client/dtmcli/dtmimp" + "github.com/dtm-labs/dtm/client/dtmcli/logger" "go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/mongo" ) diff --git a/dtmcli/barrier_redis.go b/client/dtmcli/barrier_redis.go similarity index 95% rename from dtmcli/barrier_redis.go rename to client/dtmcli/barrier_redis.go index cef1b39..62aeeb9 100644 --- a/dtmcli/barrier_redis.go +++ b/client/dtmcli/barrier_redis.go @@ -3,8 +3,8 @@ package dtmcli import ( "fmt" - "github.com/dtm-labs/dtm/dtmcli/dtmimp" - "github.com/dtm-labs/dtm/dtmcli/logger" + "github.com/dtm-labs/dtm/client/dtmcli/dtmimp" + "github.com/dtm-labs/dtm/client/dtmcli/logger" "github.com/go-redis/redis/v8" ) diff --git a/dtmcli/consts.go b/client/dtmcli/consts.go similarity index 97% rename from dtmcli/consts.go rename to client/dtmcli/consts.go index fad9776..7ae4fc6 100644 --- a/dtmcli/consts.go +++ b/client/dtmcli/consts.go @@ -7,7 +7,7 @@ package dtmcli import ( - "github.com/dtm-labs/dtm/dtmcli/dtmimp" + "github.com/dtm-labs/dtm/client/dtmcli/dtmimp" ) const ( diff --git a/dtmcli/cover_test.go b/client/dtmcli/cover_test.go similarity index 100% rename from dtmcli/cover_test.go rename to client/dtmcli/cover_test.go diff --git a/dtmcli/dtmimp/README-cn.md b/client/dtmcli/dtmimp/README-cn.md similarity index 100% rename from dtmcli/dtmimp/README-cn.md rename to client/dtmcli/dtmimp/README-cn.md diff --git a/dtmcli/dtmimp/README.md b/client/dtmcli/dtmimp/README.md similarity index 100% rename from dtmcli/dtmimp/README.md rename to client/dtmcli/dtmimp/README.md diff --git a/dtmcli/dtmimp/consts.go b/client/dtmcli/dtmimp/consts.go similarity index 100% rename from dtmcli/dtmimp/consts.go rename to client/dtmcli/dtmimp/consts.go diff --git a/dtmcli/dtmimp/db_special.go b/client/dtmcli/dtmimp/db_special.go similarity index 100% rename from dtmcli/dtmimp/db_special.go rename to client/dtmcli/dtmimp/db_special.go diff --git a/dtmcli/dtmimp/db_special_test.go b/client/dtmcli/dtmimp/db_special_test.go similarity index 100% rename from dtmcli/dtmimp/db_special_test.go rename to client/dtmcli/dtmimp/db_special_test.go diff --git a/dtmcli/dtmimp/trans_base.go b/client/dtmcli/dtmimp/trans_base.go similarity index 99% rename from dtmcli/dtmimp/trans_base.go rename to client/dtmcli/dtmimp/trans_base.go index ea2db34..16ecbd8 100644 --- a/dtmcli/dtmimp/trans_base.go +++ b/client/dtmcli/dtmimp/trans_base.go @@ -152,9 +152,6 @@ func TransRequestBranch(t *TransBase, method string, body interface{}, branchID SetQueryParams(query). SetHeaders(t.BranchHeaders). Execute(method, url) - if err == nil { - err = RespAsErrorCompatible(resp) - } return resp, err } diff --git a/dtmcli/dtmimp/trans_xa_base.go b/client/dtmcli/dtmimp/trans_xa_base.go similarity index 98% rename from dtmcli/dtmimp/trans_xa_base.go rename to client/dtmcli/dtmimp/trans_xa_base.go index 6eedb31..d936b6a 100644 --- a/dtmcli/dtmimp/trans_xa_base.go +++ b/client/dtmcli/dtmimp/trans_xa_base.go @@ -37,7 +37,7 @@ func XaHandleLocalTrans(xa *TransBase, dbConf DBConf, cb func(*sql.DB) error) (r if rerr != nil { return } - defer func() { _ = db.Close() }() + defer XaClose(db) defer DeferDo(&rerr, func() error { _, err := DBExec(dbConf.Driver, db, GetDBSpecial(dbConf.Driver).GetXaSQL("prepare", xaBranch)) return err diff --git a/dtmcli/dtmimp/types.go b/client/dtmcli/dtmimp/types.go similarity index 100% rename from dtmcli/dtmimp/types.go rename to client/dtmcli/dtmimp/types.go diff --git a/dtmcli/dtmimp/types_test.go b/client/dtmcli/dtmimp/types_test.go similarity index 100% rename from dtmcli/dtmimp/types_test.go rename to client/dtmcli/dtmimp/types_test.go diff --git a/dtmcli/dtmimp/utils.go b/client/dtmcli/dtmimp/utils.go similarity index 90% rename from dtmcli/dtmimp/utils.go rename to client/dtmcli/dtmimp/utils.go index 386d834..a857c5f 100644 --- a/dtmcli/dtmimp/utils.go +++ b/client/dtmcli/dtmimp/utils.go @@ -11,7 +11,6 @@ import ( "encoding/json" "errors" "fmt" - "net/http" "net/url" "os" "runtime" @@ -20,7 +19,7 @@ import ( "sync" "time" - "github.com/dtm-labs/dtm/dtmcli/logger" + "github.com/dtm-labs/dtm/client/dtmcli/logger" "github.com/go-resty/resty/v2" ) @@ -182,10 +181,16 @@ func XaDB(conf DBConf) (*sql.DB, error) { if conf.Driver == DBTypeMysql { dsn += "&autocommit=0" } - logger.Infof("opening standalone %s: %s", conf.Driver, strings.Replace(dsn, conf.Password, "****", 1)) + logger.Infof("opening xa standalone %s: %s", conf.Driver, strings.Replace(dsn, conf.Password, "****", 1)) return sql.Open(conf.Driver, dsn) } +// XaClose will log and close the db +func XaClose(db *sql.DB) { + logger.Infof("closing xa db") + _ = db.Close() +} + // DBExec use raw db to exec func DBExec(dbType string, db DB, sql string, values ...interface{}) (affected int64, rerr error) { if sql == "" { @@ -218,21 +223,6 @@ func GetDsn(conf DBConf) string { return dsn } -// RespAsErrorCompatible translate a resty response to error -// compatible with version < v1.10 -func RespAsErrorCompatible(resp *resty.Response) error { - code := resp.StatusCode() - str := resp.String() - if code == http.StatusTooEarly || strings.Contains(str, ResultOngoing) { - return fmt.Errorf("%s. %w", str, ErrOngoing) - } else if code == http.StatusConflict || strings.Contains(str, ResultFailure) { - return fmt.Errorf("%s. %w", str, ErrFailure) - } else if code != http.StatusOK { - return errors.New(str) - } - return nil -} - // RespAsErrorByJSONRPC translate json rpc resty response to error func RespAsErrorByJSONRPC(resp *resty.Response) error { str := resp.String() diff --git a/dtmcli/dtmimp/utils_test.go b/client/dtmcli/dtmimp/utils_test.go similarity index 100% rename from dtmcli/dtmimp/utils_test.go rename to client/dtmcli/dtmimp/utils_test.go diff --git a/dtmcli/dtmimp/vars.go b/client/dtmcli/dtmimp/vars.go similarity index 93% rename from dtmcli/dtmimp/vars.go rename to client/dtmcli/dtmimp/vars.go index 4110177..a34d29f 100644 --- a/dtmcli/dtmimp/vars.go +++ b/client/dtmcli/dtmimp/vars.go @@ -9,7 +9,7 @@ package dtmimp import ( "errors" - "github.com/dtm-labs/dtm/dtmcli/logger" + "github.com/dtm-labs/dtm/client/dtmcli/logger" "github.com/dtm-labs/dtmdriver" "github.com/go-resty/resty/v2" ) @@ -24,9 +24,6 @@ var ErrOngoing = errors.New("ONGOING") // if QueryPrepared executed before call. then DoAndSubmit return this error var ErrDuplicated = errors.New("DUPLICATED") -// XaSQLTimeoutMs milliseconds for Xa sql to timeout -var XaSQLTimeoutMs = 15000 - // MapSuccess HTTP result of SUCCESS var MapSuccess = map[string]interface{}{"dtm_result": ResultSuccess} diff --git a/dtmcli/logger/log.go b/client/dtmcli/logger/log.go similarity index 100% rename from dtmcli/logger/log.go rename to client/dtmcli/logger/log.go diff --git a/dtmcli/logger/logger_test.go b/client/dtmcli/logger/logger_test.go similarity index 86% rename from dtmcli/logger/logger_test.go rename to client/dtmcli/logger/logger_test.go index d55b6d6..e69ef02 100644 --- a/dtmcli/logger/logger_test.go +++ b/client/dtmcli/logger/logger_test.go @@ -4,6 +4,7 @@ import ( "os" "testing" + "github.com/stretchr/testify/assert" "go.uber.org/zap" ) @@ -37,3 +38,9 @@ func TestWithLogger(t *testing.T) { FatalfIf(false, "nothing") FatalIfError(nil) } + +func TestCover(t *testing.T) { + sin := lumberjackSink{} + err := sin.Sync() + assert.Nil(t, err) +} diff --git a/dtmcli/trans_msg.go b/client/dtmcli/trans_msg.go similarity index 94% rename from dtmcli/trans_msg.go rename to client/dtmcli/trans_msg.go index 95f5bd1..ee92fbf 100644 --- a/dtmcli/trans_msg.go +++ b/client/dtmcli/trans_msg.go @@ -10,7 +10,7 @@ import ( "database/sql" "errors" - "github.com/dtm-labs/dtm/dtmcli/dtmimp" + "github.com/dtm-labs/dtm/client/dtmcli/dtmimp" ) // Msg reliable msg type @@ -69,7 +69,7 @@ func (s *Msg) DoAndSubmit(queryPrepared string, busiCall func(bb *BranchBarrier) errb := busiCall(bb) if errb != nil && !errors.Is(errb, ErrFailure) { // if busicall return an error other than failure, we will query the result - _, err = dtmimp.TransRequestBranch(&s.TransBase, "GET", nil, bb.BranchID, bb.Op, queryPrepared) + _, err = requestBranch(&s.TransBase, "GET", nil, bb.BranchID, bb.Op, queryPrepared) } if errors.Is(errb, ErrFailure) || errors.Is(err, ErrFailure) { _ = dtmimp.TransCallDtm(&s.TransBase, "abort") diff --git a/dtmcli/trans_saga.go b/client/dtmcli/trans_saga.go similarity index 96% rename from dtmcli/trans_saga.go rename to client/dtmcli/trans_saga.go index 4067d7a..04c8124 100644 --- a/dtmcli/trans_saga.go +++ b/client/dtmcli/trans_saga.go @@ -7,7 +7,7 @@ package dtmcli import ( - "github.com/dtm-labs/dtm/dtmcli/dtmimp" + "github.com/dtm-labs/dtm/client/dtmcli/dtmimp" ) // Saga struct of saga diff --git a/dtmcli/trans_tcc.go b/client/dtmcli/trans_tcc.go similarity index 93% rename from dtmcli/trans_tcc.go rename to client/dtmcli/trans_tcc.go index 64ea0e3..2c6cc72 100644 --- a/dtmcli/trans_tcc.go +++ b/client/dtmcli/trans_tcc.go @@ -10,7 +10,7 @@ import ( "fmt" "net/url" - "github.com/dtm-labs/dtm/dtmcli/dtmimp" + "github.com/dtm-labs/dtm/client/dtmcli/dtmimp" "github.com/go-resty/resty/v2" ) @@ -71,5 +71,5 @@ func (t *Tcc) CallBranch(body interface{}, tryURL string, confirmURL string, can if err != nil { return nil, err } - return dtmimp.TransRequestBranch(&t.TransBase, "POST", body, branchID, dtmimp.OpTry, tryURL) + return requestBranch(&t.TransBase, "POST", body, branchID, dtmimp.OpTry, tryURL) } diff --git a/dtmcli/types.go b/client/dtmcli/types.go similarity index 82% rename from dtmcli/types.go rename to client/dtmcli/types.go index c81abbe..be7fda1 100644 --- a/dtmcli/types.go +++ b/client/dtmcli/types.go @@ -7,7 +7,7 @@ package dtmcli import ( - "github.com/dtm-labs/dtm/dtmcli/dtmimp" + "github.com/dtm-labs/dtm/client/dtmcli/dtmimp" "github.com/go-resty/resty/v2" ) @@ -30,16 +30,6 @@ func GetCurrentDBType() string { return dtmimp.GetCurrentDBType() } -// SetXaSQLTimeoutMs set XaSQLTimeoutMs -func SetXaSQLTimeoutMs(ms int) { - dtmimp.XaSQLTimeoutMs = ms -} - -// GetXaSQLTimeoutMs get XaSQLTimeoutMs -func GetXaSQLTimeoutMs() int { - return dtmimp.XaSQLTimeoutMs -} - // SetBarrierTableName sets barrier table name func SetBarrierTableName(tablename string) { dtmimp.BarrierTableName = tablename diff --git a/dtmcli/types_test.go b/client/dtmcli/types_test.go similarity index 86% rename from dtmcli/types_test.go rename to client/dtmcli/types_test.go index 213d9a3..f7c27b3 100644 --- a/dtmcli/types_test.go +++ b/client/dtmcli/types_test.go @@ -10,7 +10,7 @@ import ( "net/url" "testing" - "github.com/dtm-labs/dtm/dtmcli/dtmimp" + "github.com/dtm-labs/dtm/client/dtmcli/dtmimp" "github.com/stretchr/testify/assert" ) @@ -26,7 +26,5 @@ func TestTypes(t *testing.T) { } func TestXaSqlTimeout(t *testing.T) { - old := GetXaSQLTimeoutMs() - SetXaSQLTimeoutMs(old) SetBarrierTableName(dtmimp.BarrierTableName) // just cover this func } diff --git a/client/dtmcli/utils.go b/client/dtmcli/utils.go new file mode 100644 index 0000000..983edd7 --- /dev/null +++ b/client/dtmcli/utils.go @@ -0,0 +1,74 @@ +package dtmcli + +import ( + "errors" + "fmt" + "net/http" + "strings" + + "github.com/dtm-labs/dtm/client/dtmcli/dtmimp" + "github.com/go-resty/resty/v2" +) + +// MustGenGid generate a new gid +func MustGenGid(server string) string { + res := map[string]string{} + resp, err := dtmimp.RestyClient.R().SetResult(&res).Get(server + "/newGid") + if err != nil || res["gid"] == "" { + panic(fmt.Errorf("newGid error: %v, resp: %s", err, resp)) + } + return res["gid"] +} + +// ErrorMessage2Error return an error fmt.Errorf("%s %w", errMsg, err) but trim out duplicate wrap +// eg. ErrorMessage2Error("an error. FAILURE", ErrFailure) return an error with message: "an error. FAILURE", +// no additional " FAILURE" added +func ErrorMessage2Error(errMsg string, err error) error { + errMsg = strings.TrimSuffix(errMsg, " "+err.Error()) + return fmt.Errorf("%s %w", errMsg, err) +} + +// HTTPResp2DtmError translate a resty response to error +// compatible with version < v1.10 +func HTTPResp2DtmError(resp *resty.Response) error { + code := resp.StatusCode() + str := resp.String() + if code == http.StatusTooEarly || strings.Contains(str, ResultOngoing) { + return ErrorMessage2Error(str, ErrOngoing) + } else if code == http.StatusConflict || strings.Contains(str, ResultFailure) { + return ErrorMessage2Error(str, ErrFailure) + } else if code != http.StatusOK { + return errors.New(str) + } + return nil +} + +// Result2HttpJSON return the http code and json result +// if result is error, the return proper code, else return StatusOK +func Result2HttpJSON(result interface{}) (code int, res interface{}) { + err, _ := result.(error) + if err == nil { + code = http.StatusOK + res = result + } else { + res = map[string]string{ + "error": err.Error(), + } + if errors.Is(err, ErrFailure) { + code = http.StatusConflict + } else if errors.Is(err, ErrOngoing) { + code = http.StatusTooEarly + } else if err != nil { + code = http.StatusInternalServerError + } + } + return +} + +func requestBranch(t *dtmimp.TransBase, method string, body interface{}, branchID string, op string, url string) (*resty.Response, error) { + resp, err := dtmimp.TransRequestBranch(t, method, body, branchID, op, url) + if err == nil { + err = HTTPResp2DtmError(resp) + } + return resp, err +} diff --git a/dtmcli/xa.go b/client/dtmcli/xa.go similarity index 94% rename from dtmcli/xa.go rename to client/dtmcli/xa.go index e38b967..251fe4b 100644 --- a/dtmcli/xa.go +++ b/client/dtmcli/xa.go @@ -11,7 +11,7 @@ import ( "fmt" "net/url" - "github.com/dtm-labs/dtm/dtmcli/dtmimp" + "github.com/dtm-labs/dtm/client/dtmcli/dtmimp" "github.com/go-resty/resty/v2" ) @@ -79,5 +79,5 @@ func XaGlobalTransaction2(server string, gid string, custom func(*Xa), xaFunc Xa // CallBranch call a xa branch func (x *Xa) CallBranch(body interface{}, url string) (*resty.Response, error) { branchID := x.NewSubBranchID() - return dtmimp.TransRequestBranch(&x.TransBase, "POST", body, branchID, dtmimp.OpAction, url) + return requestBranch(&x.TransBase, "POST", body, branchID, dtmimp.OpAction, url) } diff --git a/dtmgrpc/barrier.go b/client/dtmgrpc/barrier.go similarity index 82% rename from dtmgrpc/barrier.go rename to client/dtmgrpc/barrier.go index 973c14a..b21d811 100644 --- a/dtmgrpc/barrier.go +++ b/client/dtmgrpc/barrier.go @@ -9,8 +9,8 @@ package dtmgrpc import ( "context" - "github.com/dtm-labs/dtm/dtmcli" - "github.com/dtm-labs/dtm/dtmgrpc/dtmgimp" + "github.com/dtm-labs/dtm/client/dtmcli" + "github.com/dtm-labs/dtm/client/dtmgrpc/dtmgimp" ) // BarrierFromGrpc generate a Barrier from grpc context diff --git a/dtmgrpc/dtmgimp/README-cn.md b/client/dtmgrpc/dtmgimp/README-cn.md similarity index 100% rename from dtmgrpc/dtmgimp/README-cn.md rename to client/dtmgrpc/dtmgimp/README-cn.md diff --git a/dtmgrpc/dtmgimp/README.md b/client/dtmgrpc/dtmgimp/README.md similarity index 100% rename from dtmgrpc/dtmgimp/README.md rename to client/dtmgrpc/dtmgimp/README.md diff --git a/dtmgrpc/dtmgimp/grpc_clients.go b/client/dtmgrpc/dtmgimp/grpc_clients.go similarity index 93% rename from dtmgrpc/dtmgimp/grpc_clients.go rename to client/dtmgrpc/dtmgimp/grpc_clients.go index dc98848..109785a 100644 --- a/dtmgrpc/dtmgimp/grpc_clients.go +++ b/client/dtmgrpc/dtmgimp/grpc_clients.go @@ -10,9 +10,9 @@ import ( "fmt" "sync" - "github.com/dtm-labs/dtm/dtmcli/dtmimp" - "github.com/dtm-labs/dtm/dtmcli/logger" - "github.com/dtm-labs/dtm/dtmgrpc/dtmgpb" + "github.com/dtm-labs/dtm/client/dtmcli/dtmimp" + "github.com/dtm-labs/dtm/client/dtmcli/logger" + "github.com/dtm-labs/dtm/client/dtmgrpc/dtmgpb" grpc "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" ) diff --git a/dtmgrpc/dtmgimp/types.go b/client/dtmgrpc/dtmgimp/types.go similarity index 96% rename from dtmgrpc/dtmgimp/types.go rename to client/dtmgrpc/dtmgimp/types.go index 34059c8..929dc1f 100644 --- a/dtmgrpc/dtmgimp/types.go +++ b/client/dtmgrpc/dtmgimp/types.go @@ -11,8 +11,8 @@ import ( "fmt" "time" - "github.com/dtm-labs/dtm/dtmcli/dtmimp" - "github.com/dtm-labs/dtm/dtmcli/logger" + "github.com/dtm-labs/dtm/client/dtmcli/dtmimp" + "github.com/dtm-labs/dtm/client/dtmcli/logger" "github.com/dtm-labs/dtmdriver" "google.golang.org/grpc" "google.golang.org/grpc/codes" diff --git a/dtmgrpc/dtmgimp/utils.go b/client/dtmgrpc/dtmgimp/utils.go similarity index 96% rename from dtmgrpc/dtmgimp/utils.go rename to client/dtmgrpc/dtmgimp/utils.go index 2bdb715..44fc76f 100644 --- a/dtmgrpc/dtmgimp/utils.go +++ b/client/dtmgrpc/dtmgimp/utils.go @@ -9,9 +9,9 @@ package dtmgimp import ( context "context" - "github.com/dtm-labs/dtm/dtmcli/dtmimp" - "github.com/dtm-labs/dtm/dtmcli/logger" - "github.com/dtm-labs/dtm/dtmgrpc/dtmgpb" + "github.com/dtm-labs/dtm/client/dtmcli/dtmimp" + "github.com/dtm-labs/dtm/client/dtmcli/logger" + "github.com/dtm-labs/dtm/client/dtmgrpc/dtmgpb" "google.golang.org/grpc/metadata" "google.golang.org/protobuf/proto" emptypb "google.golang.org/protobuf/types/known/emptypb" diff --git a/client/dtmgrpc/dtmgpb/dtmgimp.pb.go b/client/dtmgrpc/dtmgpb/dtmgimp.pb.go new file mode 100644 index 0000000..6b7a547 --- /dev/null +++ b/client/dtmgrpc/dtmgpb/dtmgimp.pb.go @@ -0,0 +1,831 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.28.0 +// protoc v3.17.3 +// source: client/dtmgrpc/dtmgpb/dtmgimp.proto + +package dtmgpb + +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + emptypb "google.golang.org/protobuf/types/known/emptypb" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type DtmTransOptions struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + WaitResult bool `protobuf:"varint,1,opt,name=WaitResult,proto3" json:"WaitResult,omitempty"` + TimeoutToFail int64 `protobuf:"varint,2,opt,name=TimeoutToFail,proto3" json:"TimeoutToFail,omitempty"` + RetryInterval int64 `protobuf:"varint,3,opt,name=RetryInterval,proto3" json:"RetryInterval,omitempty"` + PassthroughHeaders []string `protobuf:"bytes,4,rep,name=PassthroughHeaders,proto3" json:"PassthroughHeaders,omitempty"` + BranchHeaders map[string]string `protobuf:"bytes,5,rep,name=BranchHeaders,proto3" json:"BranchHeaders,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` + RequestTimeout int64 `protobuf:"varint,6,opt,name=RequestTimeout,proto3" json:"RequestTimeout,omitempty"` +} + +func (x *DtmTransOptions) Reset() { + *x = DtmTransOptions{} + if protoimpl.UnsafeEnabled { + mi := &file_client_dtmgrpc_dtmgpb_dtmgimp_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *DtmTransOptions) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*DtmTransOptions) ProtoMessage() {} + +func (x *DtmTransOptions) ProtoReflect() protoreflect.Message { + mi := &file_client_dtmgrpc_dtmgpb_dtmgimp_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use DtmTransOptions.ProtoReflect.Descriptor instead. +func (*DtmTransOptions) Descriptor() ([]byte, []int) { + return file_client_dtmgrpc_dtmgpb_dtmgimp_proto_rawDescGZIP(), []int{0} +} + +func (x *DtmTransOptions) GetWaitResult() bool { + if x != nil { + return x.WaitResult + } + return false +} + +func (x *DtmTransOptions) GetTimeoutToFail() int64 { + if x != nil { + return x.TimeoutToFail + } + return 0 +} + +func (x *DtmTransOptions) GetRetryInterval() int64 { + if x != nil { + return x.RetryInterval + } + return 0 +} + +func (x *DtmTransOptions) GetPassthroughHeaders() []string { + if x != nil { + return x.PassthroughHeaders + } + return nil +} + +func (x *DtmTransOptions) GetBranchHeaders() map[string]string { + if x != nil { + return x.BranchHeaders + } + return nil +} + +func (x *DtmTransOptions) GetRequestTimeout() int64 { + if x != nil { + return x.RequestTimeout + } + return 0 +} + +// DtmRequest request sent to dtm server +type DtmRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Gid string `protobuf:"bytes,1,opt,name=Gid,proto3" json:"Gid,omitempty"` + TransType string `protobuf:"bytes,2,opt,name=TransType,proto3" json:"TransType,omitempty"` + TransOptions *DtmTransOptions `protobuf:"bytes,3,opt,name=TransOptions,proto3" json:"TransOptions,omitempty"` + CustomedData string `protobuf:"bytes,4,opt,name=CustomedData,proto3" json:"CustomedData,omitempty"` + BinPayloads [][]byte `protobuf:"bytes,5,rep,name=BinPayloads,proto3" json:"BinPayloads,omitempty"` // for Msg/Saga/Workflow branch payloads + QueryPrepared string `protobuf:"bytes,6,opt,name=QueryPrepared,proto3" json:"QueryPrepared,omitempty"` // for Msg + Steps string `protobuf:"bytes,7,opt,name=Steps,proto3" json:"Steps,omitempty"` + ReqExtra map[string]string `protobuf:"bytes,8,rep,name=ReqExtra,proto3" json:"ReqExtra,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` + RollbackReason string `protobuf:"bytes,9,opt,name=RollbackReason,proto3" json:"RollbackReason,omitempty"` +} + +func (x *DtmRequest) Reset() { + *x = DtmRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_client_dtmgrpc_dtmgpb_dtmgimp_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *DtmRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*DtmRequest) ProtoMessage() {} + +func (x *DtmRequest) ProtoReflect() protoreflect.Message { + mi := &file_client_dtmgrpc_dtmgpb_dtmgimp_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use DtmRequest.ProtoReflect.Descriptor instead. +func (*DtmRequest) Descriptor() ([]byte, []int) { + return file_client_dtmgrpc_dtmgpb_dtmgimp_proto_rawDescGZIP(), []int{1} +} + +func (x *DtmRequest) GetGid() string { + if x != nil { + return x.Gid + } + return "" +} + +func (x *DtmRequest) GetTransType() string { + if x != nil { + return x.TransType + } + return "" +} + +func (x *DtmRequest) GetTransOptions() *DtmTransOptions { + if x != nil { + return x.TransOptions + } + return nil +} + +func (x *DtmRequest) GetCustomedData() string { + if x != nil { + return x.CustomedData + } + return "" +} + +func (x *DtmRequest) GetBinPayloads() [][]byte { + if x != nil { + return x.BinPayloads + } + return nil +} + +func (x *DtmRequest) GetQueryPrepared() string { + if x != nil { + return x.QueryPrepared + } + return "" +} + +func (x *DtmRequest) GetSteps() string { + if x != nil { + return x.Steps + } + return "" +} + +func (x *DtmRequest) GetReqExtra() map[string]string { + if x != nil { + return x.ReqExtra + } + return nil +} + +func (x *DtmRequest) GetRollbackReason() string { + if x != nil { + return x.RollbackReason + } + return "" +} + +type DtmGidReply struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Gid string `protobuf:"bytes,1,opt,name=Gid,proto3" json:"Gid,omitempty"` +} + +func (x *DtmGidReply) Reset() { + *x = DtmGidReply{} + if protoimpl.UnsafeEnabled { + mi := &file_client_dtmgrpc_dtmgpb_dtmgimp_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *DtmGidReply) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*DtmGidReply) ProtoMessage() {} + +func (x *DtmGidReply) ProtoReflect() protoreflect.Message { + mi := &file_client_dtmgrpc_dtmgpb_dtmgimp_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use DtmGidReply.ProtoReflect.Descriptor instead. +func (*DtmGidReply) Descriptor() ([]byte, []int) { + return file_client_dtmgrpc_dtmgpb_dtmgimp_proto_rawDescGZIP(), []int{2} +} + +func (x *DtmGidReply) GetGid() string { + if x != nil { + return x.Gid + } + return "" +} + +type DtmBranchRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Gid string `protobuf:"bytes,1,opt,name=Gid,proto3" json:"Gid,omitempty"` + TransType string `protobuf:"bytes,2,opt,name=TransType,proto3" json:"TransType,omitempty"` + BranchID string `protobuf:"bytes,3,opt,name=BranchID,proto3" json:"BranchID,omitempty"` + Op string `protobuf:"bytes,4,opt,name=Op,proto3" json:"Op,omitempty"` + Data map[string]string `protobuf:"bytes,5,rep,name=Data,proto3" json:"Data,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` + BusiPayload []byte `protobuf:"bytes,6,opt,name=BusiPayload,proto3" json:"BusiPayload,omitempty"` +} + +func (x *DtmBranchRequest) Reset() { + *x = DtmBranchRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_client_dtmgrpc_dtmgpb_dtmgimp_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *DtmBranchRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*DtmBranchRequest) ProtoMessage() {} + +func (x *DtmBranchRequest) ProtoReflect() protoreflect.Message { + mi := &file_client_dtmgrpc_dtmgpb_dtmgimp_proto_msgTypes[3] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use DtmBranchRequest.ProtoReflect.Descriptor instead. +func (*DtmBranchRequest) Descriptor() ([]byte, []int) { + return file_client_dtmgrpc_dtmgpb_dtmgimp_proto_rawDescGZIP(), []int{3} +} + +func (x *DtmBranchRequest) GetGid() string { + if x != nil { + return x.Gid + } + return "" +} + +func (x *DtmBranchRequest) GetTransType() string { + if x != nil { + return x.TransType + } + return "" +} + +func (x *DtmBranchRequest) GetBranchID() string { + if x != nil { + return x.BranchID + } + return "" +} + +func (x *DtmBranchRequest) GetOp() string { + if x != nil { + return x.Op + } + return "" +} + +func (x *DtmBranchRequest) GetData() map[string]string { + if x != nil { + return x.Data + } + return nil +} + +func (x *DtmBranchRequest) GetBusiPayload() []byte { + if x != nil { + return x.BusiPayload + } + return nil +} + +type DtmProgressesReply struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Transaction *DtmTransaction `protobuf:"bytes,1,opt,name=Transaction,proto3" json:"Transaction,omitempty"` + Progresses []*DtmProgress `protobuf:"bytes,2,rep,name=Progresses,proto3" json:"Progresses,omitempty"` +} + +func (x *DtmProgressesReply) Reset() { + *x = DtmProgressesReply{} + if protoimpl.UnsafeEnabled { + mi := &file_client_dtmgrpc_dtmgpb_dtmgimp_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *DtmProgressesReply) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*DtmProgressesReply) ProtoMessage() {} + +func (x *DtmProgressesReply) ProtoReflect() protoreflect.Message { + mi := &file_client_dtmgrpc_dtmgpb_dtmgimp_proto_msgTypes[4] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use DtmProgressesReply.ProtoReflect.Descriptor instead. +func (*DtmProgressesReply) Descriptor() ([]byte, []int) { + return file_client_dtmgrpc_dtmgpb_dtmgimp_proto_rawDescGZIP(), []int{4} +} + +func (x *DtmProgressesReply) GetTransaction() *DtmTransaction { + if x != nil { + return x.Transaction + } + return nil +} + +func (x *DtmProgressesReply) GetProgresses() []*DtmProgress { + if x != nil { + return x.Progresses + } + return nil +} + +type DtmTransaction struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Gid string `protobuf:"bytes,1,opt,name=Gid,proto3" json:"Gid,omitempty"` + Status string `protobuf:"bytes,2,opt,name=Status,proto3" json:"Status,omitempty"` + RollbackReason string `protobuf:"bytes,3,opt,name=RollbackReason,proto3" json:"RollbackReason,omitempty"` +} + +func (x *DtmTransaction) Reset() { + *x = DtmTransaction{} + if protoimpl.UnsafeEnabled { + mi := &file_client_dtmgrpc_dtmgpb_dtmgimp_proto_msgTypes[5] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *DtmTransaction) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*DtmTransaction) ProtoMessage() {} + +func (x *DtmTransaction) ProtoReflect() protoreflect.Message { + mi := &file_client_dtmgrpc_dtmgpb_dtmgimp_proto_msgTypes[5] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use DtmTransaction.ProtoReflect.Descriptor instead. +func (*DtmTransaction) Descriptor() ([]byte, []int) { + return file_client_dtmgrpc_dtmgpb_dtmgimp_proto_rawDescGZIP(), []int{5} +} + +func (x *DtmTransaction) GetGid() string { + if x != nil { + return x.Gid + } + return "" +} + +func (x *DtmTransaction) GetStatus() string { + if x != nil { + return x.Status + } + return "" +} + +func (x *DtmTransaction) GetRollbackReason() string { + if x != nil { + return x.RollbackReason + } + return "" +} + +type DtmProgress struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Status string `protobuf:"bytes,1,opt,name=Status,proto3" json:"Status,omitempty"` + BinData []byte `protobuf:"bytes,2,opt,name=BinData,proto3" json:"BinData,omitempty"` + BranchID string `protobuf:"bytes,3,opt,name=BranchID,proto3" json:"BranchID,omitempty"` + Op string `protobuf:"bytes,4,opt,name=Op,proto3" json:"Op,omitempty"` +} + +func (x *DtmProgress) Reset() { + *x = DtmProgress{} + if protoimpl.UnsafeEnabled { + mi := &file_client_dtmgrpc_dtmgpb_dtmgimp_proto_msgTypes[6] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *DtmProgress) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*DtmProgress) ProtoMessage() {} + +func (x *DtmProgress) ProtoReflect() protoreflect.Message { + mi := &file_client_dtmgrpc_dtmgpb_dtmgimp_proto_msgTypes[6] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use DtmProgress.ProtoReflect.Descriptor instead. +func (*DtmProgress) Descriptor() ([]byte, []int) { + return file_client_dtmgrpc_dtmgpb_dtmgimp_proto_rawDescGZIP(), []int{6} +} + +func (x *DtmProgress) GetStatus() string { + if x != nil { + return x.Status + } + return "" +} + +func (x *DtmProgress) GetBinData() []byte { + if x != nil { + return x.BinData + } + return nil +} + +func (x *DtmProgress) GetBranchID() string { + if x != nil { + return x.BranchID + } + return "" +} + +func (x *DtmProgress) GetOp() string { + if x != nil { + return x.Op + } + return "" +} + +var File_client_dtmgrpc_dtmgpb_dtmgimp_proto protoreflect.FileDescriptor + +var file_client_dtmgrpc_dtmgpb_dtmgimp_proto_rawDesc = []byte{ + 0x0a, 0x23, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x2f, 0x64, 0x74, 0x6d, 0x67, 0x72, 0x70, 0x63, + 0x2f, 0x64, 0x74, 0x6d, 0x67, 0x70, 0x62, 0x2f, 0x64, 0x74, 0x6d, 0x67, 0x69, 0x6d, 0x70, 0x2e, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x07, 0x64, 0x74, 0x6d, 0x67, 0x69, 0x6d, 0x70, 0x1a, 0x1b, + 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, + 0x65, 0x6d, 0x70, 0x74, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xea, 0x02, 0x0a, 0x0f, + 0x44, 0x74, 0x6d, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12, + 0x1e, 0x0a, 0x0a, 0x57, 0x61, 0x69, 0x74, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x08, 0x52, 0x0a, 0x57, 0x61, 0x69, 0x74, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x12, + 0x24, 0x0a, 0x0d, 0x54, 0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x54, 0x6f, 0x46, 0x61, 0x69, 0x6c, + 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0d, 0x54, 0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x54, + 0x6f, 0x46, 0x61, 0x69, 0x6c, 0x12, 0x24, 0x0a, 0x0d, 0x52, 0x65, 0x74, 0x72, 0x79, 0x49, 0x6e, + 0x74, 0x65, 0x72, 0x76, 0x61, 0x6c, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0d, 0x52, 0x65, + 0x74, 0x72, 0x79, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x76, 0x61, 0x6c, 0x12, 0x2e, 0x0a, 0x12, 0x50, + 0x61, 0x73, 0x73, 0x74, 0x68, 0x72, 0x6f, 0x75, 0x67, 0x68, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, + 0x73, 0x18, 0x04, 0x20, 0x03, 0x28, 0x09, 0x52, 0x12, 0x50, 0x61, 0x73, 0x73, 0x74, 0x68, 0x72, + 0x6f, 0x75, 0x67, 0x68, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x12, 0x51, 0x0a, 0x0d, 0x42, + 0x72, 0x61, 0x6e, 0x63, 0x68, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x18, 0x05, 0x20, 0x03, + 0x28, 0x0b, 0x32, 0x2b, 0x2e, 0x64, 0x74, 0x6d, 0x67, 0x69, 0x6d, 0x70, 0x2e, 0x44, 0x74, 0x6d, + 0x54, 0x72, 0x61, 0x6e, 0x73, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x42, 0x72, 0x61, + 0x6e, 0x63, 0x68, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, + 0x0d, 0x42, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x12, 0x26, + 0x0a, 0x0e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x54, 0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74, + 0x18, 0x06, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x54, + 0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x1a, 0x40, 0x0a, 0x12, 0x42, 0x72, 0x61, 0x6e, 0x63, 0x68, + 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, + 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, + 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, + 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0xa0, 0x03, 0x0a, 0x0a, 0x44, 0x74, 0x6d, + 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x10, 0x0a, 0x03, 0x47, 0x69, 0x64, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x47, 0x69, 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x54, 0x72, 0x61, + 0x6e, 0x73, 0x54, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x54, 0x72, + 0x61, 0x6e, 0x73, 0x54, 0x79, 0x70, 0x65, 0x12, 0x3c, 0x0a, 0x0c, 0x54, 0x72, 0x61, 0x6e, 0x73, + 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x18, 0x2e, + 0x64, 0x74, 0x6d, 0x67, 0x69, 0x6d, 0x70, 0x2e, 0x44, 0x74, 0x6d, 0x54, 0x72, 0x61, 0x6e, 0x73, + 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x52, 0x0c, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x4f, 0x70, + 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x22, 0x0a, 0x0c, 0x43, 0x75, 0x73, 0x74, 0x6f, 0x6d, 0x65, + 0x64, 0x44, 0x61, 0x74, 0x61, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x43, 0x75, 0x73, + 0x74, 0x6f, 0x6d, 0x65, 0x64, 0x44, 0x61, 0x74, 0x61, 0x12, 0x20, 0x0a, 0x0b, 0x42, 0x69, 0x6e, + 0x50, 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64, 0x73, 0x18, 0x05, 0x20, 0x03, 0x28, 0x0c, 0x52, 0x0b, + 0x42, 0x69, 0x6e, 0x50, 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64, 0x73, 0x12, 0x24, 0x0a, 0x0d, 0x51, + 0x75, 0x65, 0x72, 0x79, 0x50, 0x72, 0x65, 0x70, 0x61, 0x72, 0x65, 0x64, 0x18, 0x06, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x0d, 0x51, 0x75, 0x65, 0x72, 0x79, 0x50, 0x72, 0x65, 0x70, 0x61, 0x72, 0x65, + 0x64, 0x12, 0x14, 0x0a, 0x05, 0x53, 0x74, 0x65, 0x70, 0x73, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x05, 0x53, 0x74, 0x65, 0x70, 0x73, 0x12, 0x3d, 0x0a, 0x08, 0x52, 0x65, 0x71, 0x45, 0x78, + 0x74, 0x72, 0x61, 0x18, 0x08, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x21, 0x2e, 0x64, 0x74, 0x6d, 0x67, + 0x69, 0x6d, 0x70, 0x2e, 0x44, 0x74, 0x6d, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x2e, 0x52, + 0x65, 0x71, 0x45, 0x78, 0x74, 0x72, 0x61, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x08, 0x52, 0x65, + 0x71, 0x45, 0x78, 0x74, 0x72, 0x61, 0x12, 0x26, 0x0a, 0x0e, 0x52, 0x6f, 0x6c, 0x6c, 0x62, 0x61, + 0x63, 0x6b, 0x52, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x18, 0x09, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0e, + 0x52, 0x6f, 0x6c, 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x52, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x1a, 0x3b, + 0x0a, 0x0d, 0x52, 0x65, 0x71, 0x45, 0x78, 0x74, 0x72, 0x61, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, + 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, + 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0x1f, 0x0a, 0x0b, 0x44, + 0x74, 0x6d, 0x47, 0x69, 0x64, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x47, 0x69, + 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x47, 0x69, 0x64, 0x22, 0x82, 0x02, 0x0a, + 0x10, 0x44, 0x74, 0x6d, 0x42, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x12, 0x10, 0x0a, 0x03, 0x47, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, + 0x47, 0x69, 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x54, 0x79, 0x70, 0x65, + 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x54, 0x79, 0x70, + 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x42, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x49, 0x44, 0x18, 0x03, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x08, 0x42, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x49, 0x44, 0x12, 0x0e, 0x0a, + 0x02, 0x4f, 0x70, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x4f, 0x70, 0x12, 0x37, 0x0a, + 0x04, 0x44, 0x61, 0x74, 0x61, 0x18, 0x05, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x23, 0x2e, 0x64, 0x74, + 0x6d, 0x67, 0x69, 0x6d, 0x70, 0x2e, 0x44, 0x74, 0x6d, 0x42, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x52, + 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x2e, 0x44, 0x61, 0x74, 0x61, 0x45, 0x6e, 0x74, 0x72, 0x79, + 0x52, 0x04, 0x44, 0x61, 0x74, 0x61, 0x12, 0x20, 0x0a, 0x0b, 0x42, 0x75, 0x73, 0x69, 0x50, 0x61, + 0x79, 0x6c, 0x6f, 0x61, 0x64, 0x18, 0x06, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0b, 0x42, 0x75, 0x73, + 0x69, 0x50, 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64, 0x1a, 0x37, 0x0a, 0x09, 0x44, 0x61, 0x74, 0x61, + 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, + 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, + 0x01, 0x22, 0x85, 0x01, 0x0a, 0x12, 0x44, 0x74, 0x6d, 0x50, 0x72, 0x6f, 0x67, 0x72, 0x65, 0x73, + 0x73, 0x65, 0x73, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x39, 0x0a, 0x0b, 0x54, 0x72, 0x61, 0x6e, + 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x17, 0x2e, + 0x64, 0x74, 0x6d, 0x67, 0x69, 0x6d, 0x70, 0x2e, 0x44, 0x74, 0x6d, 0x54, 0x72, 0x61, 0x6e, 0x73, + 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x0b, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, + 0x69, 0x6f, 0x6e, 0x12, 0x34, 0x0a, 0x0a, 0x50, 0x72, 0x6f, 0x67, 0x72, 0x65, 0x73, 0x73, 0x65, + 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x64, 0x74, 0x6d, 0x67, 0x69, 0x6d, + 0x70, 0x2e, 0x44, 0x74, 0x6d, 0x50, 0x72, 0x6f, 0x67, 0x72, 0x65, 0x73, 0x73, 0x52, 0x0a, 0x50, + 0x72, 0x6f, 0x67, 0x72, 0x65, 0x73, 0x73, 0x65, 0x73, 0x22, 0x62, 0x0a, 0x0e, 0x44, 0x74, 0x6d, + 0x54, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x10, 0x0a, 0x03, 0x47, + 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x47, 0x69, 0x64, 0x12, 0x16, 0x0a, + 0x06, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x53, + 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x26, 0x0a, 0x0e, 0x52, 0x6f, 0x6c, 0x6c, 0x62, 0x61, 0x63, + 0x6b, 0x52, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0e, 0x52, + 0x6f, 0x6c, 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x52, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x22, 0x6b, 0x0a, + 0x0b, 0x44, 0x74, 0x6d, 0x50, 0x72, 0x6f, 0x67, 0x72, 0x65, 0x73, 0x73, 0x12, 0x16, 0x0a, 0x06, + 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x53, 0x74, + 0x61, 0x74, 0x75, 0x73, 0x12, 0x18, 0x0a, 0x07, 0x42, 0x69, 0x6e, 0x44, 0x61, 0x74, 0x61, 0x18, + 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x07, 0x42, 0x69, 0x6e, 0x44, 0x61, 0x74, 0x61, 0x12, 0x1a, + 0x0a, 0x08, 0x42, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x49, 0x44, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x08, 0x42, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x49, 0x44, 0x12, 0x0e, 0x0a, 0x02, 0x4f, 0x70, + 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x4f, 0x70, 0x32, 0xf8, 0x02, 0x0a, 0x03, 0x44, + 0x74, 0x6d, 0x12, 0x38, 0x0a, 0x06, 0x4e, 0x65, 0x77, 0x47, 0x69, 0x64, 0x12, 0x16, 0x2e, 0x67, + 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, + 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x14, 0x2e, 0x64, 0x74, 0x6d, 0x67, 0x69, 0x6d, 0x70, 0x2e, 0x44, + 0x74, 0x6d, 0x47, 0x69, 0x64, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x00, 0x12, 0x37, 0x0a, 0x06, + 0x53, 0x75, 0x62, 0x6d, 0x69, 0x74, 0x12, 0x13, 0x2e, 0x64, 0x74, 0x6d, 0x67, 0x69, 0x6d, 0x70, + 0x2e, 0x44, 0x74, 0x6d, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x67, 0x6f, + 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, + 0x70, 0x74, 0x79, 0x22, 0x00, 0x12, 0x38, 0x0a, 0x07, 0x50, 0x72, 0x65, 0x70, 0x61, 0x72, 0x65, + 0x12, 0x13, 0x2e, 0x64, 0x74, 0x6d, 0x67, 0x69, 0x6d, 0x70, 0x2e, 0x44, 0x74, 0x6d, 0x52, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x22, 0x00, 0x12, + 0x36, 0x0a, 0x05, 0x41, 0x62, 0x6f, 0x72, 0x74, 0x12, 0x13, 0x2e, 0x64, 0x74, 0x6d, 0x67, 0x69, + 0x6d, 0x70, 0x2e, 0x44, 0x74, 0x6d, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, + 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, + 0x45, 0x6d, 0x70, 0x74, 0x79, 0x22, 0x00, 0x12, 0x45, 0x0a, 0x0e, 0x52, 0x65, 0x67, 0x69, 0x73, + 0x74, 0x65, 0x72, 0x42, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x12, 0x19, 0x2e, 0x64, 0x74, 0x6d, 0x67, + 0x69, 0x6d, 0x70, 0x2e, 0x44, 0x74, 0x6d, 0x42, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x52, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x22, 0x00, 0x12, 0x45, + 0x0a, 0x0f, 0x50, 0x72, 0x65, 0x70, 0x61, 0x72, 0x65, 0x57, 0x6f, 0x72, 0x6b, 0x66, 0x6c, 0x6f, + 0x77, 0x12, 0x13, 0x2e, 0x64, 0x74, 0x6d, 0x67, 0x69, 0x6d, 0x70, 0x2e, 0x44, 0x74, 0x6d, 0x52, + 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1b, 0x2e, 0x64, 0x74, 0x6d, 0x67, 0x69, 0x6d, 0x70, + 0x2e, 0x44, 0x74, 0x6d, 0x50, 0x72, 0x6f, 0x67, 0x72, 0x65, 0x73, 0x73, 0x65, 0x73, 0x52, 0x65, + 0x70, 0x6c, 0x79, 0x22, 0x00, 0x42, 0x0a, 0x5a, 0x08, 0x2e, 0x2f, 0x64, 0x74, 0x6d, 0x67, 0x70, + 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_client_dtmgrpc_dtmgpb_dtmgimp_proto_rawDescOnce sync.Once + file_client_dtmgrpc_dtmgpb_dtmgimp_proto_rawDescData = file_client_dtmgrpc_dtmgpb_dtmgimp_proto_rawDesc +) + +func file_client_dtmgrpc_dtmgpb_dtmgimp_proto_rawDescGZIP() []byte { + file_client_dtmgrpc_dtmgpb_dtmgimp_proto_rawDescOnce.Do(func() { + file_client_dtmgrpc_dtmgpb_dtmgimp_proto_rawDescData = protoimpl.X.CompressGZIP(file_client_dtmgrpc_dtmgpb_dtmgimp_proto_rawDescData) + }) + return file_client_dtmgrpc_dtmgpb_dtmgimp_proto_rawDescData +} + +var file_client_dtmgrpc_dtmgpb_dtmgimp_proto_msgTypes = make([]protoimpl.MessageInfo, 10) +var file_client_dtmgrpc_dtmgpb_dtmgimp_proto_goTypes = []interface{}{ + (*DtmTransOptions)(nil), // 0: dtmgimp.DtmTransOptions + (*DtmRequest)(nil), // 1: dtmgimp.DtmRequest + (*DtmGidReply)(nil), // 2: dtmgimp.DtmGidReply + (*DtmBranchRequest)(nil), // 3: dtmgimp.DtmBranchRequest + (*DtmProgressesReply)(nil), // 4: dtmgimp.DtmProgressesReply + (*DtmTransaction)(nil), // 5: dtmgimp.DtmTransaction + (*DtmProgress)(nil), // 6: dtmgimp.DtmProgress + nil, // 7: dtmgimp.DtmTransOptions.BranchHeadersEntry + nil, // 8: dtmgimp.DtmRequest.ReqExtraEntry + nil, // 9: dtmgimp.DtmBranchRequest.DataEntry + (*emptypb.Empty)(nil), // 10: google.protobuf.Empty +} +var file_client_dtmgrpc_dtmgpb_dtmgimp_proto_depIdxs = []int32{ + 7, // 0: dtmgimp.DtmTransOptions.BranchHeaders:type_name -> dtmgimp.DtmTransOptions.BranchHeadersEntry + 0, // 1: dtmgimp.DtmRequest.TransOptions:type_name -> dtmgimp.DtmTransOptions + 8, // 2: dtmgimp.DtmRequest.ReqExtra:type_name -> dtmgimp.DtmRequest.ReqExtraEntry + 9, // 3: dtmgimp.DtmBranchRequest.Data:type_name -> dtmgimp.DtmBranchRequest.DataEntry + 5, // 4: dtmgimp.DtmProgressesReply.Transaction:type_name -> dtmgimp.DtmTransaction + 6, // 5: dtmgimp.DtmProgressesReply.Progresses:type_name -> dtmgimp.DtmProgress + 10, // 6: dtmgimp.Dtm.NewGid:input_type -> google.protobuf.Empty + 1, // 7: dtmgimp.Dtm.Submit:input_type -> dtmgimp.DtmRequest + 1, // 8: dtmgimp.Dtm.Prepare:input_type -> dtmgimp.DtmRequest + 1, // 9: dtmgimp.Dtm.Abort:input_type -> dtmgimp.DtmRequest + 3, // 10: dtmgimp.Dtm.RegisterBranch:input_type -> dtmgimp.DtmBranchRequest + 1, // 11: dtmgimp.Dtm.PrepareWorkflow:input_type -> dtmgimp.DtmRequest + 2, // 12: dtmgimp.Dtm.NewGid:output_type -> dtmgimp.DtmGidReply + 10, // 13: dtmgimp.Dtm.Submit:output_type -> google.protobuf.Empty + 10, // 14: dtmgimp.Dtm.Prepare:output_type -> google.protobuf.Empty + 10, // 15: dtmgimp.Dtm.Abort:output_type -> google.protobuf.Empty + 10, // 16: dtmgimp.Dtm.RegisterBranch:output_type -> google.protobuf.Empty + 4, // 17: dtmgimp.Dtm.PrepareWorkflow:output_type -> dtmgimp.DtmProgressesReply + 12, // [12:18] is the sub-list for method output_type + 6, // [6:12] is the sub-list for method input_type + 6, // [6:6] is the sub-list for extension type_name + 6, // [6:6] is the sub-list for extension extendee + 0, // [0:6] is the sub-list for field type_name +} + +func init() { file_client_dtmgrpc_dtmgpb_dtmgimp_proto_init() } +func file_client_dtmgrpc_dtmgpb_dtmgimp_proto_init() { + if File_client_dtmgrpc_dtmgpb_dtmgimp_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_client_dtmgrpc_dtmgpb_dtmgimp_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*DtmTransOptions); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_client_dtmgrpc_dtmgpb_dtmgimp_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*DtmRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_client_dtmgrpc_dtmgpb_dtmgimp_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*DtmGidReply); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_client_dtmgrpc_dtmgpb_dtmgimp_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*DtmBranchRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_client_dtmgrpc_dtmgpb_dtmgimp_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*DtmProgressesReply); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_client_dtmgrpc_dtmgpb_dtmgimp_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*DtmTransaction); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_client_dtmgrpc_dtmgpb_dtmgimp_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*DtmProgress); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_client_dtmgrpc_dtmgpb_dtmgimp_proto_rawDesc, + NumEnums: 0, + NumMessages: 10, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_client_dtmgrpc_dtmgpb_dtmgimp_proto_goTypes, + DependencyIndexes: file_client_dtmgrpc_dtmgpb_dtmgimp_proto_depIdxs, + MessageInfos: file_client_dtmgrpc_dtmgpb_dtmgimp_proto_msgTypes, + }.Build() + File_client_dtmgrpc_dtmgpb_dtmgimp_proto = out.File + file_client_dtmgrpc_dtmgpb_dtmgimp_proto_rawDesc = nil + file_client_dtmgrpc_dtmgpb_dtmgimp_proto_goTypes = nil + file_client_dtmgrpc_dtmgpb_dtmgimp_proto_depIdxs = nil +} diff --git a/dtmgrpc/dtmgpb/dtmgimp.proto b/client/dtmgrpc/dtmgpb/dtmgimp.proto similarity index 89% rename from dtmgrpc/dtmgpb/dtmgimp.proto rename to client/dtmgrpc/dtmgpb/dtmgimp.proto index 6005696..5e3459a 100644 --- a/dtmgrpc/dtmgpb/dtmgimp.proto +++ b/client/dtmgrpc/dtmgpb/dtmgimp.proto @@ -51,7 +51,14 @@ message DtmBranchRequest { } message DtmProgressesReply { - repeated DtmProgress Progresses = 1; + DtmTransaction Transaction = 1; + repeated DtmProgress Progresses = 2; +} + +message DtmTransaction { + string Gid = 1; + string Status = 2; + string RollbackReason = 3; } message DtmProgress { diff --git a/dtmgrpc/dtmgpb/dtmgimp_grpc.pb.go b/client/dtmgrpc/dtmgpb/dtmgimp_grpc.pb.go similarity index 99% rename from dtmgrpc/dtmgpb/dtmgimp_grpc.pb.go rename to client/dtmgrpc/dtmgpb/dtmgimp_grpc.pb.go index 6327fb7..4d875bf 100644 --- a/dtmgrpc/dtmgpb/dtmgimp_grpc.pb.go +++ b/client/dtmgrpc/dtmgpb/dtmgimp_grpc.pb.go @@ -2,7 +2,7 @@ // versions: // - protoc-gen-go-grpc v1.2.0 // - protoc v3.17.3 -// source: dtmgrpc/dtmgpb/dtmgimp.proto +// source: client/dtmgrpc/dtmgpb/dtmgimp.proto package dtmgpb @@ -282,5 +282,5 @@ var Dtm_ServiceDesc = grpc.ServiceDesc{ }, }, Streams: []grpc.StreamDesc{}, - Metadata: "dtmgrpc/dtmgpb/dtmgimp.proto", + Metadata: "client/dtmgrpc/dtmgpb/dtmgimp.proto", } diff --git a/dtmgrpc/msg.go b/client/dtmgrpc/msg.go similarity index 94% rename from dtmgrpc/msg.go rename to client/dtmgrpc/msg.go index 82b504d..ec622ab 100644 --- a/dtmgrpc/msg.go +++ b/client/dtmgrpc/msg.go @@ -10,9 +10,9 @@ import ( "database/sql" "errors" - "github.com/dtm-labs/dtm/dtmcli" - "github.com/dtm-labs/dtm/dtmcli/dtmimp" - "github.com/dtm-labs/dtm/dtmgrpc/dtmgimp" + "github.com/dtm-labs/dtm/client/dtmcli" + "github.com/dtm-labs/dtm/client/dtmcli/dtmimp" + "github.com/dtm-labs/dtm/client/dtmgrpc/dtmgimp" "google.golang.org/protobuf/proto" ) diff --git a/dtmgrpc/saga.go b/client/dtmgrpc/saga.go similarity index 93% rename from dtmgrpc/saga.go rename to client/dtmgrpc/saga.go index a0cc9d4..9d801aa 100644 --- a/dtmgrpc/saga.go +++ b/client/dtmgrpc/saga.go @@ -7,8 +7,8 @@ package dtmgrpc import ( - "github.com/dtm-labs/dtm/dtmcli" - "github.com/dtm-labs/dtm/dtmgrpc/dtmgimp" + "github.com/dtm-labs/dtm/client/dtmcli" + "github.com/dtm-labs/dtm/client/dtmgrpc/dtmgimp" "google.golang.org/protobuf/proto" ) diff --git a/dtmgrpc/tcc.go b/client/dtmgrpc/tcc.go similarity index 94% rename from dtmgrpc/tcc.go rename to client/dtmgrpc/tcc.go index d9d52a4..09f242f 100644 --- a/dtmgrpc/tcc.go +++ b/client/dtmgrpc/tcc.go @@ -10,9 +10,9 @@ import ( context "context" "fmt" - "github.com/dtm-labs/dtm/dtmcli/dtmimp" - "github.com/dtm-labs/dtm/dtmgrpc/dtmgimp" - "github.com/dtm-labs/dtm/dtmgrpc/dtmgpb" + "github.com/dtm-labs/dtm/client/dtmcli/dtmimp" + "github.com/dtm-labs/dtm/client/dtmgrpc/dtmgimp" + "github.com/dtm-labs/dtm/client/dtmgrpc/dtmgpb" "google.golang.org/protobuf/proto" ) diff --git a/dtmgrpc/type.go b/client/dtmgrpc/type.go similarity index 86% rename from dtmgrpc/type.go rename to client/dtmgrpc/type.go index bf31a85..883504e 100644 --- a/dtmgrpc/type.go +++ b/client/dtmgrpc/type.go @@ -9,11 +9,10 @@ package dtmgrpc import ( context "context" "errors" - "fmt" - "github.com/dtm-labs/dtm/dtmcli" - "github.com/dtm-labs/dtm/dtmcli/dtmimp" - "github.com/dtm-labs/dtm/dtmgrpc/dtmgimp" + "github.com/dtm-labs/dtm/client/dtmcli" + "github.com/dtm-labs/dtm/client/dtmcli/dtmimp" + "github.com/dtm-labs/dtm/client/dtmgrpc/dtmgimp" "github.com/dtm-labs/dtmdriver" grpc "google.golang.org/grpc" "google.golang.org/grpc/codes" @@ -40,9 +39,9 @@ func GrpcError2DtmError(err error) error { if st.Message() == dtmcli.ResultOngoing { return dtmcli.ErrOngoing } - return fmt.Errorf("%s. %w", st.Message(), dtmcli.ErrFailure) + return dtmcli.ErrorMessage2Error(st.Message(), dtmcli.ErrFailure) } else if st != nil && st.Code() == codes.FailedPrecondition { - return fmt.Errorf("%s. %w", st.Message(), dtmcli.ErrOngoing) + return dtmcli.ErrorMessage2Error(st.Message(), dtmcli.ErrOngoing) } return err } diff --git a/dtmgrpc/type_test.go b/client/dtmgrpc/type_test.go similarity index 100% rename from dtmgrpc/type_test.go rename to client/dtmgrpc/type_test.go diff --git a/dtmgrpc/xa.go b/client/dtmgrpc/xa.go similarity index 94% rename from dtmgrpc/xa.go rename to client/dtmgrpc/xa.go index 7ab34d7..96add2b 100644 --- a/dtmgrpc/xa.go +++ b/client/dtmgrpc/xa.go @@ -11,10 +11,10 @@ import ( "database/sql" "fmt" - "github.com/dtm-labs/dtm/dtmcli" - "github.com/dtm-labs/dtm/dtmcli/dtmimp" - "github.com/dtm-labs/dtm/dtmgrpc/dtmgimp" - "github.com/dtm-labs/dtm/dtmgrpc/dtmgpb" + "github.com/dtm-labs/dtm/client/dtmcli" + "github.com/dtm-labs/dtm/client/dtmcli/dtmimp" + "github.com/dtm-labs/dtm/client/dtmgrpc/dtmgimp" + "github.com/dtm-labs/dtm/client/dtmgrpc/dtmgpb" grpc "google.golang.org/grpc" "google.golang.org/protobuf/proto" emptypb "google.golang.org/protobuf/types/known/emptypb" diff --git a/dtmgrpc/workflow/dummyReadCloser.go b/client/workflow/dummyReadCloser.go similarity index 100% rename from dtmgrpc/workflow/dummyReadCloser.go rename to client/workflow/dummyReadCloser.go diff --git a/dtmgrpc/workflow/factory.go b/client/workflow/factory.go similarity index 95% rename from dtmgrpc/workflow/factory.go rename to client/workflow/factory.go index fa65a9a..ea71351 100644 --- a/dtmgrpc/workflow/factory.go +++ b/client/workflow/factory.go @@ -4,7 +4,7 @@ import ( "fmt" "net/url" - "github.com/dtm-labs/dtm/dtmcli/logger" + "github.com/dtm-labs/dtm/client/dtmcli/logger" ) type workflowFactory struct { diff --git a/dtmgrpc/workflow/imp.go b/client/workflow/imp.go similarity index 93% rename from dtmgrpc/workflow/imp.go rename to client/workflow/imp.go index 6693735..7fcab39 100644 --- a/dtmgrpc/workflow/imp.go +++ b/client/workflow/imp.go @@ -5,9 +5,9 @@ import ( "errors" "fmt" - "github.com/dtm-labs/dtm/dtmcli" - "github.com/dtm-labs/dtm/dtmcli/dtmimp" - "github.com/dtm-labs/dtm/dtmcli/logger" + "github.com/dtm-labs/dtm/client/dtmcli" + "github.com/dtm-labs/dtm/client/dtmcli/dtmimp" + "github.com/dtm-labs/dtm/client/dtmcli/logger" "github.com/go-resty/resty/v2" ) @@ -39,7 +39,7 @@ func (wf *Workflow) loadProgresses() error { Data: p.BinData, } if sr.Status == dtmcli.StatusFailed { - sr.Error = fmt.Errorf("%s. %w", string(p.BinData), dtmcli.ErrFailure) + sr.Error = dtmcli.ErrorMessage2Error(string(p.BinData), dtmcli.ErrFailure) } wf.progresses[p.BranchID+"-"+p.Op] = sr } @@ -86,7 +86,7 @@ func (wf *Workflow) initRestyClient() { "gid": wf.Gid, "trans_type": wf.TransType, "branch_id": wf.currentBranch, - "op": dtmimp.OpAction, + "op": wf.currentOp, }) err := dtmimp.BeforeRequest(c, r) return err @@ -109,7 +109,7 @@ func (wf *Workflow) process(handler WfFunc, data []byte) (err error) { err = wf.processPhase2(err) } if err == nil || errors.Is(err, dtmcli.ErrFailure) { - err1 := wf.submit(wfErrorToStatus(err)) + err1 := wf.submit(err) if err1 != nil { return err1 } @@ -178,7 +178,7 @@ func (wf *Workflow) recordedDoInner(fn func(bb *dtmcli.BranchBarrier) *stepResul } r := wf.getStepResult() if r != nil { - logger.Debugf("progress restored: %s %s %v %s %s", branchID, wf.currentOp, r.Error, r.Status, r.Data) + logger.Debugf("progress restored: '%s' '%s' '%v' '%s' '%s'", branchID, wf.currentOp, r.Error, r.Status, r.Data) return r } bb := &dtmcli.BranchBarrier{ diff --git a/dtmgrpc/workflow/rpc.go b/client/workflow/rpc.go similarity index 76% rename from dtmgrpc/workflow/rpc.go rename to client/workflow/rpc.go index 3badc5e..29dc96e 100644 --- a/dtmgrpc/workflow/rpc.go +++ b/client/workflow/rpc.go @@ -3,9 +3,9 @@ package workflow import ( "context" - "github.com/dtm-labs/dtm/dtmcli/dtmimp" - "github.com/dtm-labs/dtm/dtmgrpc/dtmgimp" - "github.com/dtm-labs/dtm/dtmgrpc/dtmgpb" + "github.com/dtm-labs/dtm/client/dtmcli/dtmimp" + "github.com/dtm-labs/dtm/client/dtmgrpc/dtmgimp" + "github.com/dtm-labs/dtm/client/dtmgrpc/dtmgpb" "google.golang.org/protobuf/types/known/emptypb" ) @@ -20,20 +20,26 @@ func (wf *Workflow) getProgress() ([]*dtmgpb.DtmProgress, error) { return nil, err } resp, err := dtmimp.RestyClient.R().SetBody(wf.TransBase).Post(wf.Dtm + "/prepareWorkflow") - var progresses []*dtmgpb.DtmProgress + var reply dtmgpb.DtmProgressesReply if err == nil { - dtmimp.MustUnmarshal(resp.Body(), &progresses) + dtmimp.MustUnmarshal(resp.Body(), &reply) } - return progresses, err + return reply.Progresses, err } -func (wf *Workflow) submit(status string) error { +func (wf *Workflow) submit(err error) error { + status := wfErrorToStatus(err) + reason := "" + if err != nil { + reason = err.Error() + } if wf.Protocol == dtmimp.ProtocolHTTP { m := map[string]interface{}{ "gid": wf.Gid, "trans_type": wf.TransType, "req_extra": map[string]string{ - "status": status, + "status": status, + "rollback_reason": reason, }, } _, err := dtmimp.TransCallDtmExt(wf.TransBase, m, "submit") @@ -41,7 +47,8 @@ func (wf *Workflow) submit(status string) error { } req := dtmgimp.GetDtmRequest(wf.TransBase) req.ReqExtra = map[string]string{ - "status": status, + "status": status, + "rollback_reason": reason, } reply := emptypb.Empty{} return dtmgimp.MustGetGrpcConn(wf.Dtm, false).Invoke(wf.Context, "/dtmgimp.Dtm/"+"Submit", req, &reply) diff --git a/dtmgrpc/workflow/server.go b/client/workflow/server.go similarity index 77% rename from dtmgrpc/workflow/server.go rename to client/workflow/server.go index ab2ebd6..1cd51fe 100644 --- a/dtmgrpc/workflow/server.go +++ b/client/workflow/server.go @@ -3,10 +3,10 @@ package workflow import ( "context" - "github.com/dtm-labs/dtm/dtmcli/dtmimp" - "github.com/dtm-labs/dtm/dtmgrpc" - "github.com/dtm-labs/dtm/dtmgrpc/dtmgimp" - "github.com/dtm-labs/dtm/dtmgrpc/workflow/wfpb" + "github.com/dtm-labs/dtm/client/dtmcli/dtmimp" + "github.com/dtm-labs/dtm/client/dtmgrpc" + "github.com/dtm-labs/dtm/client/dtmgrpc/dtmgimp" + "github.com/dtm-labs/dtm/client/workflow/wfpb" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" "google.golang.org/protobuf/types/known/emptypb" diff --git a/dtmgrpc/workflow/utils.go b/client/workflow/utils.go similarity index 88% rename from dtmgrpc/workflow/utils.go rename to client/workflow/utils.go index 5c5720e..b8d6739 100644 --- a/dtmgrpc/workflow/utils.go +++ b/client/workflow/utils.go @@ -3,14 +3,13 @@ package workflow import ( "bytes" "errors" - "fmt" "io/ioutil" "net/http" "strconv" - "github.com/dtm-labs/dtm/dtmcli" - "github.com/dtm-labs/dtm/dtmcli/dtmimp" - "github.com/dtm-labs/dtm/dtmgrpc/dtmgimp" + "github.com/dtm-labs/dtm/client/dtmcli" + "github.com/dtm-labs/dtm/client/dtmcli/dtmimp" + "github.com/dtm-labs/dtm/client/dtmgrpc/dtmgimp" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" "google.golang.org/protobuf/reflect/protoreflect" @@ -75,9 +74,9 @@ func HTTPResp2DtmError(resp *http.Response) ([]byte, error) { data, err := ioutil.ReadAll(resp.Body) resp.Body = ioutil.NopCloser(bytes.NewBuffer(data)) if code == http.StatusTooEarly { - return data, fmt.Errorf("%s. %w", string(data), dtmcli.ErrOngoing) + return data, dtmcli.ErrorMessage2Error(string(data), dtmcli.ErrOngoing) } else if code == http.StatusConflict { - return data, fmt.Errorf("%s. %w", string(data), dtmcli.ErrFailure) + return data, dtmcli.ErrorMessage2Error(string(data), dtmcli.ErrFailure) } else if err == nil && code != http.StatusOK { return data, errors.New(string(data)) } @@ -88,9 +87,9 @@ func HTTPResp2DtmError(resp *http.Response) ([]byte, error) { func GrpcError2DtmError(err error) error { st, _ := status.FromError(err) if st != nil && st.Code() == codes.Aborted { - return fmt.Errorf("%s. %w", st.Message(), dtmcli.ErrFailure) + return dtmcli.ErrorMessage2Error(st.Message(), dtmcli.ErrFailure) } else if st != nil && st.Code() == codes.FailedPrecondition { - return fmt.Errorf("%s. %w", st.Message(), dtmcli.ErrOngoing) + return dtmcli.ErrorMessage2Error(st.Message(), dtmcli.ErrOngoing) } return err } @@ -113,7 +112,7 @@ func (wf *Workflow) stepResultFromGrpc(reply interface{}, err error) *stepResult if sr.Error == nil { sr.Data = dtmgimp.MustProtoMarshal(reply.(protoreflect.ProtoMessage)) } else if sr.Status == dtmcli.StatusFailed { - sr.Data = []byte(sr.Error.Error()) + sr.Data = []byte(err.Error()) } return sr } diff --git a/client/workflow/wfpb/wf.pb.go b/client/workflow/wfpb/wf.pb.go new file mode 100644 index 0000000..e9b48af --- /dev/null +++ b/client/workflow/wfpb/wf.pb.go @@ -0,0 +1,152 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.28.0 +// protoc v3.17.3 +// source: workflow/wfpb/wf.proto + +package wfpb + +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + emptypb "google.golang.org/protobuf/types/known/emptypb" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type WorkflowData struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Data []byte `protobuf:"bytes,1,opt,name=Data,proto3" json:"Data,omitempty"` +} + +func (x *WorkflowData) Reset() { + *x = WorkflowData{} + if protoimpl.UnsafeEnabled { + mi := &file_workflow_wfpb_wf_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *WorkflowData) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*WorkflowData) ProtoMessage() {} + +func (x *WorkflowData) ProtoReflect() protoreflect.Message { + mi := &file_workflow_wfpb_wf_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use WorkflowData.ProtoReflect.Descriptor instead. +func (*WorkflowData) Descriptor() ([]byte, []int) { + return file_workflow_wfpb_wf_proto_rawDescGZIP(), []int{0} +} + +func (x *WorkflowData) GetData() []byte { + if x != nil { + return x.Data + } + return nil +} + +var File_workflow_wfpb_wf_proto protoreflect.FileDescriptor + +var file_workflow_wfpb_wf_proto_rawDesc = []byte{ + 0x0a, 0x16, 0x77, 0x6f, 0x72, 0x6b, 0x66, 0x6c, 0x6f, 0x77, 0x2f, 0x77, 0x66, 0x70, 0x62, 0x2f, + 0x77, 0x66, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x08, 0x77, 0x6f, 0x72, 0x6b, 0x66, 0x6c, + 0x6f, 0x77, 0x1a, 0x1b, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x62, 0x75, 0x66, 0x2f, 0x65, 0x6d, 0x70, 0x74, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, + 0x22, 0x0a, 0x0c, 0x57, 0x6f, 0x72, 0x6b, 0x66, 0x6c, 0x6f, 0x77, 0x44, 0x61, 0x74, 0x61, 0x12, + 0x12, 0x0a, 0x04, 0x44, 0x61, 0x74, 0x61, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x04, 0x44, + 0x61, 0x74, 0x61, 0x32, 0x47, 0x0a, 0x08, 0x57, 0x6f, 0x72, 0x6b, 0x66, 0x6c, 0x6f, 0x77, 0x12, + 0x3b, 0x0a, 0x07, 0x45, 0x78, 0x65, 0x63, 0x75, 0x74, 0x65, 0x12, 0x16, 0x2e, 0x77, 0x6f, 0x72, + 0x6b, 0x66, 0x6c, 0x6f, 0x77, 0x2e, 0x57, 0x6f, 0x72, 0x6b, 0x66, 0x6c, 0x6f, 0x77, 0x44, 0x61, + 0x74, 0x61, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x22, 0x00, 0x42, 0x08, 0x5a, 0x06, + 0x2e, 0x2f, 0x77, 0x66, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_workflow_wfpb_wf_proto_rawDescOnce sync.Once + file_workflow_wfpb_wf_proto_rawDescData = file_workflow_wfpb_wf_proto_rawDesc +) + +func file_workflow_wfpb_wf_proto_rawDescGZIP() []byte { + file_workflow_wfpb_wf_proto_rawDescOnce.Do(func() { + file_workflow_wfpb_wf_proto_rawDescData = protoimpl.X.CompressGZIP(file_workflow_wfpb_wf_proto_rawDescData) + }) + return file_workflow_wfpb_wf_proto_rawDescData +} + +var file_workflow_wfpb_wf_proto_msgTypes = make([]protoimpl.MessageInfo, 1) +var file_workflow_wfpb_wf_proto_goTypes = []interface{}{ + (*WorkflowData)(nil), // 0: workflow.WorkflowData + (*emptypb.Empty)(nil), // 1: google.protobuf.Empty +} +var file_workflow_wfpb_wf_proto_depIdxs = []int32{ + 0, // 0: workflow.Workflow.Execute:input_type -> workflow.WorkflowData + 1, // 1: workflow.Workflow.Execute:output_type -> google.protobuf.Empty + 1, // [1:2] is the sub-list for method output_type + 0, // [0:1] is the sub-list for method input_type + 0, // [0:0] is the sub-list for extension type_name + 0, // [0:0] is the sub-list for extension extendee + 0, // [0:0] is the sub-list for field type_name +} + +func init() { file_workflow_wfpb_wf_proto_init() } +func file_workflow_wfpb_wf_proto_init() { + if File_workflow_wfpb_wf_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_workflow_wfpb_wf_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*WorkflowData); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_workflow_wfpb_wf_proto_rawDesc, + NumEnums: 0, + NumMessages: 1, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_workflow_wfpb_wf_proto_goTypes, + DependencyIndexes: file_workflow_wfpb_wf_proto_depIdxs, + MessageInfos: file_workflow_wfpb_wf_proto_msgTypes, + }.Build() + File_workflow_wfpb_wf_proto = out.File + file_workflow_wfpb_wf_proto_rawDesc = nil + file_workflow_wfpb_wf_proto_goTypes = nil + file_workflow_wfpb_wf_proto_depIdxs = nil +} diff --git a/dtmgrpc/workflow/wfpb/wf.proto b/client/workflow/wfpb/wf.proto similarity index 100% rename from dtmgrpc/workflow/wfpb/wf.proto rename to client/workflow/wfpb/wf.proto diff --git a/dtmgrpc/workflow/wfpb/wf_grpc.pb.go b/client/workflow/wfpb/wf_grpc.pb.go similarity index 97% rename from dtmgrpc/workflow/wfpb/wf_grpc.pb.go rename to client/workflow/wfpb/wf_grpc.pb.go index deb3abf..66f54fa 100644 --- a/dtmgrpc/workflow/wfpb/wf_grpc.pb.go +++ b/client/workflow/wfpb/wf_grpc.pb.go @@ -2,7 +2,7 @@ // versions: // - protoc-gen-go-grpc v1.2.0 // - protoc v3.17.3 -// source: dtmgrpc/workflow/wfpb/wf.proto +// source: workflow/wfpb/wf.proto package wfpb @@ -102,5 +102,5 @@ var Workflow_ServiceDesc = grpc.ServiceDesc{ }, }, Streams: []grpc.StreamDesc{}, - Metadata: "dtmgrpc/workflow/wfpb/wf.proto", + Metadata: "workflow/wfpb/wf.proto", } diff --git a/dtmgrpc/workflow/workflow.go b/client/workflow/workflow.go similarity index 97% rename from dtmgrpc/workflow/workflow.go rename to client/workflow/workflow.go index 0e13723..8075536 100644 --- a/dtmgrpc/workflow/workflow.go +++ b/client/workflow/workflow.go @@ -7,11 +7,11 @@ import ( "net/http" "net/url" - "github.com/dtm-labs/dtm/dtmcli" - "github.com/dtm-labs/dtm/dtmcli/dtmimp" - "github.com/dtm-labs/dtm/dtmcli/logger" - "github.com/dtm-labs/dtm/dtmgrpc/dtmgimp" - "github.com/dtm-labs/dtm/dtmgrpc/workflow/wfpb" + "github.com/dtm-labs/dtm/client/dtmcli" + "github.com/dtm-labs/dtm/client/dtmcli/dtmimp" + "github.com/dtm-labs/dtm/client/dtmcli/logger" + "github.com/dtm-labs/dtm/client/dtmgrpc/dtmgimp" + "github.com/dtm-labs/dtm/client/workflow/wfpb" "github.com/go-resty/resty/v2" "google.golang.org/grpc" ) diff --git a/dtmgrpc/workflow/workflow_test.go b/client/workflow/workflow_test.go similarity index 91% rename from dtmgrpc/workflow/workflow_test.go rename to client/workflow/workflow_test.go index f4c81e7..422df2c 100644 --- a/dtmgrpc/workflow/workflow_test.go +++ b/client/workflow/workflow_test.go @@ -4,7 +4,7 @@ import ( "context" "testing" - "github.com/dtm-labs/dtm/dtmcli/dtmimp" + "github.com/dtm-labs/dtm/client/dtmcli/dtmimp" "github.com/stretchr/testify/assert" ) diff --git a/conf.sample.yml b/conf.sample.yml index f0f2cb6..fb74f14 100644 --- a/conf.sample.yml +++ b/conf.sample.yml @@ -68,3 +68,4 @@ ### advanced options # UpdateBranchAsyncGoroutineNum: 1 # num of async goroutine to update branch status +# TimeZoneOffset: '' #default '' using system default. '+8': Asia/Shanghai; '0': GMT \ No newline at end of file diff --git a/dtmcli/utils.go b/dtmcli/utils.go deleted file mode 100644 index 51dde87..0000000 --- a/dtmcli/utils.go +++ /dev/null @@ -1,62 +0,0 @@ -package dtmcli - -import ( - "errors" - "fmt" - "net/http" - - "github.com/dtm-labs/dtm/dtmcli/dtmimp" - "github.com/go-resty/resty/v2" -) - -// MustGenGid generate a new gid -func MustGenGid(server string) string { - res := map[string]string{} - resp, err := dtmimp.RestyClient.R().SetResult(&res).Get(server + "/newGid") - if err != nil || res["gid"] == "" { - panic(fmt.Errorf("newGid error: %v, resp: %s", err, resp)) - } - return res["gid"] -} - -// String2DtmError translate string to dtm error -func String2DtmError(str string) error { - return map[string]error{ - ResultFailure: ErrFailure, - ResultOngoing: ErrOngoing, - ResultSuccess: nil, - "": nil, - }[str] -} - -// Result2HttpJSON return the http code and json result -// if result is error, the return proper code, else return StatusOK -func Result2HttpJSON(result interface{}) (code int, res interface{}) { - err, _ := result.(error) - if err == nil { - code = http.StatusOK - res = result - } else { - res = map[string]string{ - "error": err.Error(), - } - if errors.Is(err, ErrFailure) { - code = http.StatusConflict - } else if errors.Is(err, ErrOngoing) { - code = http.StatusTooEarly - } else if err != nil { - code = http.StatusInternalServerError - } - } - return -} - -// IsRollback returns whether the result is indicating rollback -func IsRollback(resp *resty.Response, err error) bool { - return err == ErrFailure || dtmimp.RespAsErrorCompatible(resp) == ErrFailure -} - -// IsOngoing returns whether the result is indicating ongoing -func IsOngoing(resp *resty.Response, err error) bool { - return err == ErrOngoing || dtmimp.RespAsErrorCompatible(resp) == ErrOngoing -} diff --git a/dtmgrpc/dtmgpb/dtmgimp.pb.go b/dtmgrpc/dtmgpb/dtmgimp.pb.go deleted file mode 100644 index 35cd8d4..0000000 --- a/dtmgrpc/dtmgpb/dtmgimp.pb.go +++ /dev/null @@ -1,736 +0,0 @@ -// Code generated by protoc-gen-go. DO NOT EDIT. -// versions: -// protoc-gen-go v1.28.0 -// protoc v3.17.3 -// source: dtmgrpc/dtmgpb/dtmgimp.proto - -package dtmgpb - -import ( - protoreflect "google.golang.org/protobuf/reflect/protoreflect" - protoimpl "google.golang.org/protobuf/runtime/protoimpl" - emptypb "google.golang.org/protobuf/types/known/emptypb" - reflect "reflect" - sync "sync" -) - -const ( - // Verify that this generated code is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) - // Verify that runtime/protoimpl is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) -) - -type DtmTransOptions struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - WaitResult bool `protobuf:"varint,1,opt,name=WaitResult,proto3" json:"WaitResult,omitempty"` - TimeoutToFail int64 `protobuf:"varint,2,opt,name=TimeoutToFail,proto3" json:"TimeoutToFail,omitempty"` - RetryInterval int64 `protobuf:"varint,3,opt,name=RetryInterval,proto3" json:"RetryInterval,omitempty"` - PassthroughHeaders []string `protobuf:"bytes,4,rep,name=PassthroughHeaders,proto3" json:"PassthroughHeaders,omitempty"` - BranchHeaders map[string]string `protobuf:"bytes,5,rep,name=BranchHeaders,proto3" json:"BranchHeaders,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` - RequestTimeout int64 `protobuf:"varint,6,opt,name=RequestTimeout,proto3" json:"RequestTimeout,omitempty"` -} - -func (x *DtmTransOptions) Reset() { - *x = DtmTransOptions{} - if protoimpl.UnsafeEnabled { - mi := &file_dtmgrpc_dtmgpb_dtmgimp_proto_msgTypes[0] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *DtmTransOptions) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*DtmTransOptions) ProtoMessage() {} - -func (x *DtmTransOptions) ProtoReflect() protoreflect.Message { - mi := &file_dtmgrpc_dtmgpb_dtmgimp_proto_msgTypes[0] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use DtmTransOptions.ProtoReflect.Descriptor instead. -func (*DtmTransOptions) Descriptor() ([]byte, []int) { - return file_dtmgrpc_dtmgpb_dtmgimp_proto_rawDescGZIP(), []int{0} -} - -func (x *DtmTransOptions) GetWaitResult() bool { - if x != nil { - return x.WaitResult - } - return false -} - -func (x *DtmTransOptions) GetTimeoutToFail() int64 { - if x != nil { - return x.TimeoutToFail - } - return 0 -} - -func (x *DtmTransOptions) GetRetryInterval() int64 { - if x != nil { - return x.RetryInterval - } - return 0 -} - -func (x *DtmTransOptions) GetPassthroughHeaders() []string { - if x != nil { - return x.PassthroughHeaders - } - return nil -} - -func (x *DtmTransOptions) GetBranchHeaders() map[string]string { - if x != nil { - return x.BranchHeaders - } - return nil -} - -func (x *DtmTransOptions) GetRequestTimeout() int64 { - if x != nil { - return x.RequestTimeout - } - return 0 -} - -// DtmRequest request sent to dtm server -type DtmRequest struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Gid string `protobuf:"bytes,1,opt,name=Gid,proto3" json:"Gid,omitempty"` - TransType string `protobuf:"bytes,2,opt,name=TransType,proto3" json:"TransType,omitempty"` - TransOptions *DtmTransOptions `protobuf:"bytes,3,opt,name=TransOptions,proto3" json:"TransOptions,omitempty"` - CustomedData string `protobuf:"bytes,4,opt,name=CustomedData,proto3" json:"CustomedData,omitempty"` - BinPayloads [][]byte `protobuf:"bytes,5,rep,name=BinPayloads,proto3" json:"BinPayloads,omitempty"` // for Msg/Saga/Workflow branch payloads - QueryPrepared string `protobuf:"bytes,6,opt,name=QueryPrepared,proto3" json:"QueryPrepared,omitempty"` // for Msg - Steps string `protobuf:"bytes,7,opt,name=Steps,proto3" json:"Steps,omitempty"` - ReqExtra map[string]string `protobuf:"bytes,8,rep,name=ReqExtra,proto3" json:"ReqExtra,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` - RollbackReason string `protobuf:"bytes,9,opt,name=RollbackReason,proto3" json:"RollbackReason,omitempty"` -} - -func (x *DtmRequest) Reset() { - *x = DtmRequest{} - if protoimpl.UnsafeEnabled { - mi := &file_dtmgrpc_dtmgpb_dtmgimp_proto_msgTypes[1] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *DtmRequest) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*DtmRequest) ProtoMessage() {} - -func (x *DtmRequest) ProtoReflect() protoreflect.Message { - mi := &file_dtmgrpc_dtmgpb_dtmgimp_proto_msgTypes[1] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use DtmRequest.ProtoReflect.Descriptor instead. -func (*DtmRequest) Descriptor() ([]byte, []int) { - return file_dtmgrpc_dtmgpb_dtmgimp_proto_rawDescGZIP(), []int{1} -} - -func (x *DtmRequest) GetGid() string { - if x != nil { - return x.Gid - } - return "" -} - -func (x *DtmRequest) GetTransType() string { - if x != nil { - return x.TransType - } - return "" -} - -func (x *DtmRequest) GetTransOptions() *DtmTransOptions { - if x != nil { - return x.TransOptions - } - return nil -} - -func (x *DtmRequest) GetCustomedData() string { - if x != nil { - return x.CustomedData - } - return "" -} - -func (x *DtmRequest) GetBinPayloads() [][]byte { - if x != nil { - return x.BinPayloads - } - return nil -} - -func (x *DtmRequest) GetQueryPrepared() string { - if x != nil { - return x.QueryPrepared - } - return "" -} - -func (x *DtmRequest) GetSteps() string { - if x != nil { - return x.Steps - } - return "" -} - -func (x *DtmRequest) GetReqExtra() map[string]string { - if x != nil { - return x.ReqExtra - } - return nil -} - -func (x *DtmRequest) GetRollbackReason() string { - if x != nil { - return x.RollbackReason - } - return "" -} - -type DtmGidReply struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Gid string `protobuf:"bytes,1,opt,name=Gid,proto3" json:"Gid,omitempty"` -} - -func (x *DtmGidReply) Reset() { - *x = DtmGidReply{} - if protoimpl.UnsafeEnabled { - mi := &file_dtmgrpc_dtmgpb_dtmgimp_proto_msgTypes[2] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *DtmGidReply) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*DtmGidReply) ProtoMessage() {} - -func (x *DtmGidReply) ProtoReflect() protoreflect.Message { - mi := &file_dtmgrpc_dtmgpb_dtmgimp_proto_msgTypes[2] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use DtmGidReply.ProtoReflect.Descriptor instead. -func (*DtmGidReply) Descriptor() ([]byte, []int) { - return file_dtmgrpc_dtmgpb_dtmgimp_proto_rawDescGZIP(), []int{2} -} - -func (x *DtmGidReply) GetGid() string { - if x != nil { - return x.Gid - } - return "" -} - -type DtmBranchRequest struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Gid string `protobuf:"bytes,1,opt,name=Gid,proto3" json:"Gid,omitempty"` - TransType string `protobuf:"bytes,2,opt,name=TransType,proto3" json:"TransType,omitempty"` - BranchID string `protobuf:"bytes,3,opt,name=BranchID,proto3" json:"BranchID,omitempty"` - Op string `protobuf:"bytes,4,opt,name=Op,proto3" json:"Op,omitempty"` - Data map[string]string `protobuf:"bytes,5,rep,name=Data,proto3" json:"Data,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` - BusiPayload []byte `protobuf:"bytes,6,opt,name=BusiPayload,proto3" json:"BusiPayload,omitempty"` -} - -func (x *DtmBranchRequest) Reset() { - *x = DtmBranchRequest{} - if protoimpl.UnsafeEnabled { - mi := &file_dtmgrpc_dtmgpb_dtmgimp_proto_msgTypes[3] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *DtmBranchRequest) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*DtmBranchRequest) ProtoMessage() {} - -func (x *DtmBranchRequest) ProtoReflect() protoreflect.Message { - mi := &file_dtmgrpc_dtmgpb_dtmgimp_proto_msgTypes[3] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use DtmBranchRequest.ProtoReflect.Descriptor instead. -func (*DtmBranchRequest) Descriptor() ([]byte, []int) { - return file_dtmgrpc_dtmgpb_dtmgimp_proto_rawDescGZIP(), []int{3} -} - -func (x *DtmBranchRequest) GetGid() string { - if x != nil { - return x.Gid - } - return "" -} - -func (x *DtmBranchRequest) GetTransType() string { - if x != nil { - return x.TransType - } - return "" -} - -func (x *DtmBranchRequest) GetBranchID() string { - if x != nil { - return x.BranchID - } - return "" -} - -func (x *DtmBranchRequest) GetOp() string { - if x != nil { - return x.Op - } - return "" -} - -func (x *DtmBranchRequest) GetData() map[string]string { - if x != nil { - return x.Data - } - return nil -} - -func (x *DtmBranchRequest) GetBusiPayload() []byte { - if x != nil { - return x.BusiPayload - } - return nil -} - -type DtmProgressesReply struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Progresses []*DtmProgress `protobuf:"bytes,1,rep,name=Progresses,proto3" json:"Progresses,omitempty"` -} - -func (x *DtmProgressesReply) Reset() { - *x = DtmProgressesReply{} - if protoimpl.UnsafeEnabled { - mi := &file_dtmgrpc_dtmgpb_dtmgimp_proto_msgTypes[4] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *DtmProgressesReply) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*DtmProgressesReply) ProtoMessage() {} - -func (x *DtmProgressesReply) ProtoReflect() protoreflect.Message { - mi := &file_dtmgrpc_dtmgpb_dtmgimp_proto_msgTypes[4] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use DtmProgressesReply.ProtoReflect.Descriptor instead. -func (*DtmProgressesReply) Descriptor() ([]byte, []int) { - return file_dtmgrpc_dtmgpb_dtmgimp_proto_rawDescGZIP(), []int{4} -} - -func (x *DtmProgressesReply) GetProgresses() []*DtmProgress { - if x != nil { - return x.Progresses - } - return nil -} - -type DtmProgress struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Status string `protobuf:"bytes,1,opt,name=Status,proto3" json:"Status,omitempty"` - BinData []byte `protobuf:"bytes,2,opt,name=BinData,proto3" json:"BinData,omitempty"` - BranchID string `protobuf:"bytes,3,opt,name=BranchID,proto3" json:"BranchID,omitempty"` - Op string `protobuf:"bytes,4,opt,name=Op,proto3" json:"Op,omitempty"` -} - -func (x *DtmProgress) Reset() { - *x = DtmProgress{} - if protoimpl.UnsafeEnabled { - mi := &file_dtmgrpc_dtmgpb_dtmgimp_proto_msgTypes[5] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *DtmProgress) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*DtmProgress) ProtoMessage() {} - -func (x *DtmProgress) ProtoReflect() protoreflect.Message { - mi := &file_dtmgrpc_dtmgpb_dtmgimp_proto_msgTypes[5] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use DtmProgress.ProtoReflect.Descriptor instead. -func (*DtmProgress) Descriptor() ([]byte, []int) { - return file_dtmgrpc_dtmgpb_dtmgimp_proto_rawDescGZIP(), []int{5} -} - -func (x *DtmProgress) GetStatus() string { - if x != nil { - return x.Status - } - return "" -} - -func (x *DtmProgress) GetBinData() []byte { - if x != nil { - return x.BinData - } - return nil -} - -func (x *DtmProgress) GetBranchID() string { - if x != nil { - return x.BranchID - } - return "" -} - -func (x *DtmProgress) GetOp() string { - if x != nil { - return x.Op - } - return "" -} - -var File_dtmgrpc_dtmgpb_dtmgimp_proto protoreflect.FileDescriptor - -var file_dtmgrpc_dtmgpb_dtmgimp_proto_rawDesc = []byte{ - 0x0a, 0x1c, 0x64, 0x74, 0x6d, 0x67, 0x72, 0x70, 0x63, 0x2f, 0x64, 0x74, 0x6d, 0x67, 0x70, 0x62, - 0x2f, 0x64, 0x74, 0x6d, 0x67, 0x69, 0x6d, 0x70, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x07, - 0x64, 0x74, 0x6d, 0x67, 0x69, 0x6d, 0x70, 0x1a, 0x1b, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, - 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x65, 0x6d, 0x70, 0x74, 0x79, 0x2e, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xea, 0x02, 0x0a, 0x0f, 0x44, 0x74, 0x6d, 0x54, 0x72, 0x61, 0x6e, - 0x73, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x1e, 0x0a, 0x0a, 0x57, 0x61, 0x69, 0x74, - 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0a, 0x57, 0x61, - 0x69, 0x74, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x12, 0x24, 0x0a, 0x0d, 0x54, 0x69, 0x6d, 0x65, - 0x6f, 0x75, 0x74, 0x54, 0x6f, 0x46, 0x61, 0x69, 0x6c, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, - 0x0d, 0x54, 0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x54, 0x6f, 0x46, 0x61, 0x69, 0x6c, 0x12, 0x24, - 0x0a, 0x0d, 0x52, 0x65, 0x74, 0x72, 0x79, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x76, 0x61, 0x6c, 0x18, - 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0d, 0x52, 0x65, 0x74, 0x72, 0x79, 0x49, 0x6e, 0x74, 0x65, - 0x72, 0x76, 0x61, 0x6c, 0x12, 0x2e, 0x0a, 0x12, 0x50, 0x61, 0x73, 0x73, 0x74, 0x68, 0x72, 0x6f, - 0x75, 0x67, 0x68, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x18, 0x04, 0x20, 0x03, 0x28, 0x09, - 0x52, 0x12, 0x50, 0x61, 0x73, 0x73, 0x74, 0x68, 0x72, 0x6f, 0x75, 0x67, 0x68, 0x48, 0x65, 0x61, - 0x64, 0x65, 0x72, 0x73, 0x12, 0x51, 0x0a, 0x0d, 0x42, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x48, 0x65, - 0x61, 0x64, 0x65, 0x72, 0x73, 0x18, 0x05, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x2b, 0x2e, 0x64, 0x74, - 0x6d, 0x67, 0x69, 0x6d, 0x70, 0x2e, 0x44, 0x74, 0x6d, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x4f, 0x70, - 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x42, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x48, 0x65, 0x61, 0x64, - 0x65, 0x72, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x0d, 0x42, 0x72, 0x61, 0x6e, 0x63, 0x68, - 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x12, 0x26, 0x0a, 0x0e, 0x52, 0x65, 0x71, 0x75, 0x65, - 0x73, 0x74, 0x54, 0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x18, 0x06, 0x20, 0x01, 0x28, 0x03, 0x52, - 0x0e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x54, 0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x1a, - 0x40, 0x0a, 0x12, 0x42, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, - 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, - 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, - 0x01, 0x22, 0xa0, 0x03, 0x0a, 0x0a, 0x44, 0x74, 0x6d, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, - 0x12, 0x10, 0x0a, 0x03, 0x47, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x47, - 0x69, 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x54, 0x79, 0x70, 0x65, 0x18, - 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x54, 0x79, 0x70, 0x65, - 0x12, 0x3c, 0x0a, 0x0c, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, - 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x18, 0x2e, 0x64, 0x74, 0x6d, 0x67, 0x69, 0x6d, 0x70, - 0x2e, 0x44, 0x74, 0x6d, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, - 0x52, 0x0c, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x22, - 0x0a, 0x0c, 0x43, 0x75, 0x73, 0x74, 0x6f, 0x6d, 0x65, 0x64, 0x44, 0x61, 0x74, 0x61, 0x18, 0x04, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x43, 0x75, 0x73, 0x74, 0x6f, 0x6d, 0x65, 0x64, 0x44, 0x61, - 0x74, 0x61, 0x12, 0x20, 0x0a, 0x0b, 0x42, 0x69, 0x6e, 0x50, 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64, - 0x73, 0x18, 0x05, 0x20, 0x03, 0x28, 0x0c, 0x52, 0x0b, 0x42, 0x69, 0x6e, 0x50, 0x61, 0x79, 0x6c, - 0x6f, 0x61, 0x64, 0x73, 0x12, 0x24, 0x0a, 0x0d, 0x51, 0x75, 0x65, 0x72, 0x79, 0x50, 0x72, 0x65, - 0x70, 0x61, 0x72, 0x65, 0x64, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x51, 0x75, 0x65, - 0x72, 0x79, 0x50, 0x72, 0x65, 0x70, 0x61, 0x72, 0x65, 0x64, 0x12, 0x14, 0x0a, 0x05, 0x53, 0x74, - 0x65, 0x70, 0x73, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x53, 0x74, 0x65, 0x70, 0x73, - 0x12, 0x3d, 0x0a, 0x08, 0x52, 0x65, 0x71, 0x45, 0x78, 0x74, 0x72, 0x61, 0x18, 0x08, 0x20, 0x03, - 0x28, 0x0b, 0x32, 0x21, 0x2e, 0x64, 0x74, 0x6d, 0x67, 0x69, 0x6d, 0x70, 0x2e, 0x44, 0x74, 0x6d, - 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x2e, 0x52, 0x65, 0x71, 0x45, 0x78, 0x74, 0x72, 0x61, - 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x08, 0x52, 0x65, 0x71, 0x45, 0x78, 0x74, 0x72, 0x61, 0x12, - 0x26, 0x0a, 0x0e, 0x52, 0x6f, 0x6c, 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x52, 0x65, 0x61, 0x73, 0x6f, - 0x6e, 0x18, 0x09, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0e, 0x52, 0x6f, 0x6c, 0x6c, 0x62, 0x61, 0x63, - 0x6b, 0x52, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x1a, 0x3b, 0x0a, 0x0d, 0x52, 0x65, 0x71, 0x45, 0x78, - 0x74, 0x72, 0x61, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, - 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, - 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, - 0x3a, 0x02, 0x38, 0x01, 0x22, 0x1f, 0x0a, 0x0b, 0x44, 0x74, 0x6d, 0x47, 0x69, 0x64, 0x52, 0x65, - 0x70, 0x6c, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x47, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x03, 0x47, 0x69, 0x64, 0x22, 0x82, 0x02, 0x0a, 0x10, 0x44, 0x74, 0x6d, 0x42, 0x72, 0x61, - 0x6e, 0x63, 0x68, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x10, 0x0a, 0x03, 0x47, 0x69, - 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x47, 0x69, 0x64, 0x12, 0x1c, 0x0a, 0x09, - 0x54, 0x72, 0x61, 0x6e, 0x73, 0x54, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, - 0x09, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x42, 0x72, - 0x61, 0x6e, 0x63, 0x68, 0x49, 0x44, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x42, 0x72, - 0x61, 0x6e, 0x63, 0x68, 0x49, 0x44, 0x12, 0x0e, 0x0a, 0x02, 0x4f, 0x70, 0x18, 0x04, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x02, 0x4f, 0x70, 0x12, 0x37, 0x0a, 0x04, 0x44, 0x61, 0x74, 0x61, 0x18, 0x05, - 0x20, 0x03, 0x28, 0x0b, 0x32, 0x23, 0x2e, 0x64, 0x74, 0x6d, 0x67, 0x69, 0x6d, 0x70, 0x2e, 0x44, - 0x74, 0x6d, 0x42, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x2e, - 0x44, 0x61, 0x74, 0x61, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x04, 0x44, 0x61, 0x74, 0x61, 0x12, - 0x20, 0x0a, 0x0b, 0x42, 0x75, 0x73, 0x69, 0x50, 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64, 0x18, 0x06, - 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0b, 0x42, 0x75, 0x73, 0x69, 0x50, 0x61, 0x79, 0x6c, 0x6f, 0x61, - 0x64, 0x1a, 0x37, 0x0a, 0x09, 0x44, 0x61, 0x74, 0x61, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, - 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, - 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, - 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0x4a, 0x0a, 0x12, 0x44, 0x74, - 0x6d, 0x50, 0x72, 0x6f, 0x67, 0x72, 0x65, 0x73, 0x73, 0x65, 0x73, 0x52, 0x65, 0x70, 0x6c, 0x79, - 0x12, 0x34, 0x0a, 0x0a, 0x50, 0x72, 0x6f, 0x67, 0x72, 0x65, 0x73, 0x73, 0x65, 0x73, 0x18, 0x01, - 0x20, 0x03, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x64, 0x74, 0x6d, 0x67, 0x69, 0x6d, 0x70, 0x2e, 0x44, - 0x74, 0x6d, 0x50, 0x72, 0x6f, 0x67, 0x72, 0x65, 0x73, 0x73, 0x52, 0x0a, 0x50, 0x72, 0x6f, 0x67, - 0x72, 0x65, 0x73, 0x73, 0x65, 0x73, 0x22, 0x6b, 0x0a, 0x0b, 0x44, 0x74, 0x6d, 0x50, 0x72, 0x6f, - 0x67, 0x72, 0x65, 0x73, 0x73, 0x12, 0x16, 0x0a, 0x06, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, - 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x18, 0x0a, - 0x07, 0x42, 0x69, 0x6e, 0x44, 0x61, 0x74, 0x61, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x07, - 0x42, 0x69, 0x6e, 0x44, 0x61, 0x74, 0x61, 0x12, 0x1a, 0x0a, 0x08, 0x42, 0x72, 0x61, 0x6e, 0x63, - 0x68, 0x49, 0x44, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x42, 0x72, 0x61, 0x6e, 0x63, - 0x68, 0x49, 0x44, 0x12, 0x0e, 0x0a, 0x02, 0x4f, 0x70, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, - 0x02, 0x4f, 0x70, 0x32, 0xf8, 0x02, 0x0a, 0x03, 0x44, 0x74, 0x6d, 0x12, 0x38, 0x0a, 0x06, 0x4e, - 0x65, 0x77, 0x47, 0x69, 0x64, 0x12, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x14, 0x2e, - 0x64, 0x74, 0x6d, 0x67, 0x69, 0x6d, 0x70, 0x2e, 0x44, 0x74, 0x6d, 0x47, 0x69, 0x64, 0x52, 0x65, - 0x70, 0x6c, 0x79, 0x22, 0x00, 0x12, 0x37, 0x0a, 0x06, 0x53, 0x75, 0x62, 0x6d, 0x69, 0x74, 0x12, - 0x13, 0x2e, 0x64, 0x74, 0x6d, 0x67, 0x69, 0x6d, 0x70, 0x2e, 0x44, 0x74, 0x6d, 0x52, 0x65, 0x71, - 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x22, 0x00, 0x12, 0x38, - 0x0a, 0x07, 0x50, 0x72, 0x65, 0x70, 0x61, 0x72, 0x65, 0x12, 0x13, 0x2e, 0x64, 0x74, 0x6d, 0x67, - 0x69, 0x6d, 0x70, 0x2e, 0x44, 0x74, 0x6d, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, - 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, - 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x22, 0x00, 0x12, 0x36, 0x0a, 0x05, 0x41, 0x62, 0x6f, 0x72, - 0x74, 0x12, 0x13, 0x2e, 0x64, 0x74, 0x6d, 0x67, 0x69, 0x6d, 0x70, 0x2e, 0x44, 0x74, 0x6d, 0x52, - 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, - 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x22, 0x00, - 0x12, 0x45, 0x0a, 0x0e, 0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x42, 0x72, 0x61, 0x6e, - 0x63, 0x68, 0x12, 0x19, 0x2e, 0x64, 0x74, 0x6d, 0x67, 0x69, 0x6d, 0x70, 0x2e, 0x44, 0x74, 0x6d, - 0x42, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, - 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, - 0x45, 0x6d, 0x70, 0x74, 0x79, 0x22, 0x00, 0x12, 0x45, 0x0a, 0x0f, 0x50, 0x72, 0x65, 0x70, 0x61, - 0x72, 0x65, 0x57, 0x6f, 0x72, 0x6b, 0x66, 0x6c, 0x6f, 0x77, 0x12, 0x13, 0x2e, 0x64, 0x74, 0x6d, - 0x67, 0x69, 0x6d, 0x70, 0x2e, 0x44, 0x74, 0x6d, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, - 0x1b, 0x2e, 0x64, 0x74, 0x6d, 0x67, 0x69, 0x6d, 0x70, 0x2e, 0x44, 0x74, 0x6d, 0x50, 0x72, 0x6f, - 0x67, 0x72, 0x65, 0x73, 0x73, 0x65, 0x73, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x00, 0x42, 0x0a, - 0x5a, 0x08, 0x2e, 0x2f, 0x64, 0x74, 0x6d, 0x67, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x33, -} - -var ( - file_dtmgrpc_dtmgpb_dtmgimp_proto_rawDescOnce sync.Once - file_dtmgrpc_dtmgpb_dtmgimp_proto_rawDescData = file_dtmgrpc_dtmgpb_dtmgimp_proto_rawDesc -) - -func file_dtmgrpc_dtmgpb_dtmgimp_proto_rawDescGZIP() []byte { - file_dtmgrpc_dtmgpb_dtmgimp_proto_rawDescOnce.Do(func() { - file_dtmgrpc_dtmgpb_dtmgimp_proto_rawDescData = protoimpl.X.CompressGZIP(file_dtmgrpc_dtmgpb_dtmgimp_proto_rawDescData) - }) - return file_dtmgrpc_dtmgpb_dtmgimp_proto_rawDescData -} - -var file_dtmgrpc_dtmgpb_dtmgimp_proto_msgTypes = make([]protoimpl.MessageInfo, 9) -var file_dtmgrpc_dtmgpb_dtmgimp_proto_goTypes = []interface{}{ - (*DtmTransOptions)(nil), // 0: dtmgimp.DtmTransOptions - (*DtmRequest)(nil), // 1: dtmgimp.DtmRequest - (*DtmGidReply)(nil), // 2: dtmgimp.DtmGidReply - (*DtmBranchRequest)(nil), // 3: dtmgimp.DtmBranchRequest - (*DtmProgressesReply)(nil), // 4: dtmgimp.DtmProgressesReply - (*DtmProgress)(nil), // 5: dtmgimp.DtmProgress - nil, // 6: dtmgimp.DtmTransOptions.BranchHeadersEntry - nil, // 7: dtmgimp.DtmRequest.ReqExtraEntry - nil, // 8: dtmgimp.DtmBranchRequest.DataEntry - (*emptypb.Empty)(nil), // 9: google.protobuf.Empty -} -var file_dtmgrpc_dtmgpb_dtmgimp_proto_depIdxs = []int32{ - 6, // 0: dtmgimp.DtmTransOptions.BranchHeaders:type_name -> dtmgimp.DtmTransOptions.BranchHeadersEntry - 0, // 1: dtmgimp.DtmRequest.TransOptions:type_name -> dtmgimp.DtmTransOptions - 7, // 2: dtmgimp.DtmRequest.ReqExtra:type_name -> dtmgimp.DtmRequest.ReqExtraEntry - 8, // 3: dtmgimp.DtmBranchRequest.Data:type_name -> dtmgimp.DtmBranchRequest.DataEntry - 5, // 4: dtmgimp.DtmProgressesReply.Progresses:type_name -> dtmgimp.DtmProgress - 9, // 5: dtmgimp.Dtm.NewGid:input_type -> google.protobuf.Empty - 1, // 6: dtmgimp.Dtm.Submit:input_type -> dtmgimp.DtmRequest - 1, // 7: dtmgimp.Dtm.Prepare:input_type -> dtmgimp.DtmRequest - 1, // 8: dtmgimp.Dtm.Abort:input_type -> dtmgimp.DtmRequest - 3, // 9: dtmgimp.Dtm.RegisterBranch:input_type -> dtmgimp.DtmBranchRequest - 1, // 10: dtmgimp.Dtm.PrepareWorkflow:input_type -> dtmgimp.DtmRequest - 2, // 11: dtmgimp.Dtm.NewGid:output_type -> dtmgimp.DtmGidReply - 9, // 12: dtmgimp.Dtm.Submit:output_type -> google.protobuf.Empty - 9, // 13: dtmgimp.Dtm.Prepare:output_type -> google.protobuf.Empty - 9, // 14: dtmgimp.Dtm.Abort:output_type -> google.protobuf.Empty - 9, // 15: dtmgimp.Dtm.RegisterBranch:output_type -> google.protobuf.Empty - 4, // 16: dtmgimp.Dtm.PrepareWorkflow:output_type -> dtmgimp.DtmProgressesReply - 11, // [11:17] is the sub-list for method output_type - 5, // [5:11] is the sub-list for method input_type - 5, // [5:5] is the sub-list for extension type_name - 5, // [5:5] is the sub-list for extension extendee - 0, // [0:5] is the sub-list for field type_name -} - -func init() { file_dtmgrpc_dtmgpb_dtmgimp_proto_init() } -func file_dtmgrpc_dtmgpb_dtmgimp_proto_init() { - if File_dtmgrpc_dtmgpb_dtmgimp_proto != nil { - return - } - if !protoimpl.UnsafeEnabled { - file_dtmgrpc_dtmgpb_dtmgimp_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*DtmTransOptions); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_dtmgrpc_dtmgpb_dtmgimp_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*DtmRequest); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_dtmgrpc_dtmgpb_dtmgimp_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*DtmGidReply); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_dtmgrpc_dtmgpb_dtmgimp_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*DtmBranchRequest); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_dtmgrpc_dtmgpb_dtmgimp_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*DtmProgressesReply); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_dtmgrpc_dtmgpb_dtmgimp_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*DtmProgress); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - } - type x struct{} - out := protoimpl.TypeBuilder{ - File: protoimpl.DescBuilder{ - GoPackagePath: reflect.TypeOf(x{}).PkgPath(), - RawDescriptor: file_dtmgrpc_dtmgpb_dtmgimp_proto_rawDesc, - NumEnums: 0, - NumMessages: 9, - NumExtensions: 0, - NumServices: 1, - }, - GoTypes: file_dtmgrpc_dtmgpb_dtmgimp_proto_goTypes, - DependencyIndexes: file_dtmgrpc_dtmgpb_dtmgimp_proto_depIdxs, - MessageInfos: file_dtmgrpc_dtmgpb_dtmgimp_proto_msgTypes, - }.Build() - File_dtmgrpc_dtmgpb_dtmgimp_proto = out.File - file_dtmgrpc_dtmgpb_dtmgimp_proto_rawDesc = nil - file_dtmgrpc_dtmgpb_dtmgimp_proto_goTypes = nil - file_dtmgrpc_dtmgpb_dtmgimp_proto_depIdxs = nil -} diff --git a/dtmgrpc/workflow/wfpb/wf.pb.go b/dtmgrpc/workflow/wfpb/wf.pb.go deleted file mode 100644 index fa8a278..0000000 --- a/dtmgrpc/workflow/wfpb/wf.pb.go +++ /dev/null @@ -1,153 +0,0 @@ -// Code generated by protoc-gen-go. DO NOT EDIT. -// versions: -// protoc-gen-go v1.28.0 -// protoc v3.17.3 -// source: dtmgrpc/workflow/wfpb/wf.proto - -package wfpb - -import ( - protoreflect "google.golang.org/protobuf/reflect/protoreflect" - protoimpl "google.golang.org/protobuf/runtime/protoimpl" - emptypb "google.golang.org/protobuf/types/known/emptypb" - reflect "reflect" - sync "sync" -) - -const ( - // Verify that this generated code is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) - // Verify that runtime/protoimpl is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) -) - -type WorkflowData struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Data []byte `protobuf:"bytes,1,opt,name=Data,proto3" json:"Data,omitempty"` -} - -func (x *WorkflowData) Reset() { - *x = WorkflowData{} - if protoimpl.UnsafeEnabled { - mi := &file_dtmgrpc_workflow_wfpb_wf_proto_msgTypes[0] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *WorkflowData) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*WorkflowData) ProtoMessage() {} - -func (x *WorkflowData) ProtoReflect() protoreflect.Message { - mi := &file_dtmgrpc_workflow_wfpb_wf_proto_msgTypes[0] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use WorkflowData.ProtoReflect.Descriptor instead. -func (*WorkflowData) Descriptor() ([]byte, []int) { - return file_dtmgrpc_workflow_wfpb_wf_proto_rawDescGZIP(), []int{0} -} - -func (x *WorkflowData) GetData() []byte { - if x != nil { - return x.Data - } - return nil -} - -var File_dtmgrpc_workflow_wfpb_wf_proto protoreflect.FileDescriptor - -var file_dtmgrpc_workflow_wfpb_wf_proto_rawDesc = []byte{ - 0x0a, 0x1e, 0x64, 0x74, 0x6d, 0x67, 0x72, 0x70, 0x63, 0x2f, 0x77, 0x6f, 0x72, 0x6b, 0x66, 0x6c, - 0x6f, 0x77, 0x2f, 0x77, 0x66, 0x70, 0x62, 0x2f, 0x77, 0x66, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x12, 0x08, 0x77, 0x6f, 0x72, 0x6b, 0x66, 0x6c, 0x6f, 0x77, 0x1a, 0x1b, 0x67, 0x6f, 0x6f, 0x67, - 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x65, 0x6d, 0x70, 0x74, - 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x22, 0x0a, 0x0c, 0x57, 0x6f, 0x72, 0x6b, 0x66, - 0x6c, 0x6f, 0x77, 0x44, 0x61, 0x74, 0x61, 0x12, 0x12, 0x0a, 0x04, 0x44, 0x61, 0x74, 0x61, 0x18, - 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x04, 0x44, 0x61, 0x74, 0x61, 0x32, 0x47, 0x0a, 0x08, 0x57, - 0x6f, 0x72, 0x6b, 0x66, 0x6c, 0x6f, 0x77, 0x12, 0x3b, 0x0a, 0x07, 0x45, 0x78, 0x65, 0x63, 0x75, - 0x74, 0x65, 0x12, 0x16, 0x2e, 0x77, 0x6f, 0x72, 0x6b, 0x66, 0x6c, 0x6f, 0x77, 0x2e, 0x57, 0x6f, - 0x72, 0x6b, 0x66, 0x6c, 0x6f, 0x77, 0x44, 0x61, 0x74, 0x61, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, - 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, - 0x74, 0x79, 0x22, 0x00, 0x42, 0x08, 0x5a, 0x06, 0x2e, 0x2f, 0x77, 0x66, 0x70, 0x62, 0x62, 0x06, - 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, -} - -var ( - file_dtmgrpc_workflow_wfpb_wf_proto_rawDescOnce sync.Once - file_dtmgrpc_workflow_wfpb_wf_proto_rawDescData = file_dtmgrpc_workflow_wfpb_wf_proto_rawDesc -) - -func file_dtmgrpc_workflow_wfpb_wf_proto_rawDescGZIP() []byte { - file_dtmgrpc_workflow_wfpb_wf_proto_rawDescOnce.Do(func() { - file_dtmgrpc_workflow_wfpb_wf_proto_rawDescData = protoimpl.X.CompressGZIP(file_dtmgrpc_workflow_wfpb_wf_proto_rawDescData) - }) - return file_dtmgrpc_workflow_wfpb_wf_proto_rawDescData -} - -var file_dtmgrpc_workflow_wfpb_wf_proto_msgTypes = make([]protoimpl.MessageInfo, 1) -var file_dtmgrpc_workflow_wfpb_wf_proto_goTypes = []interface{}{ - (*WorkflowData)(nil), // 0: workflow.WorkflowData - (*emptypb.Empty)(nil), // 1: google.protobuf.Empty -} -var file_dtmgrpc_workflow_wfpb_wf_proto_depIdxs = []int32{ - 0, // 0: workflow.Workflow.Execute:input_type -> workflow.WorkflowData - 1, // 1: workflow.Workflow.Execute:output_type -> google.protobuf.Empty - 1, // [1:2] is the sub-list for method output_type - 0, // [0:1] is the sub-list for method input_type - 0, // [0:0] is the sub-list for extension type_name - 0, // [0:0] is the sub-list for extension extendee - 0, // [0:0] is the sub-list for field type_name -} - -func init() { file_dtmgrpc_workflow_wfpb_wf_proto_init() } -func file_dtmgrpc_workflow_wfpb_wf_proto_init() { - if File_dtmgrpc_workflow_wfpb_wf_proto != nil { - return - } - if !protoimpl.UnsafeEnabled { - file_dtmgrpc_workflow_wfpb_wf_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*WorkflowData); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - } - type x struct{} - out := protoimpl.TypeBuilder{ - File: protoimpl.DescBuilder{ - GoPackagePath: reflect.TypeOf(x{}).PkgPath(), - RawDescriptor: file_dtmgrpc_workflow_wfpb_wf_proto_rawDesc, - NumEnums: 0, - NumMessages: 1, - NumExtensions: 0, - NumServices: 1, - }, - GoTypes: file_dtmgrpc_workflow_wfpb_wf_proto_goTypes, - DependencyIndexes: file_dtmgrpc_workflow_wfpb_wf_proto_depIdxs, - MessageInfos: file_dtmgrpc_workflow_wfpb_wf_proto_msgTypes, - }.Build() - File_dtmgrpc_workflow_wfpb_wf_proto = out.File - file_dtmgrpc_workflow_wfpb_wf_proto_rawDesc = nil - file_dtmgrpc_workflow_wfpb_wf_proto_goTypes = nil - file_dtmgrpc_workflow_wfpb_wf_proto_depIdxs = nil -} diff --git a/dtmsvr/api.go b/dtmsvr/api.go index ae8c32d..a1c80e9 100644 --- a/dtmsvr/api.go +++ b/dtmsvr/api.go @@ -8,10 +8,11 @@ package dtmsvr import ( "fmt" + "time" - "github.com/dtm-labs/dtm/dtmcli" - "github.com/dtm-labs/dtm/dtmcli/dtmimp" - "github.com/dtm-labs/dtm/dtmcli/logger" + "github.com/dtm-labs/dtm/client/dtmcli" + "github.com/dtm-labs/dtm/client/dtmcli/dtmimp" + "github.com/dtm-labs/dtm/client/dtmcli/logger" "github.com/dtm-labs/dtm/dtmsvr/storage" ) @@ -19,10 +20,12 @@ import ( var Version = "" func svcSubmit(t *TransGlobal) interface{} { - t.Status = dtmcli.StatusSubmitted - if t.ReqExtra != nil && t.ReqExtra["status"] != "" { - t.Status = t.ReqExtra["status"] + if t.TransType == "workflow" { + t.Status = dtmcli.StatusPrepared + t.changeStatus(t.ReqExtra["status"], withRollbackReason(t.ReqExtra["rollback_reason"])) + return nil } + t.Status = dtmcli.StatusSubmitted branches, err := t.saveNew() if err == storage.ErrUniqueConflict { @@ -50,13 +53,14 @@ func svcPrepare(t *TransGlobal) interface{} { return err } -func svcPrepareWorkflow(t *TransGlobal) ([]TransBranch, error) { +func svcPrepareWorkflow(t *TransGlobal) (*storage.TransGlobalStore, []TransBranch, error) { t.Status = dtmcli.StatusPrepared _, err := t.saveNew() if err == storage.ErrUniqueConflict { // transaction exists, query the branches - return GetStore().FindBranches(t.Gid), nil + st := GetStore() + return st.FindTransGlobalStore(t.Gid), st.FindBranches(t.Gid), nil } - return []TransBranch{}, err + return &t.TransGlobalStore, []TransBranch{}, err } func svcAbort(t *TransGlobal) interface{} { @@ -95,6 +99,17 @@ func svcRegisterBranch(transType string, branch *TransBranch, data map[string]st branches[1].Op = dtmimp.OpCommit branches[1].URL = data["url"] } else if transType == "workflow" { + if data["sync"] == "" && conf.UpdateBranchSync == 0 { + now := time.Now() + updateBranchAsyncChan <- branchStatus{ + gid: branch.Gid, + branchID: branch.BranchID, + op: data["op"], + status: data["status"], + finishTime: &now, + } + return nil + } branches = []TransBranch{*branch} branches[0].Status = data["status"] branches[0].Op = data["op"] @@ -108,7 +123,7 @@ func svcRegisterBranch(transType string, branch *TransBranch, data map[string]st if err == storage.ErrNotFound { msg := fmt.Sprintf("no trans with gid: %s status: %s found", branch.Gid, dtmcli.StatusPrepared) logger.Errorf(msg) - return fmt.Errorf("message: %s %w", msg, dtmcli.ErrFailure) + return dtmcli.ErrorMessage2Error(msg, dtmcli.ErrFailure) } logger.Infof("LockGlobalSaveBranches result: %v: gid: %s old status: %s branches: %s", err, branch.Gid, dtmcli.StatusPrepared, dtmimp.MustMarshalString(branches)) diff --git a/dtmsvr/api_grpc.go b/dtmsvr/api_grpc.go index 9989577..6fe216f 100644 --- a/dtmsvr/api_grpc.go +++ b/dtmsvr/api_grpc.go @@ -9,9 +9,9 @@ package dtmsvr import ( "context" - "github.com/dtm-labs/dtm/dtmcli" - "github.com/dtm-labs/dtm/dtmgrpc" - pb "github.com/dtm-labs/dtm/dtmgrpc/dtmgpb" + "github.com/dtm-labs/dtm/client/dtmcli" + "github.com/dtm-labs/dtm/client/dtmgrpc" + pb "github.com/dtm-labs/dtm/client/dtmgrpc/dtmgpb" "google.golang.org/protobuf/types/known/emptypb" ) @@ -50,8 +50,13 @@ func (s *dtmServer) RegisterBranch(ctx context.Context, in *pb.DtmBranchRequest) } func (s *dtmServer) PrepareWorkflow(ctx context.Context, in *pb.DtmRequest) (*pb.DtmProgressesReply, error) { - branches, err := svcPrepareWorkflow(TransFromDtmRequest(ctx, in)) + trans, branches, err := svcPrepareWorkflow(TransFromDtmRequest(ctx, in)) reply := &pb.DtmProgressesReply{ + Transaction: &pb.DtmTransaction{ + Gid: trans.Gid, + Status: trans.Status, + RollbackReason: trans.RollbackReason, + }, Progresses: []*pb.DtmProgress{}, } for _, b := range branches { diff --git a/dtmsvr/api_http.go b/dtmsvr/api_http.go index 563006c..3e9763b 100644 --- a/dtmsvr/api_http.go +++ b/dtmsvr/api_http.go @@ -11,8 +11,8 @@ import ( "strconv" "time" - "github.com/dtm-labs/dtm/dtmcli" - "github.com/dtm-labs/dtm/dtmcli/dtmimp" + "github.com/dtm-labs/dtm/client/dtmcli" + "github.com/dtm-labs/dtm/client/dtmcli/dtmimp" "github.com/dtm-labs/dtm/dtmutil" "github.com/gin-gonic/gin" "github.com/prometheus/client_golang/prometheus/promhttp" @@ -87,11 +87,11 @@ func query(c *gin.Context) interface{} { } func prepareWorkflow(c *gin.Context) interface{} { - branches, err := svcPrepareWorkflow(TransFromContext(c)) + trans, branches, err := svcPrepareWorkflow(TransFromContext(c)) if err != nil { return err } - return branches + return map[string]interface{}{"Transaction": trans, "Progresses": branches} } func all(c *gin.Context) interface{} { diff --git a/dtmsvr/api_json_rpc.go b/dtmsvr/api_json_rpc.go index fc211d2..bbbe693 100644 --- a/dtmsvr/api_json_rpc.go +++ b/dtmsvr/api_json_rpc.go @@ -6,9 +6,9 @@ import ( "fmt" "time" - "github.com/dtm-labs/dtm/dtmcli" - "github.com/dtm-labs/dtm/dtmcli/dtmimp" - "github.com/dtm-labs/dtm/dtmcli/logger" + "github.com/dtm-labs/dtm/client/dtmcli" + "github.com/dtm-labs/dtm/client/dtmcli/dtmimp" + "github.com/dtm-labs/dtm/client/dtmcli/logger" "github.com/gin-gonic/gin" ) diff --git a/dtmsvr/config/config.go b/dtmsvr/config/config.go index 0ae4b41..7a0e1a7 100644 --- a/dtmsvr/config/config.go +++ b/dtmsvr/config/config.go @@ -4,8 +4,8 @@ import ( "encoding/json" "io/ioutil" - "github.com/dtm-labs/dtm/dtmcli" - "github.com/dtm-labs/dtm/dtmcli/logger" + "github.com/dtm-labs/dtm/client/dtmcli" + "github.com/dtm-labs/dtm/client/dtmcli/logger" "gopkg.in/yaml.v3" ) @@ -95,6 +95,7 @@ type Type struct { UpdateBranchAsyncGoroutineNum int64 `yaml:"UpdateBranchAsyncGoroutineNum" default:"1"` LogLevel string `yaml:"LogLevel" default:"info"` Log Log `yaml:"Log"` + TimeZoneOffset string `yaml:"TimeZoneOffset"` } // Config config diff --git a/dtmsvr/config/config_utils.go b/dtmsvr/config/config_utils.go index fa27cc7..8e5c011 100644 --- a/dtmsvr/config/config_utils.go +++ b/dtmsvr/config/config_utils.go @@ -8,7 +8,7 @@ import ( "regexp" "strings" - "github.com/dtm-labs/dtm/dtmcli/dtmimp" + "github.com/dtm-labs/dtm/client/dtmcli/dtmimp" ) func loadFromEnv(prefix string, conf interface{}) { diff --git a/dtmsvr/cron.go b/dtmsvr/cron.go index 685d2cd..c93ec72 100644 --- a/dtmsvr/cron.go +++ b/dtmsvr/cron.go @@ -13,9 +13,9 @@ import ( "runtime/debug" "time" - "github.com/dtm-labs/dtm/dtmcli" - "github.com/dtm-labs/dtm/dtmcli/dtmimp" - "github.com/dtm-labs/dtm/dtmcli/logger" + "github.com/dtm-labs/dtm/client/dtmcli" + "github.com/dtm-labs/dtm/client/dtmcli/dtmimp" + "github.com/dtm-labs/dtm/client/dtmcli/logger" ) // NowForwardDuration will be set in test, trans may be timeout diff --git a/dtmsvr/entry/main.go b/dtmsvr/entry/main.go index 14d1247..df91118 100644 --- a/dtmsvr/entry/main.go +++ b/dtmsvr/entry/main.go @@ -5,8 +5,10 @@ import ( "fmt" "os" "path/filepath" + "time" - "github.com/dtm-labs/dtm/dtmcli/logger" + "github.com/dtm-labs/dtm/client/dtmcli/dtmimp" + "github.com/dtm-labs/dtm/client/dtmcli/logger" "github.com/dtm-labs/dtm/dtmsvr" "github.com/dtm-labs/dtm/dtmsvr/config" "github.com/dtm-labs/dtm/dtmsvr/storage/registry" @@ -43,6 +45,9 @@ func Main(version *string) (*gin.Engine, *config.Type) { } logger.Infof("dtm version is: %s", *version) config.MustLoadConfig(*confFile) + if config.Config.TimeZoneOffset != "" { + time.Local = time.FixedZone("UTC", dtmimp.MustAtoi(config.Config.TimeZoneOffset)*3600) + } conf := &config.Config if *isDebug { conf.LogLevel = "debug" diff --git a/dtmsvr/storage/boltdb/boltdb.go b/dtmsvr/storage/boltdb/boltdb.go index 65571af..29dcebd 100644 --- a/dtmsvr/storage/boltdb/boltdb.go +++ b/dtmsvr/storage/boltdb/boltdb.go @@ -11,8 +11,8 @@ import ( "strings" "time" - "github.com/dtm-labs/dtm/dtmcli/dtmimp" - "github.com/dtm-labs/dtm/dtmcli/logger" + "github.com/dtm-labs/dtm/client/dtmcli/dtmimp" + "github.com/dtm-labs/dtm/client/dtmcli/logger" "github.com/dtm-labs/dtm/dtmsvr/storage" "github.com/dtm-labs/dtm/dtmutil" bolt "go.etcd.io/bbolt" diff --git a/dtmsvr/storage/boltdb/boltdb_test.go b/dtmsvr/storage/boltdb/boltdb_test.go index 70048ea..e89a3e4 100644 --- a/dtmsvr/storage/boltdb/boltdb_test.go +++ b/dtmsvr/storage/boltdb/boltdb_test.go @@ -14,7 +14,7 @@ import ( . "github.com/onsi/gomega" bolt "go.etcd.io/bbolt" - "github.com/dtm-labs/dtm/dtmcli/dtmimp" + "github.com/dtm-labs/dtm/client/dtmcli/dtmimp" "github.com/dtm-labs/dtm/dtmsvr/storage" ) diff --git a/dtmsvr/storage/redis/redis.go b/dtmsvr/storage/redis/redis.go index 6ff5869..b1e1d7a 100644 --- a/dtmsvr/storage/redis/redis.go +++ b/dtmsvr/storage/redis/redis.go @@ -15,8 +15,8 @@ import ( "github.com/go-redis/redis/v8" - "github.com/dtm-labs/dtm/dtmcli/dtmimp" - "github.com/dtm-labs/dtm/dtmcli/logger" + "github.com/dtm-labs/dtm/client/dtmcli/dtmimp" + "github.com/dtm-labs/dtm/client/dtmcli/logger" "github.com/dtm-labs/dtm/dtmsvr/config" "github.com/dtm-labs/dtm/dtmsvr/storage" "github.com/dtm-labs/dtm/dtmutil" diff --git a/dtmsvr/storage/registry/registry.go b/dtmsvr/storage/registry/registry.go index f09692f..afa86d6 100644 --- a/dtmsvr/storage/registry/registry.go +++ b/dtmsvr/storage/registry/registry.go @@ -3,7 +3,7 @@ package registry import ( "time" - "github.com/dtm-labs/dtm/dtmcli/logger" + "github.com/dtm-labs/dtm/client/dtmcli/logger" "github.com/dtm-labs/dtm/dtmsvr/config" "github.com/dtm-labs/dtm/dtmsvr/storage" diff --git a/dtmsvr/storage/sql/sql.go b/dtmsvr/storage/sql/sql.go index 7628623..d4f8f84 100644 --- a/dtmsvr/storage/sql/sql.go +++ b/dtmsvr/storage/sql/sql.go @@ -11,7 +11,7 @@ import ( "math" "time" - "github.com/dtm-labs/dtm/dtmcli/dtmimp" + "github.com/dtm-labs/dtm/client/dtmcli/dtmimp" "github.com/dtm-labs/dtm/dtmsvr/config" "github.com/dtm-labs/dtm/dtmsvr/storage" "github.com/dtm-labs/dtm/dtmutil" @@ -77,7 +77,7 @@ func (s *Store) FindBranches(gid string) []storage.TransBranchStore { // UpdateBranches update branches info func (s *Store) UpdateBranches(branches []storage.TransBranchStore, updates []string) (int, error) { db := dbGet().Clauses(clause.OnConflict{ - OnConstraint: "trans_branch_op_pkey", + OnConstraint: "gid_branch_uniq", DoUpdates: clause.AssignmentColumns(updates), }).Create(branches) return int(db.RowsAffected), db.Error diff --git a/dtmsvr/storage/trans.go b/dtmsvr/storage/trans.go index c2b3c8b..152b01f 100644 --- a/dtmsvr/storage/trans.go +++ b/dtmsvr/storage/trans.go @@ -9,8 +9,8 @@ package storage import ( "time" - "github.com/dtm-labs/dtm/dtmcli" - "github.com/dtm-labs/dtm/dtmcli/dtmimp" + "github.com/dtm-labs/dtm/client/dtmcli" + "github.com/dtm-labs/dtm/client/dtmcli/dtmimp" "github.com/dtm-labs/dtm/dtmutil" ) diff --git a/dtmsvr/svr.go b/dtmsvr/svr.go index eb5c221..b5c7604 100644 --- a/dtmsvr/svr.go +++ b/dtmsvr/svr.go @@ -12,16 +12,18 @@ import ( "net" "time" - "github.com/dtm-labs/dtm/dtmgrpc" + "github.com/dtm-labs/dtm/client/dtmgrpc" "github.com/gin-gonic/gin" - "github.com/dtm-labs/dtm/dtmcli" - "github.com/dtm-labs/dtm/dtmcli/logger" - "github.com/dtm-labs/dtm/dtmgrpc/dtmgimp" - "github.com/dtm-labs/dtm/dtmgrpc/dtmgpb" + "github.com/dtm-labs/dtm/client/dtmcli" + "github.com/dtm-labs/dtm/client/dtmcli/logger" + "github.com/dtm-labs/dtm/client/dtmgrpc/dtmgimp" + "github.com/dtm-labs/dtm/client/dtmgrpc/dtmgpb" "github.com/dtm-labs/dtm/dtmutil" "github.com/dtm-labs/dtmdriver" "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" ) // StartSvr StartSvr @@ -56,7 +58,7 @@ func StartSvr() *gin.Engine { // start grpc server lis, err := net.Listen("tcp", fmt.Sprintf(":%d", conf.GrpcPort)) logger.FatalIfError(err) - s := grpc.NewServer(grpc.ChainUnaryInterceptor(grpcMetrics, dtmgimp.GrpcServerLog)) + s := grpc.NewServer(grpc.ChainUnaryInterceptor(grpcRecover, grpcMetrics, dtmgimp.GrpcServerLog)) dtmgpb.RegisterDtmServer(s, &dtmServer{}) logger.Infof("grpc listening at %v", lis.Addr()) go func() { @@ -99,23 +101,27 @@ func updateBranchAsync() { flushBranchs := func() { defer dtmutil.RecoverPanic(nil) updates := []TransBranch{} + exists := map[string]bool{} started := time.Now() checkInterval := 20 * time.Millisecond for time.Since(started) < UpdateBranchAsyncInterval-checkInterval && len(updates) < 20 { select { case updateBranch := <-updateBranchAsyncChan: - updates = append(updates, TransBranch{ - ModelBase: dtmutil.ModelBase{ID: updateBranch.id}, - Gid: updateBranch.gid, - BranchID: updateBranch.branchID, - Op: updateBranch.op, - Status: updateBranch.status, - FinishTime: updateBranch.finishTime, - }) + k := updateBranch.gid + updateBranch.branchID + "-" + updateBranch.op + if !exists[k] { // postgres does not allow + exists[k] = true + updates = append(updates, TransBranch{ + Gid: updateBranch.gid, + BranchID: updateBranch.branchID, + Op: updateBranch.op, + Status: updateBranch.status, + FinishTime: updateBranch.finishTime, + }) + } case <-time.After(checkInterval): } } - for len(updates) > 0 { + for i := 0; i < 3 && len(updates) > 0; i++ { rowAffected, err := GetStore().UpdateBranches(updates, []string{"status", "finish_time", "update_time"}) if err != nil { @@ -132,3 +138,14 @@ func updateBranchAsync() { flushBranchs() } } + +func grpcRecover(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (res interface{}, rerr error) { + defer func() { + if x := recover(); x != nil { + rerr = status.Errorf(codes.Internal, "%v", x) + logger.Errorf("dtm server panic: %v", x) + } + }() + res, rerr = handler(ctx, req) + return +} diff --git a/dtmsvr/trans_class.go b/dtmsvr/trans_class.go index 97c7091..aed1dcf 100644 --- a/dtmsvr/trans_class.go +++ b/dtmsvr/trans_class.go @@ -4,11 +4,11 @@ import ( "context" "time" - "github.com/dtm-labs/dtm/dtmcli" - "github.com/dtm-labs/dtm/dtmcli/dtmimp" - "github.com/dtm-labs/dtm/dtmcli/logger" - "github.com/dtm-labs/dtm/dtmgrpc/dtmgimp" - "github.com/dtm-labs/dtm/dtmgrpc/dtmgpb" + "github.com/dtm-labs/dtm/client/dtmcli" + "github.com/dtm-labs/dtm/client/dtmcli/dtmimp" + "github.com/dtm-labs/dtm/client/dtmcli/logger" + "github.com/dtm-labs/dtm/client/dtmgrpc/dtmgimp" + "github.com/dtm-labs/dtm/client/dtmgrpc/dtmgpb" "github.com/dtm-labs/dtm/dtmsvr/storage" "github.com/gin-gonic/gin" ) diff --git a/dtmsvr/trans_process.go b/dtmsvr/trans_process.go index 7521b13..7050ae3 100644 --- a/dtmsvr/trans_process.go +++ b/dtmsvr/trans_process.go @@ -11,9 +11,9 @@ import ( "fmt" "time" - "github.com/dtm-labs/dtm/dtmcli" - "github.com/dtm-labs/dtm/dtmcli/dtmimp" - "github.com/dtm-labs/dtm/dtmcli/logger" + "github.com/dtm-labs/dtm/client/dtmcli" + "github.com/dtm-labs/dtm/client/dtmcli/dtmimp" + "github.com/dtm-labs/dtm/client/dtmcli/logger" "github.com/dtm-labs/dtm/dtmutil" ) @@ -49,7 +49,7 @@ func (t *TransGlobal) process(branches []TransBranch) error { if submitting && t.Status != dtmcli.StatusSucceed { if t.RollbackReason != "" { - return fmt.Errorf("%s. %w", t.RollbackReason, dtmcli.ErrFailure) + return dtmcli.ErrorMessage2Error(t.RollbackReason, dtmcli.ErrFailure) } return fmt.Errorf("wait result not return success: %w", dtmcli.ErrFailure) } diff --git a/dtmsvr/trans_status.go b/dtmsvr/trans_status.go index eb47f7e..6539fcc 100644 --- a/dtmsvr/trans_status.go +++ b/dtmsvr/trans_status.go @@ -7,11 +7,11 @@ import ( "strings" "time" - "github.com/dtm-labs/dtm/dtmcli" - "github.com/dtm-labs/dtm/dtmcli/dtmimp" - "github.com/dtm-labs/dtm/dtmcli/logger" - "github.com/dtm-labs/dtm/dtmgrpc" - "github.com/dtm-labs/dtm/dtmgrpc/dtmgimp" + "github.com/dtm-labs/dtm/client/dtmcli" + "github.com/dtm-labs/dtm/client/dtmcli/dtmimp" + "github.com/dtm-labs/dtm/client/dtmcli/logger" + "github.com/dtm-labs/dtm/client/dtmgrpc" + "github.com/dtm-labs/dtm/client/dtmgrpc/dtmgimp" "github.com/dtm-labs/dtm/dtmutil" "github.com/dtm-labs/dtmdriver" "github.com/lithammer/shortuuid/v3" @@ -81,7 +81,7 @@ func (t *TransGlobal) changeBranchStatus(b *TransBranch, status string, branchPo logger.Infof("LockGlobalSaveBranches ok: gid: %s old status: %s branches: %s", b.Gid, dtmcli.StatusPrepared, b.String()) } else { // for better performance, batch the updates of branch status - updateBranchAsyncChan <- branchStatus{id: b.ID, gid: t.Gid, branchID: b.BranchID, op: b.Op, status: status, finishTime: &now} + updateBranchAsyncChan <- branchStatus{gid: t.Gid, branchID: b.BranchID, op: b.Op, status: status, finishTime: &now} } } @@ -135,7 +135,7 @@ func (t *TransGlobal) getHTTPResult(uri string, branchID, op string, branchPaylo if err != nil { return err } - return dtmimp.RespAsErrorCompatible(resp) + return dtmcli.HTTPResp2DtmError(resp) } func (t *TransGlobal) getJSONRPCResult(uri string, branchID, op string, branchPayload []byte) error { @@ -158,7 +158,7 @@ func (t *TransGlobal) getJSONRPCResult(uri string, branchID, op string, branchPa SetHeaders(t.TransOptions.BranchHeaders). Post(uri) if err == nil { - err = dtmimp.RespAsErrorCompatible(resp) + err = dtmcli.HTTPResp2DtmError(resp) } if err == nil { err = dtmimp.RespAsErrorByJSONRPC(resp) diff --git a/dtmsvr/trans_type_msg.go b/dtmsvr/trans_type_msg.go index 49816e5..cc45245 100644 --- a/dtmsvr/trans_type_msg.go +++ b/dtmsvr/trans_type_msg.go @@ -4,9 +4,9 @@ import ( "errors" "fmt" - "github.com/dtm-labs/dtm/dtmcli" - "github.com/dtm-labs/dtm/dtmcli/dtmimp" - "github.com/dtm-labs/dtm/dtmcli/logger" + "github.com/dtm-labs/dtm/client/dtmcli" + "github.com/dtm-labs/dtm/client/dtmcli/dtmimp" + "github.com/dtm-labs/dtm/client/dtmcli/logger" ) type transMsgProcessor struct { diff --git a/dtmsvr/trans_type_saga.go b/dtmsvr/trans_type_saga.go index 9117515..4b6b8c1 100644 --- a/dtmsvr/trans_type_saga.go +++ b/dtmsvr/trans_type_saga.go @@ -5,9 +5,9 @@ import ( "fmt" "time" - "github.com/dtm-labs/dtm/dtmcli" - "github.com/dtm-labs/dtm/dtmcli/dtmimp" - "github.com/dtm-labs/dtm/dtmcli/logger" + "github.com/dtm-labs/dtm/client/dtmcli" + "github.com/dtm-labs/dtm/client/dtmcli/dtmimp" + "github.com/dtm-labs/dtm/client/dtmcli/logger" ) type transSagaProcessor struct { diff --git a/dtmsvr/trans_type_tcc.go b/dtmsvr/trans_type_tcc.go index 11f23b7..6e1147d 100644 --- a/dtmsvr/trans_type_tcc.go +++ b/dtmsvr/trans_type_tcc.go @@ -3,9 +3,9 @@ package dtmsvr import ( "fmt" - "github.com/dtm-labs/dtm/dtmcli" - "github.com/dtm-labs/dtm/dtmcli/dtmimp" - "github.com/dtm-labs/dtm/dtmcli/logger" + "github.com/dtm-labs/dtm/client/dtmcli" + "github.com/dtm-labs/dtm/client/dtmcli/dtmimp" + "github.com/dtm-labs/dtm/client/dtmcli/logger" ) type transTccProcessor struct { diff --git a/dtmsvr/trans_type_workflow.go b/dtmsvr/trans_type_workflow.go index d076a81..a350081 100644 --- a/dtmsvr/trans_type_workflow.go +++ b/dtmsvr/trans_type_workflow.go @@ -1,10 +1,10 @@ package dtmsvr import ( - "github.com/dtm-labs/dtm/dtmcli" - "github.com/dtm-labs/dtm/dtmcli/dtmimp" - "github.com/dtm-labs/dtm/dtmgrpc/dtmgimp" - "github.com/dtm-labs/dtm/dtmgrpc/workflow/wfpb" + "github.com/dtm-labs/dtm/client/dtmcli" + "github.com/dtm-labs/dtm/client/dtmcli/dtmimp" + "github.com/dtm-labs/dtm/client/dtmgrpc/dtmgimp" + "github.com/dtm-labs/dtm/client/workflow/wfpb" ) type transWorkflowProcessor struct { @@ -25,10 +25,7 @@ type cWorkflowCustom struct { } func (t *transWorkflowProcessor) ProcessOnce(branches []TransBranch) error { - if t.Status == dtmcli.StatusSubmitted { // client workflow finished - t.changeStatus(dtmcli.StatusSucceed) - return nil - } else if t.Status == dtmcli.StatusFailed || t.Status == dtmcli.StatusSucceed { + if t.Status == dtmcli.StatusFailed || t.Status == dtmcli.StatusSucceed { return nil } diff --git a/dtmsvr/trans_type_xa.go b/dtmsvr/trans_type_xa.go index c74f188..fdb7a01 100644 --- a/dtmsvr/trans_type_xa.go +++ b/dtmsvr/trans_type_xa.go @@ -3,8 +3,8 @@ package dtmsvr import ( "fmt" - "github.com/dtm-labs/dtm/dtmcli" - "github.com/dtm-labs/dtm/dtmcli/dtmimp" + "github.com/dtm-labs/dtm/client/dtmcli" + "github.com/dtm-labs/dtm/client/dtmcli/dtmimp" ) type transXaProcessor struct { diff --git a/dtmsvr/utils.go b/dtmsvr/utils.go index 8f8263c..6ab5ffe 100644 --- a/dtmsvr/utils.go +++ b/dtmsvr/utils.go @@ -10,7 +10,7 @@ import ( "fmt" "time" - "github.com/dtm-labs/dtm/dtmcli/dtmimp" + "github.com/dtm-labs/dtm/client/dtmcli/dtmimp" "github.com/dtm-labs/dtm/dtmsvr/config" "github.com/dtm-labs/dtm/dtmsvr/storage" "github.com/dtm-labs/dtm/dtmsvr/storage/registry" @@ -18,7 +18,6 @@ import ( ) type branchStatus struct { - id uint64 gid string branchID string op string diff --git a/dtmutil/db.go b/dtmutil/db.go index 043f7f9..da3a160 100644 --- a/dtmutil/db.go +++ b/dtmutil/db.go @@ -6,9 +6,9 @@ import ( "sync" "time" - "github.com/dtm-labs/dtm/dtmcli" - "github.com/dtm-labs/dtm/dtmcli/dtmimp" - "github.com/dtm-labs/dtm/dtmcli/logger" + "github.com/dtm-labs/dtm/client/dtmcli" + "github.com/dtm-labs/dtm/client/dtmcli/dtmimp" + "github.com/dtm-labs/dtm/client/dtmcli/logger" _ "github.com/go-sql-driver/mysql" // register mysql driver _ "github.com/lib/pq" // register postgres driver "gorm.io/driver/mysql" diff --git a/dtmutil/utils.go b/dtmutil/utils.go index e7bbeba..545e855 100644 --- a/dtmutil/utils.go +++ b/dtmutil/utils.go @@ -20,9 +20,9 @@ import ( "github.com/gin-gonic/gin" "github.com/go-resty/resty/v2" - "github.com/dtm-labs/dtm/dtmcli" - "github.com/dtm-labs/dtm/dtmcli/dtmimp" - "github.com/dtm-labs/dtm/dtmcli/logger" + "github.com/dtm-labs/dtm/client/dtmcli" + "github.com/dtm-labs/dtm/client/dtmcli/dtmimp" + "github.com/dtm-labs/dtm/client/dtmcli/logger" ) // GetGinApp init and return gin diff --git a/go.sum b/go.sum index 98d85de..253f1f9 100644 --- a/go.sum +++ b/go.sum @@ -1251,3 +1251,4 @@ sigs.k8s.io/structured-merge-diff/v4 v4.1.2/go.mod h1:j/nl6xW8vLS49O8YvXW1ocPhZa sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o= sigs.k8s.io/yaml v1.2.0 h1:kr/MCeFWJWTwyaHoR9c8EjH9OumOmoF9YGiZd7lFm/Q= sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc= + diff --git a/helper/bench/main.go b/helper/bench/main.go index 058db3e..78d52af 100644 --- a/helper/bench/main.go +++ b/helper/bench/main.go @@ -4,8 +4,8 @@ import ( "fmt" "os" - "github.com/dtm-labs/dtm/dtmcli" - "github.com/dtm-labs/dtm/dtmcli/logger" + "github.com/dtm-labs/dtm/client/dtmcli" + "github.com/dtm-labs/dtm/client/dtmcli/logger" "github.com/dtm-labs/dtm/dtmsvr" "github.com/dtm-labs/dtm/dtmsvr/config" "github.com/dtm-labs/dtm/dtmsvr/storage/registry" diff --git a/helper/bench/svr/http.go b/helper/bench/svr/http.go index 5a8b883..1944e1f 100644 --- a/helper/bench/svr/http.go +++ b/helper/bench/svr/http.go @@ -15,9 +15,9 @@ import ( "sync/atomic" "time" - "github.com/dtm-labs/dtm/dtmcli" - "github.com/dtm-labs/dtm/dtmcli/dtmimp" - "github.com/dtm-labs/dtm/dtmcli/logger" + "github.com/dtm-labs/dtm/client/dtmcli" + "github.com/dtm-labs/dtm/client/dtmcli/dtmimp" + "github.com/dtm-labs/dtm/client/dtmcli/logger" "github.com/dtm-labs/dtm/dtmsvr" "github.com/dtm-labs/dtm/dtmutil" "github.com/dtm-labs/dtm/test/busi" diff --git a/helper/sync-client.sh b/helper/sync-client.sh new file mode 100755 index 0000000..358dc02 --- /dev/null +++ b/helper/sync-client.sh @@ -0,0 +1,36 @@ +#! /bin/bash +set -x +ver=$1 +if [ x$ver == x ]; then + echo please specify you version like vx.x.x; + exit 1; +fi + +if [ ${ver:0:1} != v ]; then + echo please specify you version like vx.x.x; + exit 1; +fi + +cd ../client +cp -rf ../dtm/client/* ./ +sed -i '' -e 's/dtm-labs\/dtm\//dtm-labs\//g' */*.go */*/*.go + +rm -rf */*_test.go */*/*_test.go */*log */*/*log +go mod tidy +go build || exit 1 + +git add . +git commit -m"update from dtm to version $ver" +git push +git tag $ver +git push --tags + +cd ../quick-start-sample + +go get -u github.com/dtm-labs/client@$ver +go mod tidy +go build || exit 1 +git add . +git commit -m"update from dtm to version $ver" +git push + diff --git a/helper/sync-dtmcli.sh b/helper/sync-dtmcli.sh deleted file mode 100755 index 0345137..0000000 --- a/helper/sync-dtmcli.sh +++ /dev/null @@ -1,57 +0,0 @@ -#! /bin/bash -set -x -ver=$1 -if [ x$ver == x ]; then - echo please specify you version like vx.x.x; - exit 1; -fi - -if [ ${ver:0:1} != v ]; then - echo please specify you version like vx.x.x; - exit 1; -fi - -cd ../dtmcli -cp -rf ../dtm/dtmcli/* ./ -rm -f *_test.go logger/*.log -sed -i '' -e 's/dtm-labs\/dtm\//dtm-labs\//g' *.go */**.go -go mod tidy -go build || exit 1 -git add . -git commit -m"update from dtm to version $ver" -git push -git tag $ver -git push --tags - -cd ../dtmcli-go-sample -go get -u github.com/dtm-labs/dtmcli@$ver -go mod tidy -go build || exit 1 -git add . -git commit -m"update from dtm to version $ver" -git push - - -cd ../dtmgrpc -rm -rf *.go dtmgimp -cp -r ../dtm/dtmgrpc/* ./ -go get github.com/dtm-labs/dtmcli@$ver -sed -i '' -e 's/dtm-labs\/dtm\//dtm-labs\//g' *.go */**.go -rm -rf *_test.go -rm -rf workflow/*_test.go -go mod tidy -go build || exit 1 -git add . -git commit -m"update from dtm to version $ver" -git push -git tag $ver -git push --tags - -cd ../dtmgrpc-go-sample -go get github.com/dtm-labs/dtmcli@$ver -go get github.com/dtm-labs/dtmgrpc@$ver -protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative busi/*.proto || exit 1 -go build || exit 1 -git add . -git commit -m"update from dtm to version $ver" -git push \ No newline at end of file diff --git a/helper/test-cover.sh b/helper/test-cover.sh index 8d6723e..0ecf97e 100755 --- a/helper/test-cover.sh +++ b/helper/test-cover.sh @@ -1,13 +1,11 @@ set -x echo "mode: count" > coverage.txt for store in redis boltdb mysql postgres; do - for d in $(go list ./... | grep -v vendor); do - TEST_STORE=$store go test -failfast -covermode count -coverprofile=profile.out -coverpkg=github.com/dtm-labs/dtm/dtmcli,github.com/dtm-labs/dtm/dtmcli/dtmimp,github.com/dtm-labs/dtm/dtmcli/logger,github.com/dtm-labs/dtm/dtmgrpc,github.com/dtm-labs/dtm/dtmgrpc/workflow,github.com/dtm-labs/dtm/dtmgrpc/dtmgimp,github.com/dtm-labs/dtm/dtmsvr,github.com/dtm-labs/dtm/dtmsvr/config,github.com/dtm-labs/dtm/dtmsvr/storage,github.com/dtm-labs/dtm/dtmsvr/storage/boltdb,github.com/dtm-labs/dtm/dtmsvr/storage/redis,github.com/dtm-labs/dtm/dtmsvr/storage/registry,github.com/dtm-labs/dtm/dtmsvr/storage/sql,github.com/dtm-labs/dtm/dtmutil -gcflags=-l $d || exit 1 - if [ -f profile.out ]; then - cat profile.out | grep -v 'mode:' >> coverage.txt - echo > profile.out - fi - done + TEST_STORE=$store go test -failfast -covermode count -coverprofile=profile.out -coverpkg=github.com/dtm-labs/dtm/client/dtmcli,github.com/dtm-labs/dtm/client/dtmcli/dtmimp,github.com/dtm-labs/dtm/client/dtmcli/logger,github.com/dtm-labs/dtm/client/dtmgrpc,github.com/dtm-labs/dtm/client/workflow,github.com/dtm-labs/dtm/client/dtmgrpc/dtmgimp,github.com/dtm-labs/dtm/dtmsvr,dtmsvr/config,github.com/dtm-labs/dtm/dtmsvr/storage,github.com/dtm-labs/dtm/dtmsvr/storage/boltdb,github.com/dtm-labs/dtm/dtmsvr/storage/redis,github.com/dtm-labs/dtm/dtmsvr/storage/registry,github.com/dtm-labs/dtm/dtmsvr/storage/sql,github.com/dtm-labs/dtm/dtmutil -gcflags=-l ./... || exit 1 + if [ -f profile.out ]; then + cat profile.out | grep -v 'mode:' >> coverage.txt + echo > profile.out + fi done # go tool cover -html=coverage.txt diff --git a/main.go b/main.go index 8d3d5a6..e203533 100644 --- a/main.go +++ b/main.go @@ -19,7 +19,7 @@ import ( "strings" "syscall" - "github.com/dtm-labs/dtm/dtmcli/logger" + "github.com/dtm-labs/dtm/client/dtmcli/logger" "github.com/dtm-labs/dtm/dtmsvr/config" "github.com/dtm-labs/dtm/dtmsvr/entry" _ "github.com/dtm-labs/dtm/dtmsvr/microservices" diff --git a/test/api_test.go b/test/api_test.go index e63fc27..6b58584 100644 --- a/test/api_test.go +++ b/test/api_test.go @@ -12,7 +12,7 @@ import ( "strconv" "testing" - "github.com/dtm-labs/dtm/dtmcli/dtmimp" + "github.com/dtm-labs/dtm/client/dtmcli/dtmimp" "github.com/dtm-labs/dtm/dtmutil" "github.com/dtm-labs/dtm/test/busi" "github.com/stretchr/testify/assert" diff --git a/test/base_test.go b/test/base_test.go index 3fbd05c..3969054 100644 --- a/test/base_test.go +++ b/test/base_test.go @@ -11,9 +11,9 @@ import ( "fmt" "testing" - "github.com/dtm-labs/dtm/dtmcli" - "github.com/dtm-labs/dtm/dtmcli/dtmimp" - "github.com/dtm-labs/dtm/dtmcli/logger" + "github.com/dtm-labs/dtm/client/dtmcli" + "github.com/dtm-labs/dtm/client/dtmcli/dtmimp" + "github.com/dtm-labs/dtm/client/dtmcli/logger" "github.com/dtm-labs/dtm/dtmutil" "github.com/dtm-labs/dtm/test/busi" "github.com/stretchr/testify/assert" diff --git a/test/busi/barrier.go b/test/busi/barrier.go index 5f61994..ea6e53d 100644 --- a/test/busi/barrier.go +++ b/test/busi/barrier.go @@ -10,8 +10,7 @@ import ( "context" "database/sql" - "github.com/dtm-labs/dtm/dtmcli" - "github.com/dtm-labs/dtm/dtmgrpc" + "github.com/dtm-labs/dtm/client/dtmgrpc" "github.com/dtm-labs/dtm/dtmutil" "github.com/gin-gonic/gin" "go.mongodb.org/mongo-driver/mongo" @@ -80,7 +79,7 @@ func init() { app.POST(BusiAPI+"/TccBTransInTry", dtmutil.WrapHandler(func(c *gin.Context) interface{} { req := reqFrom(c) if req.TransInResult != "" { - return dtmcli.String2DtmError(req.TransInResult) + return string2DtmError(req.TransInResult) } return MustBarrierFromGin(c).CallWithDB(pdbGet(), func(tx *sql.Tx) error { return tccAdjustTrading(tx, TransInUID, req.Amount) @@ -159,7 +158,7 @@ func init() { app.POST(BusiAPI+"/TccBTransOutTry", dtmutil.WrapHandler(func(c *gin.Context) interface{} { req := reqFrom(c) if req.TransOutResult != "" { - return dtmcli.String2DtmError(req.TransOutResult) + return string2DtmError(req.TransOutResult) } bb := MustBarrierFromGin(c) if req.Store == Redis { diff --git a/test/busi/base_grpc.go b/test/busi/base_grpc.go index c7bd726..28569f9 100644 --- a/test/busi/base_grpc.go +++ b/test/busi/base_grpc.go @@ -12,18 +12,20 @@ import ( "errors" "fmt" "net" + "time" - "github.com/dtm-labs/dtm/dtmcli" - "github.com/dtm-labs/dtm/dtmcli/dtmimp" - "github.com/dtm-labs/dtm/dtmcli/logger" - "github.com/dtm-labs/dtm/dtmgrpc" + "github.com/dtm-labs/dtm/client/dtmcli/dtmimp" + "github.com/dtm-labs/dtm/client/dtmcli/logger" + "github.com/dtm-labs/dtm/client/dtmgrpc" "github.com/dtm-labs/dtm/dtmutil" - "github.com/dtm-labs/dtm/dtmgrpc/dtmgimp" - "github.com/dtm-labs/dtm/dtmgrpc/dtmgpb" - "github.com/dtm-labs/dtm/dtmgrpc/workflow" + "github.com/dtm-labs/dtm/client/dtmgrpc/dtmgimp" + "github.com/dtm-labs/dtm/client/dtmgrpc/dtmgpb" + "github.com/dtm-labs/dtm/client/workflow" grpc "google.golang.org/grpc" + "google.golang.org/grpc/codes" "google.golang.org/grpc/credentials/insecure" + status "google.golang.org/grpc/status" emptypb "google.golang.org/protobuf/types/known/emptypb" ) @@ -36,14 +38,25 @@ var DtmClient dtmgpb.DtmClient // BusiCli grpc client for busi var BusiCli BusiClient +func retry(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error { + logger.Debugf("in retry interceptor") + err := invoker(ctx, method, req, reply, cc, opts...) + if st, _ := status.FromError(err); st != nil && st.Code() == codes.Unavailable { + logger.Errorf("invoker return err: %v", err) + time.Sleep(1000 * time.Millisecond) + err = invoker(ctx, method, req, reply, cc, opts...) + } + return err +} + // GrpcStartup for grpc func GrpcStartup() *grpc.Server { conn, err := grpc.Dial(dtmutil.DefaultGrpcServer, grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithUnaryInterceptor(dtmgimp.GrpcClientLog)) logger.FatalIfError(err) DtmClient = dtmgpb.NewDtmClient(conn) logger.Debugf("dtm client inited") - - conn1, err := grpc.Dial(BusiGrpc, grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithUnaryInterceptor(workflow.Interceptor)) + // in github actions, the call is failed sometime, so add a retry + conn1, err := grpc.Dial(BusiGrpc, grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithChainUnaryInterceptor(workflow.Interceptor, retry)) logger.FatalIfError(err) BusiCli = NewBusiClient(conn1) @@ -58,6 +71,7 @@ func RunGrpc(server *grpc.Server) { logger.FatalIfError(err) logger.Debugf("busi grpc listening at %v", lis.Addr()) err = server.Serve(lis) + logger.Errorf("grpc server serve return: %v", err) logger.FatalIfError(err) } @@ -68,7 +82,7 @@ type busiServer struct { func (s *busiServer) QueryPrepared(ctx context.Context, in *ReqGrpc) (*BusiReply, error) { res := MainSwitch.QueryPreparedResult.Fetch() - err := dtmcli.String2DtmError(res) + err := string2DtmError(res) return &BusiReply{Message: "a sample data"}, dtmgrpc.DtmError2GrpcError(err) } diff --git a/test/busi/base_http.go b/test/busi/base_http.go index 94bde53..f5672b7 100644 --- a/test/busi/base_http.go +++ b/test/busi/base_http.go @@ -12,10 +12,10 @@ import ( "fmt" "io/ioutil" - "github.com/dtm-labs/dtm/dtmcli" - "github.com/dtm-labs/dtm/dtmcli/dtmimp" - "github.com/dtm-labs/dtm/dtmcli/logger" - "github.com/dtm-labs/dtm/dtmgrpc/workflow" + "github.com/dtm-labs/dtm/client/dtmcli" + "github.com/dtm-labs/dtm/client/dtmcli/dtmimp" + "github.com/dtm-labs/dtm/client/dtmcli/logger" + "github.com/dtm-labs/dtm/client/workflow" "github.com/dtm-labs/dtm/dtmutil" "github.com/gin-gonic/gin" "gorm.io/driver/mysql" @@ -125,7 +125,7 @@ func BaseAddRoute(app *gin.Engine) { app.GET(BusiAPI+"/QueryPrepared", dtmutil.WrapHandler(func(c *gin.Context) interface{} { logger.Debugf("%s QueryPrepared", c.Query("gid")) - return dtmcli.String2DtmError(dtmimp.OrString(MainSwitch.QueryPreparedResult.Fetch(), dtmcli.ResultSuccess)) + return string2DtmError(dtmimp.OrString(MainSwitch.QueryPreparedResult.Fetch(), dtmcli.ResultSuccess)) })) app.GET(BusiAPI+"/QueryPreparedB", dtmutil.WrapHandler(func(c *gin.Context) interface{} { logger.Debugf("%s QueryPreparedB", c.Query("gid")) diff --git a/test/busi/base_jrpc.go b/test/busi/base_jrpc.go index 8378790..c24b8f2 100644 --- a/test/busi/base_jrpc.go +++ b/test/busi/base_jrpc.go @@ -3,8 +3,8 @@ package busi import ( "fmt" - "github.com/dtm-labs/dtm/dtmcli/dtmimp" - "github.com/dtm-labs/dtm/dtmcli/logger" + "github.com/dtm-labs/dtm/client/dtmcli/dtmimp" + "github.com/dtm-labs/dtm/client/dtmcli/logger" "github.com/dtm-labs/dtm/dtmutil" "github.com/gin-gonic/gin" ) diff --git a/test/busi/base_types.go b/test/busi/base_types.go index 395850d..f10056a 100644 --- a/test/busi/base_types.go +++ b/test/busi/base_types.go @@ -10,9 +10,9 @@ import ( "context" "fmt" - "github.com/dtm-labs/dtm/dtmcli" - "github.com/dtm-labs/dtm/dtmcli/dtmimp" - "github.com/dtm-labs/dtm/dtmcli/logger" + "github.com/dtm-labs/dtm/client/dtmcli" + "github.com/dtm-labs/dtm/client/dtmcli/dtmimp" + "github.com/dtm-labs/dtm/client/dtmcli/logger" "github.com/gin-gonic/gin" "go.mongodb.org/mongo-driver/bson" ) diff --git a/test/busi/data.go b/test/busi/data.go index f2f575a..4927532 100644 --- a/test/busi/data.go +++ b/test/busi/data.go @@ -6,9 +6,9 @@ import ( "fmt" "strings" - "github.com/dtm-labs/dtm/dtmcli" - "github.com/dtm-labs/dtm/dtmcli/dtmimp" - "github.com/dtm-labs/dtm/dtmcli/logger" + "github.com/dtm-labs/dtm/client/dtmcli" + "github.com/dtm-labs/dtm/client/dtmcli/dtmimp" + "github.com/dtm-labs/dtm/client/dtmcli/logger" "github.com/dtm-labs/dtm/dtmutil" "github.com/gin-gonic/gin" "go.mongodb.org/mongo-driver/bson" @@ -67,7 +67,7 @@ func handleGeneralBusiness(c *gin.Context, result1 string, result2 string, busi if res == dtmimp.ResultFailure { return fmt.Errorf("reason:%s. %w", MainSwitch.FailureReason.Fetch(), dtmimp.ErrFailure) } - return dtmcli.String2DtmError(res) + return string2DtmError(res) } // old business handler. for compatible usage diff --git a/test/busi/quick_start.go b/test/busi/quick_start.go index 729be30..0d40042 100644 --- a/test/busi/quick_start.go +++ b/test/busi/quick_start.go @@ -5,7 +5,7 @@ import ( "log" "time" - "github.com/dtm-labs/dtm/dtmcli" + "github.com/dtm-labs/dtm/client/dtmcli" "github.com/gin-gonic/gin" "github.com/lithammer/shortuuid/v3" ) diff --git a/test/busi/utils.go b/test/busi/utils.go index db07113..e30b463 100644 --- a/test/busi/utils.go +++ b/test/busi/utils.go @@ -9,11 +9,11 @@ import ( sync "sync" "time" - "github.com/dtm-labs/dtm/dtmcli" - "github.com/dtm-labs/dtm/dtmcli/dtmimp" - "github.com/dtm-labs/dtm/dtmcli/logger" - "github.com/dtm-labs/dtm/dtmgrpc" - "github.com/dtm-labs/dtm/dtmgrpc/dtmgpb" + "github.com/dtm-labs/dtm/client/dtmcli" + "github.com/dtm-labs/dtm/client/dtmcli/dtmimp" + "github.com/dtm-labs/dtm/client/dtmcli/logger" + "github.com/dtm-labs/dtm/client/dtmgrpc" + "github.com/dtm-labs/dtm/client/dtmgrpc/dtmgpb" "github.com/dtm-labs/dtm/dtmutil" "github.com/gin-gonic/gin" "github.com/go-redis/redis/v8" @@ -72,6 +72,16 @@ func MustBarrierFromGrpc(ctx context.Context) *dtmcli.BranchBarrier { return ti } +// string2DtmError translate string to dtm error +func string2DtmError(str string) error { + return map[string]error{ + dtmcli.ResultFailure: dtmcli.ErrFailure, + dtmcli.ResultOngoing: dtmcli.ErrOngoing, + dtmcli.ResultSuccess: nil, + "": nil, + }[str] +} + // SetGrpcHeaderForHeadersYes interceptor to set head for HeadersYes func SetGrpcHeaderForHeadersYes(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error { if r, ok := req.(*dtmgpb.DtmRequest); ok && strings.HasSuffix(r.Gid, "HeadersYes") { diff --git a/test/common_test.go b/test/common_test.go index a28a144..2fe2724 100644 --- a/test/common_test.go +++ b/test/common_test.go @@ -3,9 +3,9 @@ package test import ( "testing" - "github.com/dtm-labs/dtm/dtmcli" - "github.com/dtm-labs/dtm/dtmcli/dtmimp" - "github.com/dtm-labs/dtm/dtmgrpc" + "github.com/dtm-labs/dtm/client/dtmcli" + "github.com/dtm-labs/dtm/client/dtmcli/dtmimp" + "github.com/dtm-labs/dtm/client/dtmgrpc" "github.com/dtm-labs/dtm/dtmsvr/storage/sql" "github.com/dtm-labs/dtm/dtmutil" "github.com/stretchr/testify/assert" diff --git a/test/dtmsvr_test.go b/test/dtmsvr_test.go index 273fe36..497a449 100644 --- a/test/dtmsvr_test.go +++ b/test/dtmsvr_test.go @@ -7,10 +7,14 @@ package test import ( + "context" "testing" "time" - "github.com/dtm-labs/dtm/dtmcli/dtmimp" + "github.com/dtm-labs/dtm/client/dtmcli/dtmimp" + "github.com/dtm-labs/dtm/client/dtmgrpc/dtmgimp" + "github.com/dtm-labs/dtm/client/dtmgrpc/dtmgpb" + "github.com/dtm-labs/dtm/client/workflow" "github.com/dtm-labs/dtm/dtmsvr" "github.com/dtm-labs/dtm/dtmsvr/config" "github.com/dtm-labs/dtm/dtmutil" @@ -39,8 +43,11 @@ func getBranchesStatus(gid string) []string { return status } +func isSqlStore() bool { + return conf.Store.Driver == config.Mysql || conf.Store.Driver == config.Postgres +} func TestUpdateBranchAsync(t *testing.T) { - if conf.Store.Driver != config.Mysql { + if !isSqlStore() { return } conf.UpdateBranchSync = 0 @@ -49,8 +56,39 @@ func TestUpdateBranchAsync(t *testing.T) { err := saga.Submit() assert.Nil(t, err) waitTransProcessed(saga.Gid) + + gid := dtmimp.GetFuncName() + "-wf" + workflow.SetProtocolForTest(dtmimp.ProtocolHTTP) + err = workflow.Register(gid, func(wf *workflow.Workflow, data []byte) error { + _, err := busi.BusiCli.TransOut(wf.NewBranchCtx(), &busi.ReqGrpc{}) + // add additional data directly + dtmimp.TransRegisterBranch(wf.TransBase, map[string]string{ + "branch_id": "01", + "op": "action", + "status": "succeed", + }, "registerBranch") + return err + }) + assert.Nil(t, err) + err = workflow.Execute(gid, gid, nil) + assert.Nil(t, err) + time.Sleep(dtmsvr.UpdateBranchAsyncInterval) + assert.Equal(t, []string{StatusPrepared, StatusSucceed}, getBranchesStatus(saga.Gid)) assert.Equal(t, StatusSucceed, getTransStatus(saga.Gid)) + + assert.Equal(t, []string{StatusSucceed}, getBranchesStatus(gid)) + assert.Equal(t, StatusSucceed, getTransStatus(gid)) + conf.UpdateBranchSync = 1 } + +func TestGrpcPanic(t *testing.T) { + gid := dtmimp.GetFuncName() + req := dtmgpb.DtmRequest{ + Gid: gid, + } + err := dtmgimp.MustGetGrpcConn(DtmGrpcServer, false).Invoke(context.Background(), "/dtmgimp.Dtm/"+"Submit", &req, nil) + assert.Error(t, err) +} diff --git a/test/main_test.go b/test/main_test.go index 688c839..71e74c0 100644 --- a/test/main_test.go +++ b/test/main_test.go @@ -11,11 +11,11 @@ import ( "testing" "time" - "github.com/dtm-labs/dtm/dtmcli" - "github.com/dtm-labs/dtm/dtmcli/dtmimp" - "github.com/dtm-labs/dtm/dtmcli/logger" - "github.com/dtm-labs/dtm/dtmgrpc" - "github.com/dtm-labs/dtm/dtmgrpc/workflow" + "github.com/dtm-labs/dtm/client/dtmcli" + "github.com/dtm-labs/dtm/client/dtmcli/dtmimp" + "github.com/dtm-labs/dtm/client/dtmcli/logger" + "github.com/dtm-labs/dtm/client/dtmgrpc" + "github.com/dtm-labs/dtm/client/workflow" "github.com/dtm-labs/dtm/dtmsvr" "github.com/dtm-labs/dtm/dtmsvr/config" "github.com/dtm-labs/dtm/dtmsvr/storage/registry" diff --git a/test/msg_barrier_mongo_test.go b/test/msg_barrier_mongo_test.go index 0e5d8c3..32bb0f0 100644 --- a/test/msg_barrier_mongo_test.go +++ b/test/msg_barrier_mongo_test.go @@ -4,8 +4,8 @@ import ( "errors" "testing" - "github.com/dtm-labs/dtm/dtmcli" - "github.com/dtm-labs/dtm/dtmcli/dtmimp" + "github.com/dtm-labs/dtm/client/dtmcli" + "github.com/dtm-labs/dtm/client/dtmcli/dtmimp" "github.com/dtm-labs/dtm/test/busi" "github.com/stretchr/testify/assert" "go.mongodb.org/mongo-driver/mongo" diff --git a/test/msg_barrier_redis_test.go b/test/msg_barrier_redis_test.go index d111b94..dd7ada5 100644 --- a/test/msg_barrier_redis_test.go +++ b/test/msg_barrier_redis_test.go @@ -4,8 +4,8 @@ import ( "errors" "testing" - "github.com/dtm-labs/dtm/dtmcli" - "github.com/dtm-labs/dtm/dtmcli/dtmimp" + "github.com/dtm-labs/dtm/client/dtmcli" + "github.com/dtm-labs/dtm/client/dtmcli/dtmimp" "github.com/dtm-labs/dtm/test/busi" "github.com/stretchr/testify/assert" ) diff --git a/test/msg_barrier_test.go b/test/msg_barrier_test.go index 6ed525d..c6e1006 100644 --- a/test/msg_barrier_test.go +++ b/test/msg_barrier_test.go @@ -7,9 +7,9 @@ import ( "testing" "bou.ke/monkey" - "github.com/dtm-labs/dtm/dtmcli" - "github.com/dtm-labs/dtm/dtmcli/dtmimp" - "github.com/dtm-labs/dtm/dtmcli/logger" + "github.com/dtm-labs/dtm/client/dtmcli" + "github.com/dtm-labs/dtm/client/dtmcli/dtmimp" + "github.com/dtm-labs/dtm/client/dtmcli/logger" "github.com/dtm-labs/dtm/test/busi" "github.com/stretchr/testify/assert" ) diff --git a/test/msg_delay_test.go b/test/msg_delay_test.go index 5aa866f..8915318 100644 --- a/test/msg_delay_test.go +++ b/test/msg_delay_test.go @@ -3,8 +3,8 @@ package test import ( "testing" - "github.com/dtm-labs/dtm/dtmcli" - "github.com/dtm-labs/dtm/dtmcli/dtmimp" + "github.com/dtm-labs/dtm/client/dtmcli" + "github.com/dtm-labs/dtm/client/dtmcli/dtmimp" "github.com/dtm-labs/dtm/dtmsvr" "github.com/dtm-labs/dtm/dtmutil" "github.com/dtm-labs/dtm/test/busi" diff --git a/test/msg_grpc_barrier_redis_test.go b/test/msg_grpc_barrier_redis_test.go index c9525f3..d5b81fa 100644 --- a/test/msg_grpc_barrier_redis_test.go +++ b/test/msg_grpc_barrier_redis_test.go @@ -4,9 +4,9 @@ import ( "errors" "testing" - "github.com/dtm-labs/dtm/dtmcli" - "github.com/dtm-labs/dtm/dtmcli/dtmimp" - "github.com/dtm-labs/dtm/dtmgrpc" + "github.com/dtm-labs/dtm/client/dtmcli" + "github.com/dtm-labs/dtm/client/dtmcli/dtmimp" + "github.com/dtm-labs/dtm/client/dtmgrpc" "github.com/dtm-labs/dtm/test/busi" "github.com/stretchr/testify/assert" ) diff --git a/test/msg_grpc_barrier_test.go b/test/msg_grpc_barrier_test.go index ac75b40..5a3d012 100644 --- a/test/msg_grpc_barrier_test.go +++ b/test/msg_grpc_barrier_test.go @@ -7,9 +7,9 @@ import ( "testing" "bou.ke/monkey" - "github.com/dtm-labs/dtm/dtmcli/dtmimp" - "github.com/dtm-labs/dtm/dtmcli/logger" - "github.com/dtm-labs/dtm/dtmgrpc" + "github.com/dtm-labs/dtm/client/dtmcli/dtmimp" + "github.com/dtm-labs/dtm/client/dtmcli/logger" + "github.com/dtm-labs/dtm/client/dtmgrpc" "github.com/dtm-labs/dtm/test/busi" "github.com/stretchr/testify/assert" ) diff --git a/test/msg_grpc_test.go b/test/msg_grpc_test.go index 3d5cda0..59f53c9 100644 --- a/test/msg_grpc_test.go +++ b/test/msg_grpc_test.go @@ -10,9 +10,9 @@ import ( "fmt" "testing" - "github.com/dtm-labs/dtm/dtmcli" - "github.com/dtm-labs/dtm/dtmcli/dtmimp" - "github.com/dtm-labs/dtm/dtmgrpc" + "github.com/dtm-labs/dtm/client/dtmcli" + "github.com/dtm-labs/dtm/client/dtmcli/dtmimp" + "github.com/dtm-labs/dtm/client/dtmgrpc" "github.com/dtm-labs/dtm/dtmutil" "github.com/dtm-labs/dtm/test/busi" "github.com/stretchr/testify/assert" diff --git a/test/msg_jrpc_test.go b/test/msg_jrpc_test.go index 4c4fe94..e90fa1f 100644 --- a/test/msg_jrpc_test.go +++ b/test/msg_jrpc_test.go @@ -11,8 +11,8 @@ import ( "errors" "testing" - "github.com/dtm-labs/dtm/dtmcli" - "github.com/dtm-labs/dtm/dtmcli/dtmimp" + "github.com/dtm-labs/dtm/client/dtmcli" + "github.com/dtm-labs/dtm/client/dtmcli/dtmimp" "github.com/dtm-labs/dtm/dtmutil" "github.com/dtm-labs/dtm/test/busi" "github.com/stretchr/testify/assert" diff --git a/test/msg_options_test.go b/test/msg_options_test.go index 7597ec5..e230346 100644 --- a/test/msg_options_test.go +++ b/test/msg_options_test.go @@ -9,8 +9,8 @@ package test import ( "testing" - "github.com/dtm-labs/dtm/dtmcli" - "github.com/dtm-labs/dtm/dtmcli/dtmimp" + "github.com/dtm-labs/dtm/client/dtmcli" + "github.com/dtm-labs/dtm/client/dtmcli/dtmimp" "github.com/dtm-labs/dtm/test/busi" "github.com/stretchr/testify/assert" ) diff --git a/test/msg_test.go b/test/msg_test.go index 9ce4197..1c90516 100644 --- a/test/msg_test.go +++ b/test/msg_test.go @@ -9,8 +9,8 @@ package test import ( "testing" - "github.com/dtm-labs/dtm/dtmcli" - "github.com/dtm-labs/dtm/dtmcli/dtmimp" + "github.com/dtm-labs/dtm/client/dtmcli" + "github.com/dtm-labs/dtm/client/dtmcli/dtmimp" "github.com/dtm-labs/dtm/dtmutil" "github.com/dtm-labs/dtm/test/busi" "github.com/stretchr/testify/assert" diff --git a/test/saga_barrier_mongo_test.go b/test/saga_barrier_mongo_test.go index ebf468f..0cf2b61 100644 --- a/test/saga_barrier_mongo_test.go +++ b/test/saga_barrier_mongo_test.go @@ -9,8 +9,8 @@ package test import ( "testing" - "github.com/dtm-labs/dtm/dtmcli" - "github.com/dtm-labs/dtm/dtmcli/dtmimp" + "github.com/dtm-labs/dtm/client/dtmcli" + "github.com/dtm-labs/dtm/client/dtmcli/dtmimp" "github.com/dtm-labs/dtm/test/busi" "github.com/stretchr/testify/assert" ) diff --git a/test/saga_barrier_redis_test.go b/test/saga_barrier_redis_test.go index 5e732c1..1f6efb1 100644 --- a/test/saga_barrier_redis_test.go +++ b/test/saga_barrier_redis_test.go @@ -9,8 +9,8 @@ package test import ( "testing" - "github.com/dtm-labs/dtm/dtmcli" - "github.com/dtm-labs/dtm/dtmcli/dtmimp" + "github.com/dtm-labs/dtm/client/dtmcli" + "github.com/dtm-labs/dtm/client/dtmcli/dtmimp" "github.com/dtm-labs/dtm/test/busi" "github.com/stretchr/testify/assert" ) diff --git a/test/saga_barrier_test.go b/test/saga_barrier_test.go index 77a94e8..58bc7ae 100644 --- a/test/saga_barrier_test.go +++ b/test/saga_barrier_test.go @@ -9,8 +9,8 @@ package test import ( "testing" - "github.com/dtm-labs/dtm/dtmcli" - "github.com/dtm-labs/dtm/dtmcli/dtmimp" + "github.com/dtm-labs/dtm/client/dtmcli" + "github.com/dtm-labs/dtm/client/dtmcli/dtmimp" "github.com/dtm-labs/dtm/test/busi" "github.com/stretchr/testify/assert" ) diff --git a/test/saga_compatible_test.go b/test/saga_compatible_test.go index 98ebf75..ce97319 100644 --- a/test/saga_compatible_test.go +++ b/test/saga_compatible_test.go @@ -10,7 +10,7 @@ import ( "fmt" "testing" - "github.com/dtm-labs/dtm/dtmcli/dtmimp" + "github.com/dtm-labs/dtm/client/dtmcli/dtmimp" "github.com/dtm-labs/dtm/dtmutil" "github.com/dtm-labs/dtm/test/busi" "github.com/stretchr/testify/assert" diff --git a/test/saga_concurrent_test.go b/test/saga_concurrent_test.go index be7a57a..3091e5a 100644 --- a/test/saga_concurrent_test.go +++ b/test/saga_concurrent_test.go @@ -9,8 +9,8 @@ package test import ( "testing" - "github.com/dtm-labs/dtm/dtmcli" - "github.com/dtm-labs/dtm/dtmcli/dtmimp" + "github.com/dtm-labs/dtm/client/dtmcli" + "github.com/dtm-labs/dtm/client/dtmcli/dtmimp" "github.com/dtm-labs/dtm/test/busi" "github.com/stretchr/testify/assert" ) diff --git a/test/saga_cover_test.go b/test/saga_cover_test.go index 500f424..a204fc8 100644 --- a/test/saga_cover_test.go +++ b/test/saga_cover_test.go @@ -3,7 +3,7 @@ package test import ( "testing" - "github.com/dtm-labs/dtm/dtmcli" + "github.com/dtm-labs/dtm/client/dtmcli" ) func TestSagaCover(t *testing.T) { diff --git a/test/saga_grpc_barrier_test.go b/test/saga_grpc_barrier_test.go index 7beecd1..3bb6523 100644 --- a/test/saga_grpc_barrier_test.go +++ b/test/saga_grpc_barrier_test.go @@ -9,8 +9,8 @@ package test import ( "testing" - "github.com/dtm-labs/dtm/dtmcli/dtmimp" - "github.com/dtm-labs/dtm/dtmgrpc" + "github.com/dtm-labs/dtm/client/dtmcli/dtmimp" + "github.com/dtm-labs/dtm/client/dtmgrpc" "github.com/dtm-labs/dtm/dtmutil" "github.com/dtm-labs/dtm/test/busi" "github.com/stretchr/testify/assert" diff --git a/test/saga_grpc_test.go b/test/saga_grpc_test.go index f7cc57a..c4a5be3 100644 --- a/test/saga_grpc_test.go +++ b/test/saga_grpc_test.go @@ -9,9 +9,9 @@ package test import ( "testing" - "github.com/dtm-labs/dtm/dtmcli" - "github.com/dtm-labs/dtm/dtmcli/dtmimp" - "github.com/dtm-labs/dtm/dtmgrpc" + "github.com/dtm-labs/dtm/client/dtmcli" + "github.com/dtm-labs/dtm/client/dtmcli/dtmimp" + "github.com/dtm-labs/dtm/client/dtmgrpc" "github.com/dtm-labs/dtm/dtmutil" "github.com/dtm-labs/dtm/test/busi" "github.com/stretchr/testify/assert" diff --git a/test/saga_options_test.go b/test/saga_options_test.go index cd43ece..74631f7 100644 --- a/test/saga_options_test.go +++ b/test/saga_options_test.go @@ -9,8 +9,8 @@ package test import ( "testing" - "github.com/dtm-labs/dtm/dtmcli" - "github.com/dtm-labs/dtm/dtmcli/dtmimp" + "github.com/dtm-labs/dtm/client/dtmcli" + "github.com/dtm-labs/dtm/client/dtmcli/dtmimp" "github.com/dtm-labs/dtm/dtmutil" "github.com/dtm-labs/dtm/test/busi" "github.com/stretchr/testify/assert" diff --git a/test/saga_test.go b/test/saga_test.go index 118ea9b..25db741 100644 --- a/test/saga_test.go +++ b/test/saga_test.go @@ -9,8 +9,8 @@ package test import ( "testing" - "github.com/dtm-labs/dtm/dtmcli" - "github.com/dtm-labs/dtm/dtmcli/dtmimp" + "github.com/dtm-labs/dtm/client/dtmcli" + "github.com/dtm-labs/dtm/client/dtmcli/dtmimp" "github.com/dtm-labs/dtm/dtmutil" "github.com/dtm-labs/dtm/test/busi" "github.com/stretchr/testify/assert" diff --git a/test/store_test.go b/test/store_test.go index 4cc3c00..68a6daa 100644 --- a/test/store_test.go +++ b/test/store_test.go @@ -5,7 +5,7 @@ import ( "testing" "time" - "github.com/dtm-labs/dtm/dtmcli/dtmimp" + "github.com/dtm-labs/dtm/client/dtmcli/dtmimp" "github.com/dtm-labs/dtm/dtmsvr/storage" "github.com/dtm-labs/dtm/dtmsvr/storage/registry" "github.com/dtm-labs/dtm/dtmutil" diff --git a/test/tcc_barrier_test.go b/test/tcc_barrier_test.go index 59e0503..286bb8c 100644 --- a/test/tcc_barrier_test.go +++ b/test/tcc_barrier_test.go @@ -12,9 +12,9 @@ import ( "fmt" "testing" - "github.com/dtm-labs/dtm/dtmcli" - "github.com/dtm-labs/dtm/dtmcli/dtmimp" - "github.com/dtm-labs/dtm/dtmcli/logger" + "github.com/dtm-labs/dtm/client/dtmcli" + "github.com/dtm-labs/dtm/client/dtmcli/dtmimp" + "github.com/dtm-labs/dtm/client/dtmcli/logger" "github.com/dtm-labs/dtm/test/busi" "github.com/gin-gonic/gin" "github.com/go-resty/resty/v2" diff --git a/test/tcc_cover_test.go b/test/tcc_cover_test.go index 4f66270..c3b17b0 100644 --- a/test/tcc_cover_test.go +++ b/test/tcc_cover_test.go @@ -3,8 +3,8 @@ package test import ( "testing" - "github.com/dtm-labs/dtm/dtmcli" - "github.com/dtm-labs/dtm/dtmcli/dtmimp" + "github.com/dtm-labs/dtm/client/dtmcli" + "github.com/dtm-labs/dtm/client/dtmcli/dtmimp" "github.com/dtm-labs/dtm/dtmutil" "github.com/dtm-labs/dtm/test/busi" "github.com/go-resty/resty/v2" diff --git a/test/tcc_grpc_cover_test.go b/test/tcc_grpc_cover_test.go index 1018dc0..627120a 100644 --- a/test/tcc_grpc_cover_test.go +++ b/test/tcc_grpc_cover_test.go @@ -3,8 +3,8 @@ package test import ( "testing" - "github.com/dtm-labs/dtm/dtmcli/dtmimp" - "github.com/dtm-labs/dtm/dtmgrpc" + "github.com/dtm-labs/dtm/client/dtmcli/dtmimp" + "github.com/dtm-labs/dtm/client/dtmgrpc" "github.com/dtm-labs/dtm/dtmutil" "github.com/dtm-labs/dtm/test/busi" "github.com/stretchr/testify/assert" diff --git a/test/tcc_grpc_test.go b/test/tcc_grpc_test.go index 06d905f..5c7757f 100644 --- a/test/tcc_grpc_test.go +++ b/test/tcc_grpc_test.go @@ -10,10 +10,10 @@ import ( "context" "testing" - "github.com/dtm-labs/dtm/dtmcli" - "github.com/dtm-labs/dtm/dtmcli/dtmimp" - "github.com/dtm-labs/dtm/dtmcli/logger" - "github.com/dtm-labs/dtm/dtmgrpc" + "github.com/dtm-labs/dtm/client/dtmcli" + "github.com/dtm-labs/dtm/client/dtmcli/dtmimp" + "github.com/dtm-labs/dtm/client/dtmcli/logger" + "github.com/dtm-labs/dtm/client/dtmgrpc" "github.com/dtm-labs/dtm/dtmutil" "github.com/dtm-labs/dtm/test/busi" "github.com/stretchr/testify/assert" diff --git a/test/tcc_jrpc_test.go b/test/tcc_jrpc_test.go index ea29d84..4942b52 100644 --- a/test/tcc_jrpc_test.go +++ b/test/tcc_jrpc_test.go @@ -3,8 +3,8 @@ package test import ( "testing" - "github.com/dtm-labs/dtm/dtmcli" - "github.com/dtm-labs/dtm/dtmcli/dtmimp" + "github.com/dtm-labs/dtm/client/dtmcli" + "github.com/dtm-labs/dtm/client/dtmcli/dtmimp" "github.com/dtm-labs/dtm/dtmutil" "github.com/dtm-labs/dtm/test/busi" "github.com/go-resty/resty/v2" diff --git a/test/tcc_old_test.go b/test/tcc_old_test.go index 4e38562..3e2f36e 100644 --- a/test/tcc_old_test.go +++ b/test/tcc_old_test.go @@ -3,8 +3,8 @@ package test import ( "testing" - "github.com/dtm-labs/dtm/dtmcli" - "github.com/dtm-labs/dtm/dtmcli/dtmimp" + "github.com/dtm-labs/dtm/client/dtmcli" + "github.com/dtm-labs/dtm/client/dtmcli/dtmimp" "github.com/dtm-labs/dtm/dtmutil" "github.com/dtm-labs/dtm/test/busi" "github.com/go-resty/resty/v2" diff --git a/test/tcc_test.go b/test/tcc_test.go index a1964ec..19b9d6d 100644 --- a/test/tcc_test.go +++ b/test/tcc_test.go @@ -9,8 +9,8 @@ package test import ( "testing" - "github.com/dtm-labs/dtm/dtmcli" - "github.com/dtm-labs/dtm/dtmcli/dtmimp" + "github.com/dtm-labs/dtm/client/dtmcli" + "github.com/dtm-labs/dtm/client/dtmcli/dtmimp" "github.com/dtm-labs/dtm/dtmutil" "github.com/dtm-labs/dtm/test/busi" "github.com/go-resty/resty/v2" @@ -46,7 +46,7 @@ func TestTccRollback(t *testing.T) { cronTransOnce(t, gid) assert.Equal(t, StatusFailed, getTransStatus(gid)) assert.Equal(t, []string{StatusSucceed, StatusPrepared, StatusSucceed, StatusPrepared}, getBranchesStatus(gid)) - assert.Equal(t, "{\"error\":\"reason:. FAILURE\"}. FAILURE", getTrans(gid).RollbackReason) + assert.Contains(t, getTrans(gid).RollbackReason, dtmcli.ResultFailure) } func TestTccTimeout(t *testing.T) { diff --git a/test/types.go b/test/types.go index 0f3ed43..821f543 100644 --- a/test/types.go +++ b/test/types.go @@ -10,9 +10,9 @@ import ( "testing" "time" - "github.com/dtm-labs/dtm/dtmcli" - "github.com/dtm-labs/dtm/dtmcli/dtmimp" - "github.com/dtm-labs/dtm/dtmcli/logger" + "github.com/dtm-labs/dtm/client/dtmcli" + "github.com/dtm-labs/dtm/client/dtmcli/dtmimp" + "github.com/dtm-labs/dtm/client/dtmcli/logger" "github.com/dtm-labs/dtm/dtmsvr" "github.com/dtm-labs/dtm/dtmsvr/config" "github.com/dtm-labs/dtm/dtmutil" diff --git a/test/workflow_base_test.go b/test/workflow_base_test.go index 885dba9..bb6d854 100644 --- a/test/workflow_base_test.go +++ b/test/workflow_base_test.go @@ -10,8 +10,8 @@ import ( "testing" "time" - "github.com/dtm-labs/dtm/dtmcli" - "github.com/dtm-labs/dtm/dtmcli/dtmimp" + "github.com/dtm-labs/dtm/client/dtmcli" + "github.com/dtm-labs/dtm/client/dtmcli/dtmimp" "github.com/dtm-labs/dtm/dtmsvr" "github.com/dtm-labs/dtm/dtmsvr/storage" "github.com/stretchr/testify/assert" diff --git a/test/workflow_grpc_test.go b/test/workflow_grpc_test.go index a01c3cf..726f83b 100644 --- a/test/workflow_grpc_test.go +++ b/test/workflow_grpc_test.go @@ -10,16 +10,16 @@ import ( "database/sql" "testing" - "github.com/dtm-labs/dtm/dtmcli" - "github.com/dtm-labs/dtm/dtmcli/dtmimp" - "github.com/dtm-labs/dtm/dtmgrpc/dtmgimp" - "github.com/dtm-labs/dtm/dtmgrpc/workflow" + "github.com/dtm-labs/dtm/client/dtmcli" + "github.com/dtm-labs/dtm/client/dtmcli/dtmimp" + "github.com/dtm-labs/dtm/client/dtmgrpc/dtmgimp" + "github.com/dtm-labs/dtm/client/workflow" "github.com/dtm-labs/dtm/test/busi" "github.com/stretchr/testify/assert" ) func TestWorkflowGrpcSimple(t *testing.T) { - workflow.SetProtocolForTest(dtmimp.ProtocolHTTP) + workflow.SetProtocolForTest(dtmimp.ProtocolGRPC) req := &busi.ReqGrpc{Amount: 30, TransInResult: "FAILURE"} gid := dtmimp.GetFuncName() workflow.Register(gid, func(wf *workflow.Workflow, data []byte) error { @@ -33,12 +33,11 @@ func TestWorkflowGrpcSimple(t *testing.T) { return err }) err := workflow.Execute(gid, gid, dtmgimp.MustProtoMarshal(req)) - assert.Error(t, err, dtmcli.ErrFailure) + assert.Error(t, err) assert.Equal(t, StatusFailed, getTransStatus(gid)) - waitTransProcessed(gid) } -func TestWorkflowGrpcNormal(t *testing.T) { +func TestWorkflowGrpcRollback(t *testing.T) { workflow.SetProtocolForTest(dtmimp.ProtocolGRPC) req := &busi.ReqGrpc{Amount: 30, TransInResult: "FAILURE"} gid := dtmimp.GetFuncName() @@ -60,52 +59,55 @@ func TestWorkflowGrpcNormal(t *testing.T) { _, err = busi.BusiCli.TransInBSaga(wf.Context, &req) return err }) + before := getBeforeBalances("mysql") err := workflow.Execute(gid, gid, dtmgimp.MustProtoMarshal(req)) assert.Error(t, err, dtmcli.ErrFailure) assert.Equal(t, StatusFailed, getTransStatus(gid)) - waitTransProcessed(gid) + assertSameBalance(t, before, "mysql") } func TestWorkflowMixed(t *testing.T) { workflow.SetProtocolForTest(dtmimp.ProtocolHTTP) - req := &busi.ReqGrpc{Amount: 30} gid := dtmimp.GetFuncName() - workflow.Register(gid, func(wf *workflow.Workflow, data []byte) error { + err := workflow.Register(gid, func(wf *workflow.Workflow, data []byte) error { var req busi.ReqGrpc dtmgimp.MustProtoUnmarshal(data, &req) - wf.NewBranch().OnRollback(func(bb *dtmcli.BranchBarrier) error { + _, err := wf.NewBranch().OnRollback(func(bb *dtmcli.BranchBarrier) error { _, err := busi.BusiCli.TransOutRevertBSaga(wf.Context, &req) return err + }).Do(func(bb *dtmcli.BranchBarrier) ([]byte, error) { + return nil, bb.CallWithDB(dbGet().ToSQLDB(), func(tx *sql.Tx) error { + return busi.SagaAdjustBalance(tx, busi.TransOutUID, int(-req.Amount), "") + }) }) - _, err := busi.BusiCli.TransOutBSaga(wf.Context, &req) if err != nil { return err } + req2 := &busi.ReqHTTP{Amount: int(req.Amount / 2)} _, err = wf.NewBranch().OnCommit(func(bb *dtmcli.BranchBarrier) error { - _, err := busi.BusiCli.TransInConfirm(wf.Context, &req) + _, err := wf.NewRequest().SetBody(req2).Post(Busi + "/TccBTransInConfirm") return err }).OnRollback(func(bb *dtmcli.BranchBarrier) error { - req2 := &busi.ReqHTTP{Amount: 30} - _, err := wf.NewRequest().SetBody(req2).Post(Busi + "/TransInRevert") + _, err := wf.NewRequest().SetBody(req2).Post(Busi + "/TccBTransInCancel") return err - }).Do(func(bb *dtmcli.BranchBarrier) ([]byte, error) { - err := busi.SagaAdjustBalance(dbGet().ToSQLDB(), busi.TransInUID, int(req.Amount), "") - return nil, err - }) + }).NewRequest().SetBody(req2).Post(Busi + "/TccBTransInTry") if err != nil { return err } _, err = wf.NewBranch().DoXa(busi.BusiConf, func(db *sql.DB) ([]byte, error) { - return nil, busi.SagaAdjustBalance(db, busi.TransInUID, 0, dtmcli.ResultSuccess) + return nil, busi.SagaAdjustBalance(db, busi.TransInUID, int(req.Amount/2), dtmcli.ResultSuccess) }) return err }) - err := workflow.Execute(gid, gid, dtmgimp.MustProtoMarshal(req)) + assert.Nil(t, err) + before := getBeforeBalances("mysql") + req := &busi.ReqGrpc{Amount: 30} + err = workflow.Execute(gid, gid, dtmgimp.MustProtoMarshal(req)) assert.Nil(t, err) assert.Equal(t, StatusSucceed, getTransStatus(gid)) - waitTransProcessed(gid) + assertNotSameBalance(t, before, "mysql") } func TestWorkflowGrpcError(t *testing.T) { @@ -125,7 +127,6 @@ func TestWorkflowGrpcError(t *testing.T) { }) err := workflow.Execute(gid, gid, dtmgimp.MustProtoMarshal(req)) assert.Error(t, err) - go waitTransProcessed(gid) cronTransOnceForwardCron(t, gid, 1000) assert.Equal(t, StatusSucceed, getTransStatus(gid)) } diff --git a/test/workflow_http_test.go b/test/workflow_http_test.go index e8b8de2..59b9d55 100644 --- a/test/workflow_http_test.go +++ b/test/workflow_http_test.go @@ -10,10 +10,10 @@ import ( "database/sql" "testing" - "github.com/dtm-labs/dtm/dtmcli" - "github.com/dtm-labs/dtm/dtmcli/dtmimp" - "github.com/dtm-labs/dtm/dtmcli/logger" - "github.com/dtm-labs/dtm/dtmgrpc/workflow" + "github.com/dtm-labs/dtm/client/dtmcli" + "github.com/dtm-labs/dtm/client/dtmcli/dtmimp" + "github.com/dtm-labs/dtm/client/dtmcli/logger" + "github.com/dtm-labs/dtm/client/workflow" "github.com/dtm-labs/dtm/test/busi" "github.com/stretchr/testify/assert" ) @@ -43,7 +43,6 @@ func TestWorkflowNormal(t *testing.T) { err := workflow.Execute(gid, gid, dtmimp.MustMarshal(req)) assert.Nil(t, err) - waitTransProcessed(gid) assert.Equal(t, StatusSucceed, getTransStatus(gid)) } @@ -81,11 +80,88 @@ func TestWorkflowRollback(t *testing.T) { } return nil }) + before := getBeforeBalances("mysql") err := workflow.Execute(gid, gid, dtmimp.MustMarshal(req)) assert.Error(t, err, dtmcli.ErrFailure) assert.Equal(t, StatusFailed, getTransStatus(gid)) - waitTransProcessed(gid) + assertSameBalance(t, before, "mysql") +} + +func TestWorkflowTcc(t *testing.T) { + workflow.SetProtocolForTest(dtmimp.ProtocolHTTP) + req := busi.GenReqHTTP(30, false, false) + gid := dtmimp.GetFuncName() + + workflow.Register(gid, func(wf *workflow.Workflow, data []byte) error { + var req busi.ReqHTTP + dtmimp.MustUnmarshal(data, &req) + _, err := wf.NewBranch().OnRollback(func(bb *dtmcli.BranchBarrier) error { + _, err := wf.NewRequest().SetBody(req).Post(Busi + "/TccBTransOutCancel") + return err + }).OnCommit(func(bb *dtmcli.BranchBarrier) error { + _, err := wf.NewRequest().SetBody(req).Post(Busi + "/TccBTransOutConfirm") + return err + }).NewRequest().SetBody(req).Post(Busi + "/TccBTransOutTry") + if err != nil { + return err + } + _, err = wf.NewBranch().OnRollback(func(bb *dtmcli.BranchBarrier) error { + _, err := wf.NewRequest().SetBody(req).Post(Busi + "/TccBTransInCancel") + return err + }).OnCommit(func(bb *dtmcli.BranchBarrier) error { + _, err := wf.NewRequest().SetBody(req).Post(Busi + "/TccBTransInConfirm") + return err + }).NewRequest().SetBody(req).Post(Busi + "/TccBTransInTry") + if err != nil { + return err + } + return nil + }) + + before := getBeforeBalances("mysql") + err := workflow.Execute(gid, gid, dtmimp.MustMarshal(req)) + assert.Nil(t, err) + assert.Equal(t, StatusSucceed, getTransStatus(gid)) + assertNotSameBalance(t, before, "mysql") +} + +func TestWorkflowTccRollback(t *testing.T) { + workflow.SetProtocolForTest(dtmimp.ProtocolHTTP) + req := busi.GenReqHTTP(30, false, true) + gid := dtmimp.GetFuncName() + + workflow.Register(gid, func(wf *workflow.Workflow, data []byte) error { + var req busi.ReqHTTP + dtmimp.MustUnmarshal(data, &req) + _, err := wf.NewBranch().OnRollback(func(bb *dtmcli.BranchBarrier) error { + _, err := wf.NewRequest().SetBody(req).Post(Busi + "/TccBTransOutCancel") + return err + }).OnCommit(func(bb *dtmcli.BranchBarrier) error { + _, err := wf.NewRequest().SetBody(req).Post(Busi + "/TccBTransOutConfirm") + return err + }).NewRequest().SetBody(req).Post(Busi + "/TccBTransOutTry") + if err != nil { + return err + } + _, err = wf.NewBranch().OnRollback(func(bb *dtmcli.BranchBarrier) error { + _, err := wf.NewRequest().SetBody(req).Post(Busi + "/TccBTransInCancel") + return err + }).OnCommit(func(bb *dtmcli.BranchBarrier) error { + _, err := wf.NewRequest().SetBody(req).Post(Busi + "/TccBTransInConfirm") + return err + }).NewRequest().SetBody(req).Post(Busi + "/TccBTransInTry") + if err != nil { + return err + } + return nil + }) + + before := getBeforeBalances("mysql") + err := workflow.Execute(gid, gid, dtmimp.MustMarshal(req)) + assert.Error(t, err) + assert.Equal(t, StatusFailed, getTransStatus(gid)) + assertSameBalance(t, before, "mysql") } func TestWorkflowError(t *testing.T) { @@ -103,7 +179,6 @@ func TestWorkflowError(t *testing.T) { err := workflow.Execute(gid, gid, dtmimp.MustMarshal(req)) assert.Error(t, err) - go waitTransProcessed(gid) cronTransOnceForwardCron(t, gid, 1000) assert.Equal(t, StatusSucceed, getTransStatus(gid)) } @@ -123,7 +198,6 @@ func TestWorkflowOngoing(t *testing.T) { err := workflow.Execute(gid, gid, dtmimp.MustMarshal(req)) assert.Error(t, err) - go waitTransProcessed(gid) cronTransOnceForwardCron(t, gid, 1000) assert.Equal(t, StatusSucceed, getTransStatus(gid)) } diff --git a/test/workflow_ongoing_test.go b/test/workflow_ongoing_test.go index 6d55864..4aa31c6 100644 --- a/test/workflow_ongoing_test.go +++ b/test/workflow_ongoing_test.go @@ -10,11 +10,11 @@ import ( "database/sql" "testing" - "github.com/dtm-labs/dtm/dtmcli" - "github.com/dtm-labs/dtm/dtmcli/dtmimp" - "github.com/dtm-labs/dtm/dtmcli/logger" - "github.com/dtm-labs/dtm/dtmgrpc/dtmgimp" - "github.com/dtm-labs/dtm/dtmgrpc/workflow" + "github.com/dtm-labs/dtm/client/dtmcli" + "github.com/dtm-labs/dtm/client/dtmcli/dtmimp" + "github.com/dtm-labs/dtm/client/dtmcli/logger" + "github.com/dtm-labs/dtm/client/dtmgrpc/dtmgimp" + "github.com/dtm-labs/dtm/client/workflow" "github.com/dtm-labs/dtm/test/busi" "github.com/stretchr/testify/assert" ) @@ -49,7 +49,6 @@ func TestWorkflowSimpleResume(t *testing.T) { err := workflow.Execute(gid, gid, dtmimp.MustMarshal(req)) assert.Error(t, err) - go waitTransProcessed(gid) cronTransOnceForwardNow(t, gid, 1000) assert.Equal(t, StatusSucceed, getTransStatus(gid)) } @@ -93,6 +92,7 @@ func TestWorkflowGrpcRollbackResume(t *testing.T) { }, func(wf *workflow.Workflow) { wf.Options.CompensateErrorBranch = true }) + before := getBeforeBalances("mysql") req := &busi.ReqGrpc{Amount: 30, TransInResult: "FAILURE"} err := workflow.Execute(gid, gid, dtmgimp.MustProtoMarshal(req)) assert.Error(t, err, dtmcli.ErrOngoing) @@ -105,10 +105,9 @@ func TestWorkflowGrpcRollbackResume(t *testing.T) { assert.Equal(t, StatusPrepared, getTransStatus(gid)) cronTransOnceForwardNow(t, gid, 1000) assert.Equal(t, StatusPrepared, getTransStatus(gid)) - // next cron will make a workflow submit, and do an additional write to chan, so make an additional read chan - go waitTransProcessed(gid) cronTransOnceForwardNow(t, gid, 1000) assert.Equal(t, StatusFailed, getTransStatus(gid)) + assertSameBalance(t, before, "mysql") } func TestWorkflowXaResume(t *testing.T) { @@ -140,6 +139,7 @@ func TestWorkflowXaResume(t *testing.T) { return err }) + before := getBeforeBalances("mysql") err := workflow.Execute(gid, gid, nil) assert.Equal(t, dtmcli.ErrOngoing, err) @@ -147,8 +147,7 @@ func TestWorkflowXaResume(t *testing.T) { assert.Equal(t, StatusPrepared, getTransStatus(gid)) cronTransOnceForwardNow(t, gid, 1000) assert.Equal(t, StatusPrepared, getTransStatus(gid)) - // next cron will make a workflow submit, and do an additional write to chan, so make an additional read chan - go waitTransProcessed(gid) cronTransOnceForwardNow(t, gid, 1000) assert.Equal(t, StatusSucceed, getTransStatus(gid)) + assertNotSameBalance(t, before, "mysql") } diff --git a/test/workflow_xa_test.go b/test/workflow_xa_test.go index b488f7c..84030e6 100644 --- a/test/workflow_xa_test.go +++ b/test/workflow_xa_test.go @@ -10,10 +10,10 @@ import ( "database/sql" "testing" - "github.com/dtm-labs/dtm/dtmcli" - "github.com/dtm-labs/dtm/dtmcli/dtmimp" - "github.com/dtm-labs/dtm/dtmcli/logger" - "github.com/dtm-labs/dtm/dtmgrpc/workflow" + "github.com/dtm-labs/dtm/client/dtmcli" + "github.com/dtm-labs/dtm/client/dtmcli/dtmimp" + "github.com/dtm-labs/dtm/client/dtmcli/logger" + "github.com/dtm-labs/dtm/client/workflow" "github.com/dtm-labs/dtm/test/busi" "github.com/stretchr/testify/assert" ) @@ -33,10 +33,11 @@ func TestWorkflowXaAction(t *testing.T) { }) return err }) + before := getBeforeBalances("mysql") err := workflow.Execute(gid, gid, nil) assert.Nil(t, err) - waitTransProcessed(gid) assert.Equal(t, StatusSucceed, getTransStatus(gid)) + assertNotSameBalance(t, before, "mysql") } func TestWorkflowXaRollback(t *testing.T) { @@ -56,8 +57,9 @@ func TestWorkflowXaRollback(t *testing.T) { }) return err }) + before := getBeforeBalances("mysql") err := workflow.Execute(gid, gid, nil) assert.Equal(t, dtmcli.ErrFailure, err) - waitTransProcessed(gid) assert.Equal(t, StatusFailed, getTransStatus(gid)) + assertSameBalance(t, before, "mysql") } diff --git a/test/xa_cover_test.go b/test/xa_cover_test.go index 371b8be..5d2e76e 100644 --- a/test/xa_cover_test.go +++ b/test/xa_cover_test.go @@ -3,8 +3,8 @@ package test import ( "testing" - "github.com/dtm-labs/dtm/dtmcli" - "github.com/dtm-labs/dtm/dtmcli/dtmimp" + "github.com/dtm-labs/dtm/client/dtmcli" + "github.com/dtm-labs/dtm/client/dtmcli/dtmimp" "github.com/dtm-labs/dtm/test/busi" "github.com/go-resty/resty/v2" "github.com/stretchr/testify/assert" diff --git a/test/xa_grpc_test.go b/test/xa_grpc_test.go index c6f334c..47042ec 100644 --- a/test/xa_grpc_test.go +++ b/test/xa_grpc_test.go @@ -11,8 +11,8 @@ import ( "fmt" "testing" - "github.com/dtm-labs/dtm/dtmcli/dtmimp" - "github.com/dtm-labs/dtm/dtmgrpc" + "github.com/dtm-labs/dtm/client/dtmcli/dtmimp" + "github.com/dtm-labs/dtm/client/dtmgrpc" "github.com/dtm-labs/dtm/test/busi" "github.com/stretchr/testify/assert" "google.golang.org/protobuf/types/known/emptypb" diff --git a/test/xa_test.go b/test/xa_test.go index 49016a7..146148d 100644 --- a/test/xa_test.go +++ b/test/xa_test.go @@ -10,8 +10,8 @@ import ( "fmt" "testing" - "github.com/dtm-labs/dtm/dtmcli" - "github.com/dtm-labs/dtm/dtmcli/dtmimp" + "github.com/dtm-labs/dtm/client/dtmcli" + "github.com/dtm-labs/dtm/client/dtmcli/dtmimp" "github.com/dtm-labs/dtm/dtmutil" "github.com/dtm-labs/dtm/test/busi" "github.com/go-resty/resty/v2"