Skip to content

Commit

Permalink
update from seatago (apache#3)
Browse files Browse the repository at this point in the history
Signed-off-by: charlie <[email protected]>
  • Loading branch information
Charlie17Li authored Feb 4, 2023
1 parent 772b2d2 commit ad428fc
Show file tree
Hide file tree
Showing 26 changed files with 415 additions and 39 deletions.
45 changes: 34 additions & 11 deletions at/basic/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,48 @@ import (
"github.com/seata/seata-go/pkg/tm"
)

type OrderTbl struct {
id int
userID string
commodityCode string
count int64
money int64
descs string
}

func main() {
client.Init()
client.InitPath("./sample/conf/seatago.yml")
initService()
tm.WithGlobalTx(context.Background(), &tm.GtxConfig{
Name: "ATSampleLocalGlobalTx",
Timeout: time.Second * 30,
}, updateData)
}, insertData)
<-make(chan struct{})
}

func insertData(ctx context.Context) error {
sql := "INSERT INTO `order_tbl` (`id`, `user_id`, `commodity_code`, `count`, `money`, `descs`) VALUES (?, ?, ?, ?, ?, ?);"
ret, err := db.ExecContext(ctx, sql, 333, "NO-100001", "C100000", 100, nil, "init desc")
if err != nil {
fmt.Printf("insert failed, err:%v\n", err)
return err
}
rows, err := ret.RowsAffected()
if err != nil {
fmt.Printf("insert failed, err:%v\n", err)
return err
}
fmt.Printf("insert success: %d.\n", rows)
return nil
}

func deleteData(ctx context.Context) error {
sql := "delete from order_tbl where id=?"
ret, err := db.ExecContext(ctx, sql, 2)
if err != nil {
fmt.Printf("delete failed, err:%v\n", err)
return err
}
rows, err := ret.RowsAffected()
if err != nil {
fmt.Printf("delete failed, err:%v\n", err)
return err
}
fmt.Printf("delete success: %d.\n", rows)
return nil
}

func updateData(ctx context.Context) error {
sql := "update order_tbl set descs=? where id=?"
ret, err := db.ExecContext(ctx, sql, fmt.Sprintf("NewDescs-%d", time.Now().UnixMilli()), 1)
Expand Down
5 changes: 2 additions & 3 deletions at/gin/client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package main

import (
"context"
"errors"
"flag"
"fmt"
"net/http"
Expand All @@ -37,7 +36,7 @@ var serverIpPort = "http://127.0.0.1:8080"

func main() {
flag.Parse()
client.Init()
client.InitPath("./sample/conf/seatago.yml")

bgCtx, cancel := context.WithTimeout(context.Background(), time.Minute*10)
defer cancel()
Expand All @@ -60,7 +59,7 @@ func updateData(ctx context.Context) (re error) {
Set(constant.XidKey, tm.GetXID(ctx)).
End(func(response gorequest.Response, body string, errs []error) {
if response.StatusCode != http.StatusOK {
re = errors.New("update data fail")
re = fmt.Errorf("update data fail")
}
})
return
Expand Down
2 changes: 1 addition & 1 deletion at/gin/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
)

func main() {
client.Init()
client.InitPath("./sample/conf/seatago.yml")
initService()

r := gin.Default()
Expand Down
2 changes: 1 addition & 1 deletion at/gin/server/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ var (

func initService() {
var err error
db, err = sql.Open(sql2.SeataATMySQLDriver, "root:123456@tcp(127.0.0.1:3306)/seata_client?multiStatements=true&interpolateParams=true")
db, err = sql.Open(sql2.SeataATMySQLDriver, "root:12345678@tcp(127.0.0.1:3306)/seata_client?multiStatements=true&interpolateParams=true")
if err != nil {
panic("init service error")
}
Expand Down
2 changes: 1 addition & 1 deletion at/non_transaction/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ var (
)

func main() {
client.Init()
client.InitPath("./sample/conf/seatago.yml")
initService()

insertId := insertData()
Expand Down
2 changes: 1 addition & 1 deletion at/non_transaction/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var (

func initService() {
var err error
db, err = sql.Open(sql2.SeataATMySQLDriver, "root:123456@tcp(127.0.0.1:3306)/seata_client?multiStatements=true&interpolateParams=true")
db, err = sql.Open(sql2.SeataATMySQLDriver, "root:12345678@tcp(127.0.0.1:3306)/seata_client?multiStatements=true&interpolateParams=true")
if err != nil {
panic("init service error")
}
Expand Down
13 changes: 7 additions & 6 deletions at/rollback/client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package main

import (
"context"
"errors"
"flag"
"fmt"
"net/http"
Expand All @@ -33,12 +32,14 @@ import (
"github.com/seata/seata-go/pkg/util/log"
)

var serverIpPort = "http://127.0.0.1:8080"
var serverIpPort2 = "http://127.0.0.1:8081"
var (
serverIpPort = "http://127.0.0.1:8080"
serverIpPort2 = "http://127.0.0.1:8081"
)

func main() {
flag.Parse()
client.Init()
client.InitPath("./sample/conf/seatago.yml")

bgCtx, cancel := context.WithTimeout(context.Background(), time.Minute*10)
defer cancel()
Expand All @@ -61,15 +62,15 @@ func updateData(ctx context.Context) (re error) {
Set(constant.XidKey, tm.GetXID(ctx)).
End(func(response gorequest.Response, body string, errs []error) {
if response.StatusCode != http.StatusOK {
re = errors.New("update data fail")
re = fmt.Errorf("update data fail")
}
})

request.Post(serverIpPort2+"/updateDataFail").
Set(constant.XidKey, tm.GetXID(ctx)).
End(func(response gorequest.Response, body string, errs1 []error) {
if response.StatusCode != http.StatusOK {
re = errors.New("update data fail")
re = fmt.Errorf("update data fail")
}
})
return
Expand Down
2 changes: 1 addition & 1 deletion at/rollback/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
)

func main() {
client.Init()
client.InitPath("./sample/conf/seatago.yml")
initService()

r := gin.Default()
Expand Down
2 changes: 1 addition & 1 deletion at/rollback/server2/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
)

func main() {
client.Init()
client.InitPath("./sample/conf/seatago.yml")
initService()

r := gin.Default()
Expand Down
4 changes: 1 addition & 3 deletions at/rollback/server2/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ import (
"fmt"
"time"

"github.com/pkg/errors"

sql2 "github.com/seata/seata-go/pkg/datasource/sql"
)

Expand Down Expand Up @@ -55,7 +53,7 @@ func updateDataFail(ctx context.Context) error {
}
fmt.Printf("update success: %d.\n", rows)
if rows == 0 {
return errors.New("rows affected 0")
return fmt.Errorf("rows affected 0")
}
return nil
}
160 changes: 160 additions & 0 deletions conf/seatago.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# time 时间单位对应的是 time.Duration(1)
seata:
enabled: true
# application id
application-id: applicationName
# service group
tx-service-group: default_tx_group
access-key: aliyunAccessKey
secret-key: aliyunSecretKey
enable-auto-data-source-proxy: true
data-source-proxy-mode: AT
client:
rm:
# Maximum cache length of asynchronous queue
async-commit-buffer-limit: 10000
# The maximum number of retries when report reports the status
report-retry-count: 5
# The interval for regularly checking the metadata of the db(AT)
table-meta-check-enable: false
# Whether to report the status if the transaction is successfully executed(AT)
report-success-enable: false
# Whether to allow regular check of db metadata(AT)
saga-branch-register-enable: false
saga-json-parser: fastjson
saga-retry-persist-mode-update: false
saga-compensate-persist-mode-update: false
#Ordered.HIGHEST_PRECEDENCE + 1000 #
tcc-action-interceptor-order: -2147482648
# Parse SQL parser selection
sql-parser-type: druid
lock:
retry-interval: 10
retry-times: 30s
retry-policy-branch-rollback-on-conflict: true
tm:
commit-retry-count: 5
rollback-retry-count: 5
default-global-transaction-timeout: 60s
degrade-check: false
degrade-check-period: 2000
degrade-check-allow-times: 10s
interceptor-order: -2147482648
undo:
# Judge whether the before image and after image are the same,If it is the same, undo will not be recorded
data-validation: true
# Serialization method
log-serialization: jackson
# undo log table name
log-table: undo_log
# Only store modified fields
only-care-update-columns: true
compress:
# Whether compression is required
enable: true
# Compression type
type: zip
# Compression threshold Unit: k
threshold: 64k
load-balance:
type: RandomLoadBalance
virtual-nodes: 10
service:
vgroup-mapping:
# Prefix for Print Log
default_tx_group: default
grouplist:
default: 127.0.0.1:8091
enable-degrade: false
# close the transaction
disable-global-transaction: false
transport:
shutdown:
wait: 3s
# Netty related configurations
# type
type: TCP
server: NIO
heartbeat: true
# Encoding and decoding mode
serialization: seata
# Message compression mode
compressor: none
# Allow batch sending of requests (TM)
enable-tm-client-batch-send-request: false
# Allow batch sending of requests (RM)
enable-rm-client-batch-send-request: true
# RM send request timeout
rpc-rm-request-timeout: 30s
# TM send request timeout
rpc-tm-request-timeout: 30s
# Configuration Center
config:
type: file
file:
name: config.conf
nacos:
namespace: ""
server-addr: 127.0.0.1:8848
group: SEATA_GROUP
username: ""
password: ""
##if use MSE Nacos with auth, mutex with username/password attribute
#access-key: ""
#secret-key: ""
data-id: seata.properties
# Registration Center
registry:
type: file
file:
name: registry.conf
nacos:
application: seata-server
server-addr: 127.0.0.1:8848
group: "SEATA_GROUP"
namespace: ""
username: ""
password: ""
##if use MSE Nacos with auth, mutex with username/password attribute #
#access-key: "" #
#secret-key: "" #
log:
exception-rate: 100
tcc:
fence:
# Anti suspension table name
log-table-name: tcc_fence_log_test
clean-period: 60s
# getty configuration
getty:
reconnect-interval: 0
# temporary not supported connection-num
connection-num: 1
session:
compress-encoding: false
tcp-no-delay: true
tcp-keep-alive: true
keep-alive-period: 120s
tcp-r-buf-size: 262144
tcp-w-buf-size: 65536
tcp-read-timeout: 5s
tcp-write-timeout: 5s
wait-timeout: 1s
max-msg-len: 16498688
session-name: client_test
cron-period: 1s
Loading

0 comments on commit ad428fc

Please sign in to comment.