remove logrus
This commit is contained in:
parent
5ecc66213c
commit
9e8359c893
@ -8,7 +8,7 @@ import (
|
|||||||
|
|
||||||
_ "github.com/go-sql-driver/mysql"
|
_ "github.com/go-sql-driver/mysql"
|
||||||
// _ "github.com/lib/pq"
|
// _ "github.com/lib/pq"
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
"gorm.io/driver/mysql"
|
"gorm.io/driver/mysql"
|
||||||
|
|
||||||
// "gorm.io/driver/postgres"
|
// "gorm.io/driver/postgres"
|
||||||
@ -78,7 +78,7 @@ func (op *tracePlugin) Initialize(db *gorm.DB) (err error) {
|
|||||||
after := func(db *gorm.DB) {
|
after := func(db *gorm.DB) {
|
||||||
_ts, _ := db.InstanceGet("ivy.startTime")
|
_ts, _ := db.InstanceGet("ivy.startTime")
|
||||||
sql := db.Dialector.Explain(db.Statement.SQL.String(), db.Statement.Vars...)
|
sql := db.Dialector.Explain(db.Statement.SQL.String(), db.Statement.Vars...)
|
||||||
logrus.Printf("used: %d ms affected: %d sql is: %s", time.Since(_ts.(time.Time)).Milliseconds(), db.RowsAffected, sql)
|
Logf("used: %d ms affected: %d sql is: %s", time.Since(_ts.(time.Time)).Milliseconds(), db.RowsAffected, sql)
|
||||||
if v, ok := db.InstanceGet("ivy.must"); ok && v.(bool) {
|
if v, ok := db.InstanceGet("ivy.must"); ok && v.(bool) {
|
||||||
if db.Error != nil && db.Error != gorm.ErrRecordNotFound {
|
if db.Error != nil && db.Error != gorm.ErrRecordNotFound {
|
||||||
panic(db.Error)
|
panic(db.Error)
|
||||||
@ -89,7 +89,7 @@ func (op *tracePlugin) Initialize(db *gorm.DB) (err error) {
|
|||||||
beforeName := "cb_before"
|
beforeName := "cb_before"
|
||||||
afterName := "cb_after"
|
afterName := "cb_after"
|
||||||
|
|
||||||
logrus.Printf("installing db plugin: %s", op.Name())
|
Logf("installing db plugin: %s", op.Name())
|
||||||
// 开始前
|
// 开始前
|
||||||
_ = db.Callback().Create().Before("gorm:before_create").Register(beforeName, before)
|
_ = db.Callback().Create().Before("gorm:before_create").Register(beforeName, before)
|
||||||
_ = db.Callback().Query().Before("gorm:query").Register(beforeName, before)
|
_ = db.Callback().Query().Before("gorm:query").Register(beforeName, before)
|
||||||
@ -126,7 +126,7 @@ func GetDsn(conf map[string]string) string {
|
|||||||
func DbGet(conf map[string]string) *DB {
|
func DbGet(conf map[string]string) *DB {
|
||||||
dsn := GetDsn(conf)
|
dsn := GetDsn(conf)
|
||||||
if dbs[dsn] == nil {
|
if dbs[dsn] == nil {
|
||||||
logrus.Printf("connecting %s", strings.Replace(dsn, conf["password"], "****", 1))
|
Logf("connecting %s", strings.Replace(dsn, conf["password"], "****", 1))
|
||||||
db1, err := gorm.Open(getGormDialator(conf["driver"], dsn), &gorm.Config{
|
db1, err := gorm.Open(getGormDialator(conf["driver"], dsn), &gorm.Config{
|
||||||
SkipDefaultTransaction: true,
|
SkipDefaultTransaction: true,
|
||||||
})
|
})
|
||||||
@ -149,7 +149,7 @@ func SdbGet(conf map[string]string) *sql.DB {
|
|||||||
// SdbAlone get a standalone db connection
|
// SdbAlone get a standalone db connection
|
||||||
func SdbAlone(conf map[string]string) *sql.DB {
|
func SdbAlone(conf map[string]string) *sql.DB {
|
||||||
dsn := GetDsn(conf)
|
dsn := GetDsn(conf)
|
||||||
logrus.Printf("opening alone %s: %s", conf["driver"], strings.Replace(dsn, conf["password"], "****", 1))
|
Logf("opening alone %s: %s", conf["driver"], strings.Replace(dsn, conf["password"], "****", 1))
|
||||||
mdb, err := sql.Open(conf["driver"], dsn)
|
mdb, err := sql.Open(conf["driver"], dsn)
|
||||||
E2P(err)
|
E2P(err)
|
||||||
return mdb
|
return mdb
|
||||||
@ -160,9 +160,9 @@ func SdbExec(db *sql.DB, sql string, values ...interface{}) (affected int64, rer
|
|||||||
r, rerr := db.Exec(sql, values...)
|
r, rerr := db.Exec(sql, values...)
|
||||||
if rerr == nil {
|
if rerr == nil {
|
||||||
affected, rerr = r.RowsAffected()
|
affected, rerr = r.RowsAffected()
|
||||||
logrus.Printf("affected: %d for %s %v", affected, sql, values)
|
Logf("affected: %d for %s %v", affected, sql, values)
|
||||||
} else {
|
} else {
|
||||||
RedLogf("exec error: %v for %s %v", rerr, sql, values)
|
LogRedf("exec error: %v for %s %v", rerr, sql, values)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -172,15 +172,15 @@ func StxExec(tx *sql.Tx, sql string, values ...interface{}) (affected int64, rer
|
|||||||
r, rerr := tx.Exec(sql, values...)
|
r, rerr := tx.Exec(sql, values...)
|
||||||
if rerr == nil {
|
if rerr == nil {
|
||||||
affected, rerr = r.RowsAffected()
|
affected, rerr = r.RowsAffected()
|
||||||
logrus.Printf("affected: %d for %s %v", affected, sql, values)
|
Logf("affected: %d for %s %v", affected, sql, values)
|
||||||
} else {
|
} else {
|
||||||
RedLogf("exec error: %v for %s %v", rerr, sql, values)
|
LogRedf("exec error: %v for %s %v", rerr, sql, values)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// StxQueryRow use raw tx to query row
|
// StxQueryRow use raw tx to query row
|
||||||
func StxQueryRow(tx *sql.Tx, query string, args ...interface{}) *sql.Row {
|
func StxQueryRow(tx *sql.Tx, query string, args ...interface{}) *sql.Row {
|
||||||
logrus.Printf("querying: "+query, args...)
|
Logf("querying: "+query, args...)
|
||||||
return tx.QueryRow(query, args...)
|
return tx.QueryRow(query, args...)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -125,9 +125,9 @@ func GetGinApp() *gin.Engine {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
began := time.Now()
|
began := time.Now()
|
||||||
logrus.Printf("begin %s %s query: %s body: %s", c.Request.Method, c.FullPath(), c.Request.URL.RawQuery, body)
|
Logf("begin %s %s query: %s body: %s", c.Request.Method, c.FullPath(), c.Request.URL.RawQuery, body)
|
||||||
c.Next()
|
c.Next()
|
||||||
logrus.Printf("used %d ms %s %s query: %s body: %s", time.Since(began).Milliseconds(), c.Request.Method, c.FullPath(), c.Request.URL.RawQuery, body)
|
Logf("used %d ms %s %s query: %s body: %s", time.Since(began).Milliseconds(), c.Request.Method, c.FullPath(), c.Request.URL.RawQuery, body)
|
||||||
|
|
||||||
})
|
})
|
||||||
app.Any("/api/ping", func(c *gin.Context) { c.JSON(200, M{"msg": "pong"}) })
|
app.Any("/api/ping", func(c *gin.Context) { c.JSON(200, M{"msg": "pong"}) })
|
||||||
@ -145,10 +145,10 @@ func WrapHandler(fn func(*gin.Context) (interface{}, error)) gin.HandlerFunc {
|
|||||||
b, err = json.Marshal(r)
|
b, err = json.Marshal(r)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Printf("status: 500, code: 500 message: %s", err.Error())
|
Logf("status: 500, code: 500 message: %s", err.Error())
|
||||||
c.JSON(500, M{"code": 500, "message": err.Error()})
|
c.JSON(500, M{"code": 500, "message": err.Error()})
|
||||||
} else {
|
} else {
|
||||||
logrus.Printf("status: 200, content: %s", string(b))
|
Logf("status: 200, content: %s", string(b))
|
||||||
c.Status(200)
|
c.Status(200)
|
||||||
c.Writer.Header().Add("Content-Type", "application/json")
|
c.Writer.Header().Add("Content-Type", "application/json")
|
||||||
_, err = c.Writer.Write(b)
|
_, err = c.Writer.Write(b)
|
||||||
@ -166,12 +166,12 @@ func init() {
|
|||||||
// RestyClient.SetRetryWaitTime(1 * time.Second)
|
// RestyClient.SetRetryWaitTime(1 * time.Second)
|
||||||
RestyClient.OnBeforeRequest(func(c *resty.Client, r *resty.Request) error {
|
RestyClient.OnBeforeRequest(func(c *resty.Client, r *resty.Request) error {
|
||||||
r.URL = MayReplaceLocalhost(r.URL)
|
r.URL = MayReplaceLocalhost(r.URL)
|
||||||
logrus.Printf("requesting: %s %s %v %v", r.Method, r.URL, r.Body, r.QueryParam)
|
Logf("requesting: %s %s %v %v", r.Method, r.URL, r.Body, r.QueryParam)
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
RestyClient.OnAfterResponse(func(c *resty.Client, resp *resty.Response) error {
|
RestyClient.OnAfterResponse(func(c *resty.Client, resp *resty.Response) error {
|
||||||
r := resp.Request
|
r := resp.Request
|
||||||
logrus.Printf("requested: %s %s %s", r.Method, r.URL, resp.String())
|
Logf("requested: %s %s %s", r.Method, r.URL, resp.String())
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -184,15 +184,9 @@ func CheckRestySuccess(resp *resty.Response, err error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// formatter 自定义formatter
|
// Logf 输出日志
|
||||||
type formatter struct{}
|
func Logf(format string, args ...interface{}) {
|
||||||
|
msg := fmt.Sprintf(format, args...)
|
||||||
// Format 进行格式化
|
|
||||||
func (f *formatter) Format(entry *logrus.Entry) ([]byte, error) {
|
|
||||||
var b *bytes.Buffer = &bytes.Buffer{}
|
|
||||||
if entry.Buffer != nil {
|
|
||||||
b = entry.Buffer
|
|
||||||
}
|
|
||||||
n := time.Now()
|
n := time.Now()
|
||||||
ts := fmt.Sprintf("%d-%02d-%02d %02d:%02d:%02d.%03d", n.Year(), n.Month(), n.Day(), n.Hour(), n.Minute(), n.Second(), n.Nanosecond()/1000000)
|
ts := fmt.Sprintf("%d-%02d-%02d %02d:%02d:%02d.%03d", n.Year(), n.Month(), n.Day(), n.Hour(), n.Minute(), n.Second(), n.Nanosecond()/1000000)
|
||||||
var file string
|
var file string
|
||||||
@ -203,23 +197,21 @@ func (f *formatter) Format(entry *logrus.Entry) ([]byte, error) {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
b.WriteString(fmt.Sprintf("%s %s:%d %s\n", ts, path.Base(file), line, entry.Message))
|
fmt.Printf("%s %s:%d %s\n", ts, path.Base(file), line, msg)
|
||||||
return b.Bytes(), nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// RedLogf 采用红色打印错误类信息
|
// LogRedf 采用红色打印错误类信息
|
||||||
func RedLogf(fmt string, args ...interface{}) {
|
func LogRedf(fmt string, args ...interface{}) {
|
||||||
logrus.Errorf("\x1b[31m\n"+fmt+"\x1b[0m\n", args...)
|
logrus.Errorf("\x1b[31m\n"+fmt+"\x1b[0m\n", args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// InitConfig init config
|
// InitConfig init config
|
||||||
func InitConfig(dir string, config interface{}) {
|
func InitConfig(dir string, config interface{}) {
|
||||||
logrus.SetFormatter(&formatter{})
|
|
||||||
cont, err := ioutil.ReadFile(dir + "/conf.yml")
|
cont, err := ioutil.ReadFile(dir + "/conf.yml")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
cont, err = ioutil.ReadFile(dir + "/conf.sample.yml")
|
cont, err = ioutil.ReadFile(dir + "/conf.sample.yml")
|
||||||
}
|
}
|
||||||
logrus.Printf("cont is: \n%s", string(cont))
|
Logf("cont is: \n%s", string(cont))
|
||||||
E2P(err)
|
E2P(err)
|
||||||
err = yaml.Unmarshal(cont, config)
|
err = yaml.Unmarshal(cont, config)
|
||||||
E2P(err)
|
E2P(err)
|
||||||
|
|||||||
@ -8,7 +8,6 @@ import (
|
|||||||
"net/url"
|
"net/url"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
"github.com/yedf/dtm/common"
|
"github.com/yedf/dtm/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -79,7 +78,7 @@ func ThroughBarrierCall(db *sql.DB, transInfo *TransInfo, busiCall BusiFunc) (re
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer func() {
|
defer func() {
|
||||||
logrus.Printf("result is %v error is %v", res, rerr)
|
common.Logf("result is %v error is %v", res, rerr)
|
||||||
if x := recover(); x != nil {
|
if x := recover(); x != nil {
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
panic(x)
|
panic(x)
|
||||||
@ -96,7 +95,7 @@ func ThroughBarrierCall(db *sql.DB, transInfo *TransInfo, busiCall BusiFunc) (re
|
|||||||
}[ti.BranchType]
|
}[ti.BranchType]
|
||||||
originAffected, _ := insertBarrier(tx, ti.TransType, ti.Gid, ti.BranchID, originType, ti.BranchType)
|
originAffected, _ := insertBarrier(tx, ti.TransType, ti.Gid, ti.BranchID, originType, ti.BranchType)
|
||||||
currentAffected, rerr := insertBarrier(tx, ti.TransType, ti.Gid, ti.BranchID, ti.BranchType, ti.BranchType)
|
currentAffected, rerr := insertBarrier(tx, ti.TransType, ti.Gid, ti.BranchID, ti.BranchType, ti.BranchType)
|
||||||
logrus.Printf("originAffected: %d currentAffected: %d", originAffected, currentAffected)
|
common.Logf("originAffected: %d currentAffected: %d", originAffected, currentAffected)
|
||||||
if (ti.BranchType == "cancel" || ti.BranchType == "compensate") && originAffected > 0 { // 这个是空补偿,返回成功
|
if (ti.BranchType == "cancel" || ti.BranchType == "compensate") && originAffected > 0 { // 这个是空补偿,返回成功
|
||||||
res = ResultSuccess
|
res = ResultSuccess
|
||||||
return
|
return
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
package dtmcli
|
package dtmcli
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
"github.com/yedf/dtm/common"
|
"github.com/yedf/dtm/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -40,7 +39,7 @@ func NewMsg(server string, gid string) *Msg {
|
|||||||
|
|
||||||
// Add add a new step
|
// Add add a new step
|
||||||
func (s *Msg) Add(action string, postData interface{}) *Msg {
|
func (s *Msg) Add(action string, postData interface{}) *Msg {
|
||||||
logrus.Printf("msg %s Add %s %v", s.MsgData.Gid, action, postData)
|
common.Logf("msg %s Add %s %v", s.MsgData.Gid, action, postData)
|
||||||
step := MsgStep{
|
step := MsgStep{
|
||||||
Action: action,
|
Action: action,
|
||||||
Data: common.MustMarshalString(postData),
|
Data: common.MustMarshalString(postData),
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
package dtmcli
|
package dtmcli
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
"github.com/yedf/dtm/common"
|
"github.com/yedf/dtm/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -40,7 +39,7 @@ func NewSaga(server string, gid string) *Saga {
|
|||||||
|
|
||||||
// Add add a saga step
|
// Add add a saga step
|
||||||
func (s *Saga) Add(action string, compensate string, postData interface{}) *Saga {
|
func (s *Saga) Add(action string, compensate string, postData interface{}) *Saga {
|
||||||
logrus.Printf("saga %s Add %s %s %v", s.SagaData.Gid, action, compensate, postData)
|
common.Logf("saga %s Add %s %s %v", s.SagaData.Gid, action, compensate, postData)
|
||||||
step := SagaStep{
|
step := SagaStep{
|
||||||
Action: action,
|
Action: action,
|
||||||
Compensate: compensate,
|
Compensate: compensate,
|
||||||
|
|||||||
@ -7,7 +7,6 @@ import (
|
|||||||
"runtime/debug"
|
"runtime/debug"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
"github.com/yedf/dtm/common"
|
"github.com/yedf/dtm/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -55,7 +54,7 @@ func lockOneTrans(expireIn time.Duration) *TransGlobal {
|
|||||||
|
|
||||||
func handlePanic(perr *error) {
|
func handlePanic(perr *error) {
|
||||||
if err := recover(); err != nil {
|
if err := recover(); err != nil {
|
||||||
common.RedLogf("----panic %v handlered\n%s", err, string(debug.Stack()))
|
common.LogRedf("----panic %v handlered\n%s", err, string(debug.Stack()))
|
||||||
if perr != nil {
|
if perr != nil {
|
||||||
*perr = fmt.Errorf("dtm panic: %v", err)
|
*perr = fmt.Errorf("dtm panic: %v", err)
|
||||||
}
|
}
|
||||||
@ -65,6 +64,6 @@ func handlePanic(perr *error) {
|
|||||||
func sleepCronTime() {
|
func sleepCronTime() {
|
||||||
delta := math.Min(3, float64(config.TransCronInterval))
|
delta := math.Min(3, float64(config.TransCronInterval))
|
||||||
interval := time.Duration((float64(config.TransCronInterval) - rand.Float64()*delta) * float64(time.Second))
|
interval := time.Duration((float64(config.TransCronInterval) - rand.Float64()*delta) * float64(time.Second))
|
||||||
logrus.Printf("sleeping for %v", interval)
|
common.Logf("sleeping for %v", interval)
|
||||||
time.Sleep(interval)
|
time.Sleep(interval)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,7 +6,6 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/yedf/dtm/common"
|
"github.com/yedf/dtm/common"
|
||||||
"github.com/yedf/dtm/dtmcli"
|
"github.com/yedf/dtm/dtmcli"
|
||||||
@ -103,7 +102,7 @@ func assertSucceed(t *testing.T, gid string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func genMsg(gid string) *dtmcli.Msg {
|
func genMsg(gid string) *dtmcli.Msg {
|
||||||
logrus.Printf("beginning a msg test ---------------- %s", gid)
|
common.Logf("beginning a msg test ---------------- %s", gid)
|
||||||
msg := dtmcli.NewMsg(examples.DtmServer, gid)
|
msg := dtmcli.NewMsg(examples.DtmServer, gid)
|
||||||
msg.QueryPrepared = examples.Busi + "/CanSubmit"
|
msg.QueryPrepared = examples.Busi + "/CanSubmit"
|
||||||
req := examples.GenTransReq(30, false, false)
|
req := examples.GenTransReq(30, false, false)
|
||||||
@ -113,7 +112,7 @@ func genMsg(gid string) *dtmcli.Msg {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func genSaga(gid string, outFailed bool, inFailed bool) *dtmcli.Saga {
|
func genSaga(gid string, outFailed bool, inFailed bool) *dtmcli.Saga {
|
||||||
logrus.Printf("beginning a saga test ---------------- %s", gid)
|
common.Logf("beginning a saga test ---------------- %s", gid)
|
||||||
saga := dtmcli.NewSaga(examples.DtmServer, gid)
|
saga := dtmcli.NewSaga(examples.DtmServer, gid)
|
||||||
req := examples.GenTransReq(30, outFailed, inFailed)
|
req := examples.GenTransReq(30, outFailed, inFailed)
|
||||||
saga.Add(examples.Busi+"/TransOut", examples.Busi+"/TransOutRevert", &req)
|
saga.Add(examples.Busi+"/TransOut", examples.Busi+"/TransOutRevert", &req)
|
||||||
@ -153,7 +152,7 @@ func TestSqlDB(t *testing.T) {
|
|||||||
}
|
}
|
||||||
db.Must().Exec("insert ignore into dtm_barrier.barrier(trans_type, gid, branch_id, branch_type, reason) values('saga', 'gid1', 'branch_id1', 'action', 'saga')")
|
db.Must().Exec("insert ignore into dtm_barrier.barrier(trans_type, gid, branch_id, branch_type, reason) values('saga', 'gid1', 'branch_id1', 'action', 'saga')")
|
||||||
_, err := dtmcli.ThroughBarrierCall(db.ToSQLDB(), transInfo, func(db *sql.Tx) (interface{}, error) {
|
_, err := dtmcli.ThroughBarrierCall(db.ToSQLDB(), transInfo, func(db *sql.Tx) (interface{}, error) {
|
||||||
logrus.Printf("rollback gid2")
|
common.Logf("rollback gid2")
|
||||||
return nil, fmt.Errorf("gid2 error")
|
return nil, fmt.Errorf("gid2 error")
|
||||||
})
|
})
|
||||||
asserts.Error(err, fmt.Errorf("gid2 error"))
|
asserts.Error(err, fmt.Errorf("gid2 error"))
|
||||||
@ -163,14 +162,14 @@ func TestSqlDB(t *testing.T) {
|
|||||||
asserts.Equal(dbr.RowsAffected, int64(0))
|
asserts.Equal(dbr.RowsAffected, int64(0))
|
||||||
gid2Res := common.M{"result": "first"}
|
gid2Res := common.M{"result": "first"}
|
||||||
_, err = dtmcli.ThroughBarrierCall(db.ToSQLDB(), transInfo, func(db *sql.Tx) (interface{}, error) {
|
_, err = dtmcli.ThroughBarrierCall(db.ToSQLDB(), transInfo, func(db *sql.Tx) (interface{}, error) {
|
||||||
logrus.Printf("submit gid2")
|
common.Logf("submit gid2")
|
||||||
return gid2Res, nil
|
return gid2Res, nil
|
||||||
})
|
})
|
||||||
asserts.Nil(err)
|
asserts.Nil(err)
|
||||||
dbr = db.Model(&dtmcli.BarrierModel{}).Where("gid=?", "gid2").Find(&[]dtmcli.BarrierModel{})
|
dbr = db.Model(&dtmcli.BarrierModel{}).Where("gid=?", "gid2").Find(&[]dtmcli.BarrierModel{})
|
||||||
asserts.Equal(dbr.RowsAffected, int64(1))
|
asserts.Equal(dbr.RowsAffected, int64(1))
|
||||||
newResult, err := dtmcli.ThroughBarrierCall(db.ToSQLDB(), transInfo, func(db *sql.Tx) (interface{}, error) {
|
newResult, err := dtmcli.ThroughBarrierCall(db.ToSQLDB(), transInfo, func(db *sql.Tx) (interface{}, error) {
|
||||||
logrus.Printf("submit gid2")
|
common.Logf("submit gid2")
|
||||||
return common.MS{"result": "ignored"}, nil
|
return common.MS{"result": "ignored"}, nil
|
||||||
})
|
})
|
||||||
asserts.Equal(newResult, gid2Res)
|
asserts.Equal(newResult, gid2Res)
|
||||||
|
|||||||
@ -4,7 +4,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
"github.com/yedf/dtm/common"
|
"github.com/yedf/dtm/common"
|
||||||
"github.com/yedf/dtm/examples"
|
"github.com/yedf/dtm/examples"
|
||||||
)
|
)
|
||||||
@ -13,10 +12,10 @@ var dtmsvrPort = 8080
|
|||||||
|
|
||||||
// StartSvr StartSvr
|
// StartSvr StartSvr
|
||||||
func StartSvr() {
|
func StartSvr() {
|
||||||
logrus.Printf("start dtmsvr")
|
common.Logf("start dtmsvr")
|
||||||
app := common.GetGinApp()
|
app := common.GetGinApp()
|
||||||
addRoute(app)
|
addRoute(app)
|
||||||
logrus.Printf("dtmsvr listen at: %d", dtmsvrPort)
|
common.Logf("dtmsvr listen at: %d", dtmsvrPort)
|
||||||
go app.Run(fmt.Sprintf(":%d", dtmsvrPort))
|
go app.Run(fmt.Sprintf(":%d", dtmsvrPort))
|
||||||
time.Sleep(100 * time.Millisecond)
|
time.Sleep(100 * time.Millisecond)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,7 +5,6 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
"github.com/yedf/dtm/common"
|
"github.com/yedf/dtm/common"
|
||||||
"github.com/yedf/dtm/dtmcli"
|
"github.com/yedf/dtm/dtmcli"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
@ -131,12 +130,12 @@ func (t *TransGlobal) processInner(db *common.DB) (rerr error) {
|
|||||||
defer handlePanic(&rerr)
|
defer handlePanic(&rerr)
|
||||||
defer func() {
|
defer func() {
|
||||||
if TransProcessedTestChan != nil {
|
if TransProcessedTestChan != nil {
|
||||||
logrus.Printf("processed: %s", t.Gid)
|
common.Logf("processed: %s", t.Gid)
|
||||||
TransProcessedTestChan <- t.Gid
|
TransProcessedTestChan <- t.Gid
|
||||||
logrus.Printf("notified: %s", t.Gid)
|
common.Logf("notified: %s", t.Gid)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
logrus.Printf("processing: %s status: %s", t.Gid, t.Status)
|
common.Logf("processing: %s status: %s", t.Gid, t.Status)
|
||||||
if t.Status == "prepared" && t.TransType != "msg" {
|
if t.Status == "prepared" && t.TransType != "msg" {
|
||||||
t.changeStatus(db, "aborting")
|
t.changeStatus(db, "aborting")
|
||||||
}
|
}
|
||||||
@ -195,7 +194,7 @@ func TransFromContext(c *gin.Context) *TransGlobal {
|
|||||||
b, err := c.GetRawData()
|
b, err := c.GetRawData()
|
||||||
e2p(err)
|
e2p(err)
|
||||||
common.MustUnmarshal(b, &data)
|
common.MustUnmarshal(b, &data)
|
||||||
logrus.Printf("creating trans in prepare")
|
common.Logf("creating trans in prepare")
|
||||||
if data["steps"] != nil {
|
if data["steps"] != nil {
|
||||||
data["data"] = common.MustMarshalString(data["steps"])
|
data["data"] = common.MustMarshalString(data["steps"])
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,8 +3,8 @@ package dtmsvr
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/yedf/dtm/common"
|
||||||
"github.com/yedf/dtm/dtmcli"
|
"github.com/yedf/dtm/dtmcli"
|
||||||
"github.com/yedf/dtm/examples"
|
"github.com/yedf/dtm/examples"
|
||||||
)
|
)
|
||||||
@ -20,7 +20,7 @@ func sagaBarrierNormal(t *testing.T) {
|
|||||||
saga := dtmcli.NewSaga(DtmServer, "sagaBarrierNormal").
|
saga := dtmcli.NewSaga(DtmServer, "sagaBarrierNormal").
|
||||||
Add(Busi+"/SagaBTransOut", Busi+"/SagaBTransOutCompensate", req).
|
Add(Busi+"/SagaBTransOut", Busi+"/SagaBTransOutCompensate", req).
|
||||||
Add(Busi+"/SagaBTransIn", Busi+"/SagaBTransInCompensate", req)
|
Add(Busi+"/SagaBTransIn", Busi+"/SagaBTransInCompensate", req)
|
||||||
logrus.Printf("busi trans submit")
|
common.Logf("busi trans submit")
|
||||||
err := saga.Submit()
|
err := saga.Submit()
|
||||||
e2p(err)
|
e2p(err)
|
||||||
WaitTransProcessed(saga.Gid)
|
WaitTransProcessed(saga.Gid)
|
||||||
@ -31,7 +31,7 @@ func sagaBarrierRollback(t *testing.T) {
|
|||||||
saga := dtmcli.NewSaga(DtmServer, "sagaBarrierRollback").
|
saga := dtmcli.NewSaga(DtmServer, "sagaBarrierRollback").
|
||||||
Add(Busi+"/SagaBTransOut", Busi+"/SagaBTransOutCompensate", &examples.TransReq{Amount: 30}).
|
Add(Busi+"/SagaBTransOut", Busi+"/SagaBTransOutCompensate", &examples.TransReq{Amount: 30}).
|
||||||
Add(Busi+"/SagaBTransIn", Busi+"/SagaBTransInCompensate", &examples.TransReq{Amount: 30, TransInResult: "FAILURE"})
|
Add(Busi+"/SagaBTransIn", Busi+"/SagaBTransInCompensate", &examples.TransReq{Amount: 30, TransInResult: "FAILURE"})
|
||||||
logrus.Printf("busi trans submit")
|
common.Logf("busi trans submit")
|
||||||
err := saga.Submit()
|
err := saga.Submit()
|
||||||
e2p(err)
|
e2p(err)
|
||||||
WaitTransProcessed(saga.Gid)
|
WaitTransProcessed(saga.Gid)
|
||||||
|
|||||||
@ -8,7 +8,6 @@ import (
|
|||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/go-resty/resty/v2"
|
"github.com/go-resty/resty/v2"
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/yedf/dtm/common"
|
"github.com/yedf/dtm/common"
|
||||||
"github.com/yedf/dtm/dtmcli"
|
"github.com/yedf/dtm/dtmcli"
|
||||||
@ -62,7 +61,7 @@ func tccBarrierDisorder(t *testing.T) {
|
|||||||
res, err := examples.TccBarrierTransOutCancel(c)
|
res, err := examples.TccBarrierTransOutCancel(c)
|
||||||
if !sleeped {
|
if !sleeped {
|
||||||
sleeped = true
|
sleeped = true
|
||||||
logrus.Printf("sleep before cancel return")
|
common.Logf("sleep before cancel return")
|
||||||
<-timeoutChan
|
<-timeoutChan
|
||||||
finishedChan <- "1"
|
finishedChan <- "1"
|
||||||
}
|
}
|
||||||
@ -81,7 +80,7 @@ func tccBarrierDisorder(t *testing.T) {
|
|||||||
}, "registerTccBranch")
|
}, "registerTccBranch")
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
go func() {
|
go func() {
|
||||||
logrus.Printf("sleeping to wait for tcc try timeout")
|
common.Logf("sleeping to wait for tcc try timeout")
|
||||||
<-timeoutChan
|
<-timeoutChan
|
||||||
r, _ := common.RestyClient.R().
|
r, _ := common.RestyClient.R().
|
||||||
SetBody(body).
|
SetBody(body).
|
||||||
@ -96,10 +95,10 @@ func tccBarrierDisorder(t *testing.T) {
|
|||||||
assert.True(t, strings.Contains(r.String(), "FAILURE"))
|
assert.True(t, strings.Contains(r.String(), "FAILURE"))
|
||||||
finishedChan <- "1"
|
finishedChan <- "1"
|
||||||
}()
|
}()
|
||||||
logrus.Printf("cron to timeout and then call cancel")
|
common.Logf("cron to timeout and then call cancel")
|
||||||
go CronTransOnce(60 * time.Second)
|
go CronTransOnce(60 * time.Second)
|
||||||
time.Sleep(100 * time.Millisecond)
|
time.Sleep(100 * time.Millisecond)
|
||||||
logrus.Printf("cron to timeout and then call cancelled twice")
|
common.Logf("cron to timeout and then call cancelled twice")
|
||||||
CronTransOnce(60 * time.Second)
|
CronTransOnce(60 * time.Second)
|
||||||
timeoutChan <- "wake"
|
timeoutChan <- "wake"
|
||||||
timeoutChan <- "wake"
|
timeoutChan <- "wake"
|
||||||
|
|||||||
@ -38,13 +38,13 @@ var TransProcessedTestChan chan string = nil
|
|||||||
|
|
||||||
// WaitTransProcessed only for test usage. wait for transaction processed once
|
// WaitTransProcessed only for test usage. wait for transaction processed once
|
||||||
func WaitTransProcessed(gid string) {
|
func WaitTransProcessed(gid string) {
|
||||||
logrus.Printf("waiting for gid %s", gid)
|
common.Logf("waiting for gid %s", gid)
|
||||||
id := <-TransProcessedTestChan
|
id := <-TransProcessedTestChan
|
||||||
for id != gid {
|
for id != gid {
|
||||||
logrus.Errorf("-------id %s not match gid %s", id, gid)
|
logrus.Errorf("-------id %s not match gid %s", id, gid)
|
||||||
id = <-TransProcessedTestChan
|
id = <-TransProcessedTestChan
|
||||||
}
|
}
|
||||||
logrus.Printf("finish for gid %s", gid)
|
common.Logf("finish for gid %s", gid)
|
||||||
}
|
}
|
||||||
|
|
||||||
var gNode *snowflake.Node = nil
|
var gNode *snowflake.Node = nil
|
||||||
|
|||||||
@ -5,7 +5,6 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
"github.com/yedf/dtm/common"
|
"github.com/yedf/dtm/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -21,10 +20,10 @@ var Busi string = fmt.Sprintf("http://localhost:%d%s", BusiPort, BusiAPI)
|
|||||||
|
|
||||||
// BaseAppStartup base app startup
|
// BaseAppStartup base app startup
|
||||||
func BaseAppStartup() *gin.Engine {
|
func BaseAppStartup() *gin.Engine {
|
||||||
logrus.Printf("examples starting")
|
common.Logf("examples starting")
|
||||||
app := common.GetGinApp()
|
app := common.GetGinApp()
|
||||||
BaseAddRoute(app)
|
BaseAddRoute(app)
|
||||||
logrus.Printf("Starting busi at: %d", BusiPort)
|
common.Logf("Starting busi at: %d", BusiPort)
|
||||||
go app.Run(fmt.Sprintf(":%d", BusiPort))
|
go app.Run(fmt.Sprintf(":%d", BusiPort))
|
||||||
time.Sleep(100 * time.Millisecond)
|
time.Sleep(100 * time.Millisecond)
|
||||||
return app
|
return app
|
||||||
@ -63,7 +62,7 @@ var MainSwitch mainSwitchType
|
|||||||
func handleGeneralBusiness(c *gin.Context, result1 string, result2 string, busi string) (interface{}, error) {
|
func handleGeneralBusiness(c *gin.Context, result1 string, result2 string, busi string) (interface{}, error) {
|
||||||
info := infoFromContext(c)
|
info := infoFromContext(c)
|
||||||
res := common.OrString(result1, result2, "SUCCESS")
|
res := common.OrString(result1, result2, "SUCCESS")
|
||||||
logrus.Printf("%s %s result: %s", busi, info.String(), res)
|
common.Logf("%s %s result: %s", busi, info.String(), res)
|
||||||
return M{"dtm_result": res}, nil
|
return M{"dtm_result": res}, nil
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -89,7 +88,7 @@ func BaseAddRoute(app *gin.Engine) {
|
|||||||
return handleGeneralBusiness(c, MainSwitch.TransOutRevertResult.Fetch(), "", "TransOutRevert")
|
return handleGeneralBusiness(c, MainSwitch.TransOutRevertResult.Fetch(), "", "TransOutRevert")
|
||||||
}))
|
}))
|
||||||
app.GET(BusiAPI+"/CanSubmit", common.WrapHandler(func(c *gin.Context) (interface{}, error) {
|
app.GET(BusiAPI+"/CanSubmit", common.WrapHandler(func(c *gin.Context) (interface{}, error) {
|
||||||
logrus.Printf("%s CanSubmit", c.Query("gid"))
|
common.Logf("%s CanSubmit", c.Query("gid"))
|
||||||
return common.OrString(MainSwitch.CanSubmitResult.Fetch(), "SUCCESS"), nil
|
return common.OrString(MainSwitch.CanSubmitResult.Fetch(), "SUCCESS"), nil
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,7 +2,7 @@ package examples
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/yedf/dtm/common"
|
||||||
"github.com/yedf/dtm/dtmcli"
|
"github.com/yedf/dtm/dtmcli"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -12,14 +12,14 @@ func MsgSetup(app *gin.Engine) {
|
|||||||
|
|
||||||
// MsgFireRequest 1
|
// MsgFireRequest 1
|
||||||
func MsgFireRequest() string {
|
func MsgFireRequest() string {
|
||||||
logrus.Printf("a busi transaction begin")
|
common.Logf("a busi transaction begin")
|
||||||
req := &TransReq{Amount: 30}
|
req := &TransReq{Amount: 30}
|
||||||
msg := dtmcli.NewMsg(DtmServer, dtmcli.MustGenGid(DtmServer)).
|
msg := dtmcli.NewMsg(DtmServer, dtmcli.MustGenGid(DtmServer)).
|
||||||
Add(Busi+"/TransOut", req).
|
Add(Busi+"/TransOut", req).
|
||||||
Add(Busi+"/TransIn", req)
|
Add(Busi+"/TransIn", req)
|
||||||
err := msg.Prepare(Busi + "/TransQuery")
|
err := msg.Prepare(Busi + "/TransQuery")
|
||||||
e2p(err)
|
e2p(err)
|
||||||
logrus.Printf("busi trans submit")
|
common.Logf("busi trans submit")
|
||||||
err = msg.Submit()
|
err = msg.Submit()
|
||||||
e2p(err)
|
e2p(err)
|
||||||
return msg.Gid
|
return msg.Gid
|
||||||
|
|||||||
@ -2,7 +2,7 @@ package examples
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/yedf/dtm/common"
|
||||||
"github.com/yedf/dtm/dtmcli"
|
"github.com/yedf/dtm/dtmcli"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -12,7 +12,7 @@ func SagaSetup(app *gin.Engine) {
|
|||||||
|
|
||||||
// SagaFireRequest 1
|
// SagaFireRequest 1
|
||||||
func SagaFireRequest() string {
|
func SagaFireRequest() string {
|
||||||
logrus.Printf("a saga busi transaction begin")
|
common.Logf("a saga busi transaction begin")
|
||||||
req := &TransReq{
|
req := &TransReq{
|
||||||
Amount: 30,
|
Amount: 30,
|
||||||
TransInResult: "SUCCESS",
|
TransInResult: "SUCCESS",
|
||||||
@ -21,9 +21,9 @@ func SagaFireRequest() string {
|
|||||||
saga := dtmcli.NewSaga(DtmServer, dtmcli.MustGenGid(DtmServer)).
|
saga := dtmcli.NewSaga(DtmServer, dtmcli.MustGenGid(DtmServer)).
|
||||||
Add(Busi+"/TransOut", Busi+"/TransOutRevert", req).
|
Add(Busi+"/TransOut", Busi+"/TransOutRevert", req).
|
||||||
Add(Busi+"/TransIn", Busi+"/TransInRevert", req)
|
Add(Busi+"/TransIn", Busi+"/TransInRevert", req)
|
||||||
logrus.Printf("saga busi trans submit")
|
common.Logf("saga busi trans submit")
|
||||||
err := saga.Submit()
|
err := saga.Submit()
|
||||||
logrus.Printf("result gid is: %s", saga.Gid)
|
common.Logf("result gid is: %s", saga.Gid)
|
||||||
e2p(err)
|
e2p(err)
|
||||||
return saga.Gid
|
return saga.Gid
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,19 +4,18 @@ import (
|
|||||||
"database/sql"
|
"database/sql"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
"github.com/yedf/dtm/common"
|
"github.com/yedf/dtm/common"
|
||||||
"github.com/yedf/dtm/dtmcli"
|
"github.com/yedf/dtm/dtmcli"
|
||||||
)
|
)
|
||||||
|
|
||||||
// SagaBarrierFireRequest 1
|
// SagaBarrierFireRequest 1
|
||||||
func SagaBarrierFireRequest() string {
|
func SagaBarrierFireRequest() string {
|
||||||
logrus.Printf("a busi transaction begin")
|
common.Logf("a busi transaction begin")
|
||||||
req := &TransReq{Amount: 30}
|
req := &TransReq{Amount: 30}
|
||||||
saga := dtmcli.NewSaga(DtmServer, dtmcli.MustGenGid(DtmServer)).
|
saga := dtmcli.NewSaga(DtmServer, dtmcli.MustGenGid(DtmServer)).
|
||||||
Add(Busi+"/SagaBTransOut", Busi+"/SagaBTransOutCompensate", req).
|
Add(Busi+"/SagaBTransOut", Busi+"/SagaBTransOutCompensate", req).
|
||||||
Add(Busi+"/SagaBTransIn", Busi+"/SagaBTransInCompensate", req)
|
Add(Busi+"/SagaBTransIn", Busi+"/SagaBTransInCompensate", req)
|
||||||
logrus.Printf("busi trans submit")
|
common.Logf("busi trans submit")
|
||||||
err := saga.Submit()
|
err := saga.Submit()
|
||||||
e2p(err)
|
e2p(err)
|
||||||
return saga.Gid
|
return saga.Gid
|
||||||
@ -28,7 +27,7 @@ func SagaBarrierAddRoute(app *gin.Engine) {
|
|||||||
app.POST(BusiAPI+"/SagaBTransInCompensate", common.WrapHandler(sagaBarrierTransInCompensate))
|
app.POST(BusiAPI+"/SagaBTransInCompensate", common.WrapHandler(sagaBarrierTransInCompensate))
|
||||||
app.POST(BusiAPI+"/SagaBTransOut", common.WrapHandler(sagaBarrierTransOut))
|
app.POST(BusiAPI+"/SagaBTransOut", common.WrapHandler(sagaBarrierTransOut))
|
||||||
app.POST(BusiAPI+"/SagaBTransOutCompensate", common.WrapHandler(sagaBarrierTransOutCompensate))
|
app.POST(BusiAPI+"/SagaBTransOutCompensate", common.WrapHandler(sagaBarrierTransOutCompensate))
|
||||||
logrus.Printf("examples listening at %d", BusiPort)
|
common.Logf("examples listening at %d", BusiPort)
|
||||||
}
|
}
|
||||||
|
|
||||||
func sagaBarrierAdjustBalance(sdb *sql.Tx, uid int, amount int) (interface{}, error) {
|
func sagaBarrierAdjustBalance(sdb *sql.Tx, uid int, amount int) (interface{}, error) {
|
||||||
|
|||||||
@ -3,7 +3,6 @@ package examples
|
|||||||
import (
|
import (
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/go-resty/resty/v2"
|
"github.com/go-resty/resty/v2"
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
"github.com/yedf/dtm/common"
|
"github.com/yedf/dtm/common"
|
||||||
"github.com/yedf/dtm/dtmcli"
|
"github.com/yedf/dtm/dtmcli"
|
||||||
)
|
)
|
||||||
@ -13,7 +12,7 @@ func TccSetup(app *gin.Engine) {
|
|||||||
app.POST(BusiAPI+"/TransInTccParent", common.WrapHandler(func(c *gin.Context) (interface{}, error) {
|
app.POST(BusiAPI+"/TransInTccParent", common.WrapHandler(func(c *gin.Context) (interface{}, error) {
|
||||||
tcc, err := dtmcli.TccFromReq(c)
|
tcc, err := dtmcli.TccFromReq(c)
|
||||||
e2p(err)
|
e2p(err)
|
||||||
logrus.Printf("TransInTccParent ")
|
common.Logf("TransInTccParent ")
|
||||||
return tcc.CallBranch(&TransReq{Amount: reqFrom(c).Amount}, Busi+"/TransIn", Busi+"/TransInConfirm", Busi+"/TransInRevert")
|
return tcc.CallBranch(&TransReq{Amount: reqFrom(c).Amount}, Busi+"/TransIn", Busi+"/TransInConfirm", Busi+"/TransInRevert")
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
@ -34,7 +33,7 @@ func TccFireRequestNested() string {
|
|||||||
|
|
||||||
// TccFireRequest 1
|
// TccFireRequest 1
|
||||||
func TccFireRequest() string {
|
func TccFireRequest() string {
|
||||||
logrus.Printf("tcc simple transaction begin")
|
common.Logf("tcc simple transaction begin")
|
||||||
gid := dtmcli.MustGenGid(DtmServer)
|
gid := dtmcli.MustGenGid(DtmServer)
|
||||||
err := dtmcli.TccGlobalTransaction(DtmServer, gid, func(tcc *dtmcli.Tcc) (*resty.Response, error) {
|
err := dtmcli.TccGlobalTransaction(DtmServer, gid, func(tcc *dtmcli.Tcc) (*resty.Response, error) {
|
||||||
resp, err := tcc.CallBranch(&TransReq{Amount: 30}, Busi+"/TransOut", Busi+"/TransOutConfirm", Busi+"/TransOutRevert")
|
resp, err := tcc.CallBranch(&TransReq{Amount: 30}, Busi+"/TransOut", Busi+"/TransOutConfirm", Busi+"/TransOutRevert")
|
||||||
|
|||||||
@ -6,14 +6,13 @@ import (
|
|||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/go-resty/resty/v2"
|
"github.com/go-resty/resty/v2"
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
"github.com/yedf/dtm/common"
|
"github.com/yedf/dtm/common"
|
||||||
"github.com/yedf/dtm/dtmcli"
|
"github.com/yedf/dtm/dtmcli"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TccBarrierFireRequest 1
|
// TccBarrierFireRequest 1
|
||||||
func TccBarrierFireRequest() string {
|
func TccBarrierFireRequest() string {
|
||||||
logrus.Printf("tcc transaction begin")
|
common.Logf("tcc transaction begin")
|
||||||
gid := dtmcli.MustGenGid(DtmServer)
|
gid := dtmcli.MustGenGid(DtmServer)
|
||||||
err := dtmcli.TccGlobalTransaction(DtmServer, gid, func(tcc *dtmcli.Tcc) (*resty.Response, error) {
|
err := dtmcli.TccGlobalTransaction(DtmServer, gid, func(tcc *dtmcli.Tcc) (*resty.Response, error) {
|
||||||
resp, err := tcc.CallBranch(&TransReq{Amount: 30}, Busi+"/TccBTransOutTry", Busi+"/TccBTransOutConfirm", Busi+"/TccBTransOutCancel")
|
resp, err := tcc.CallBranch(&TransReq{Amount: 30}, Busi+"/TccBTransOutTry", Busi+"/TccBTransOutConfirm", Busi+"/TccBTransOutCancel")
|
||||||
@ -34,7 +33,7 @@ func TccBarrierAddRoute(app *gin.Engine) {
|
|||||||
app.POST(BusiAPI+"/TccBTransOutTry", common.WrapHandler(tccBarrierTransOutTry))
|
app.POST(BusiAPI+"/TccBTransOutTry", common.WrapHandler(tccBarrierTransOutTry))
|
||||||
app.POST(BusiAPI+"/TccBTransOutConfirm", common.WrapHandler(tccBarrierTransOutConfirm))
|
app.POST(BusiAPI+"/TccBTransOutConfirm", common.WrapHandler(tccBarrierTransOutConfirm))
|
||||||
app.POST(BusiAPI+"/TccBTransOutCancel", common.WrapHandler(TccBarrierTransOutCancel))
|
app.POST(BusiAPI+"/TccBTransOutCancel", common.WrapHandler(TccBarrierTransOutCancel))
|
||||||
logrus.Printf("examples listening at %d", BusiPort)
|
common.Logf("examples listening at %d", BusiPort)
|
||||||
}
|
}
|
||||||
|
|
||||||
const transInUID = 1
|
const transInUID = 1
|
||||||
|
|||||||
@ -5,7 +5,6 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
"github.com/yedf/dtm/common"
|
"github.com/yedf/dtm/common"
|
||||||
"github.com/yedf/dtm/dtmcli"
|
"github.com/yedf/dtm/dtmcli"
|
||||||
)
|
)
|
||||||
@ -22,7 +21,7 @@ var qsBusi = fmt.Sprintf("http://localhost:%d%s", qsBusiPort, qsBusiAPI)
|
|||||||
func QsStartSvr() {
|
func QsStartSvr() {
|
||||||
app := common.GetGinApp()
|
app := common.GetGinApp()
|
||||||
qsAddRoute(app)
|
qsAddRoute(app)
|
||||||
logrus.Printf("quick qs examples listening at %d", qsBusiPort)
|
common.Logf("quick qs examples listening at %d", qsBusiPort)
|
||||||
go app.Run(fmt.Sprintf(":%d", qsBusiPort))
|
go app.Run(fmt.Sprintf(":%d", qsBusiPort))
|
||||||
time.Sleep(100 * time.Millisecond)
|
time.Sleep(100 * time.Millisecond)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user