@@ -1,38 +1 @@ | |||
package runtime | |||
import ( | |||
"fmt" | |||
"os" | |||
"runtime/debug" | |||
"time" | |||
) | |||
var debugIgnoreStdout = false | |||
// GoWithRecover wraps a `go func()` with recover() | |||
func GoWithRecover(handler func(), recoverHandler func(r interface{})) { | |||
go func() { | |||
defer func() { | |||
if r := recover(); r != nil { | |||
// TODO: log | |||
if !debugIgnoreStdout { | |||
fmt.Fprintf(os.Stderr, "%s goroutine panic: %v\n%s\n", | |||
time.Now(), r, string(debug.Stack())) | |||
} | |||
if recoverHandler != nil { | |||
go func() { | |||
defer func() { | |||
if p := recover(); p != nil { | |||
if !debugIgnoreStdout { | |||
fmt.Fprintf(os.Stderr, "recover goroutine panic:%v\n%s\n", p, string(debug.Stack())) | |||
} | |||
} | |||
}() | |||
recoverHandler(r) | |||
}() | |||
} | |||
} | |||
}() | |||
handler() | |||
}() | |||
} |
@@ -1,22 +0,0 @@ | |||
package xid_utils | |||
import ( | |||
"context" | |||
"github.com/seata/seata-go/pkg/common/model" | |||
) | |||
func GetXID(ctx context.Context) string { | |||
xid := ctx.Value(model.XID) | |||
if xid == nil { | |||
return "" | |||
} | |||
return xid.(string) | |||
} | |||
func HasXID(ctx context.Context) bool { | |||
return GetXID(ctx) != "" | |||
} | |||
func SetXID(ctx context.Context, xid string) context.Context { | |||
return context.WithValue(ctx, model.XID, xid) | |||
} |
@@ -13,8 +13,6 @@ type ClientConfig struct { | |||
SeataVersion string `yaml:"seata_version" json:"seata_version,omitempty"` | |||
GettyConfig GettyConfig `yaml:"getty" json:"getty,omitempty"` | |||
TMConfig TMConfig `yaml:"tm" json:"tm,omitempty"` | |||
ATConfig struct { | |||
DSN string `yaml:"dsn" json:"dsn,omitempty"` | |||
ReportRetryCount int `default:"5" yaml:"report_retry_count" json:"report_retry_count,omitempty"` | |||
@@ -22,23 +20,14 @@ type ClientConfig struct { | |||
LockRetryInterval time.Duration `default:"10ms" yaml:"lock_retry_interval" json:"lock_retry_interval,omitempty"` | |||
LockRetryTimes int `default:"30" yaml:"lock_retry_times" json:"lock_retry_times,omitempty"` | |||
} `yaml:"at" json:"at,omitempty"` | |||
RegistryConfig RegistryConfig `yaml:"registry_config" json:"registry_config,omitempty"` //注册中心配置信息 | |||
ConfigCenterConfig ConfigCenterConfig `yaml:"config_center" json:"config_center,omitempty"` //配置中心配置信息 | |||
} | |||
func GetClientConfig() *ClientConfig { | |||
// todo mock data | |||
//return clientConfig | |||
return &ClientConfig{ | |||
GettyConfig: GetDefaultGettyConfig(), | |||
} | |||
} | |||
func GetTMConfig() TMConfig { | |||
return clientConfig.TMConfig | |||
} | |||
func GetDefaultClientConfig(applicationID string) *ClientConfig { | |||
return &ClientConfig{ | |||
ApplicationID: applicationID, | |||
@@ -46,6 +35,5 @@ func GetDefaultClientConfig(applicationID string) *ClientConfig { | |||
EnableClientBatchSendRequest: false, | |||
SeataVersion: "1.1.0", | |||
GettyConfig: GetDefaultGettyConfig(), | |||
TMConfig: GetDefaultTmConfig(), | |||
} | |||
} |
@@ -1,31 +0,0 @@ | |||
package config | |||
import ( | |||
"time" | |||
) | |||
// ConfigCenterConfig config center config | |||
type ConfigCenterConfig struct { | |||
Mode string `yaml:"type" json:"type,omitempty"` //类型 | |||
NacosConfig NacosConfigCenter `yaml:"nacos" json:"nacos,omitempty"` | |||
ETCDConfig EtcdConfigCenter `yaml:"etcdv3" json:"etcdv3,omitempty"` | |||
} | |||
// NacosConfigCenter nacos config center | |||
type NacosConfigCenter struct { | |||
ServerAddr string `yaml:"server_addr" json:"server_addr,omitempty"` | |||
Group string `default:"SEATA_GROUP" yaml:"group" json:"group,omitempty"` | |||
Namespace string `yaml:"namespace" json:"namespace,omitempty"` | |||
Cluster string `yaml:"cluster" json:"cluster,omitempty"` | |||
UserName string `yaml:"username" json:"username,omitempty"` | |||
Password string `yaml:"password" json:"password,omitempty"` | |||
DataID string `default:"seata" yaml:"data_id" json:"data_id,omitempty"` | |||
} | |||
type EtcdConfigCenter struct { | |||
Name string `default:"seata-config-center" yaml:"name" json:"name"` | |||
ConfigKey string `default:"config-seata" yaml:"config_key" json:"config_key,omitempty"` | |||
Endpoints string `yaml:"endpoints" json:"endpoints,omitempty"` | |||
Heartbeats int `yaml:"heartbeats" json:"heartbeats"` | |||
Timeout time.Duration `yaml:"timeout" json:"timeout"` | |||
} |
@@ -29,7 +29,7 @@ func GetDefaultGettyConfig() GettyConfig { | |||
TCPNoDelay: true, | |||
TCPKeepAlive: true, | |||
KeepAlivePeriod: 180 * time.Second, | |||
TCPRBufSize: 262144, | |||
TCPRBufSize: 2144, | |||
TCPWBufSize: 65536, | |||
TCPReadTimeout: time.Second, | |||
TCPWriteTimeout: 5 * time.Second, | |||
@@ -1,42 +0,0 @@ | |||
package config | |||
import ( | |||
"time" | |||
) | |||
var config *RegistryConfig | |||
// RegistryConfig registry config | |||
type RegistryConfig struct { | |||
Mode string `yaml:"type" json:"type,omitempty"` //类型 | |||
NacosConfig NacosConfig `yaml:"nacos" json:"nacos,omitempty"` | |||
EtcdConfig EtcdConfig `yaml:"etcdv3" json:"etcdv3"` | |||
} | |||
// NacosConfig nacos config | |||
type NacosConfig struct { | |||
Application string `yaml:"application" json:"application,omitempty"` | |||
ServerAddr string `yaml:"server_addr" json:"server_addr,omitempty"` | |||
Group string `default:"SEATA_GROUP" yaml:"group" json:"group,omitempty"` | |||
Namespace string `yaml:"namespace" json:"namespace,omitempty"` | |||
Cluster string `yaml:"cluster" json:"cluster,omitempty"` | |||
UserName string `yaml:"username" json:"username,omitempty"` | |||
Password string `yaml:"password" json:"password,omitempty"` | |||
} | |||
// InitRegistryConfig init registry config | |||
func InitRegistryConfig(registryConfig *RegistryConfig) { | |||
config = registryConfig | |||
} | |||
// GetRegistryConfig get registry config | |||
func GetRegistryConfig() *RegistryConfig { | |||
return config | |||
} | |||
type EtcdConfig struct { | |||
ClusterName string `default:"seata-golang-etcdv3" yaml:"cluster_name" json:"cluster_name,omitempty"` | |||
Endpoints string `yaml:"endpoints" json:"endpoints,omitempty"` | |||
Heartbeats int `yaml:"heartbeats" json:"heartbeats"` | |||
Timeout time.Duration `yaml:"timeout" json:"timeout"` | |||
} |
@@ -1,21 +0,0 @@ | |||
package config | |||
type TMConfig struct { | |||
CommitRetryCount uint16 `default:"5" yaml:"commit_retry_count" json:"commit_retry_count,omitempty"` | |||
RollbackRetryCount uint16 `default:"5" yaml:"rollback_retry_count" json:"rollback_retry_count,omitempty"` | |||
DefaultGlobalTransactionTimeout uint16 `default:"60000" yaml:"default_global_transaction_timeout" json:"default_global_transaction_timeout,omitempty"` | |||
DegradeCheck bool `default:"false" yaml:"degrade_check" json:"degrade_check,omitempty"` | |||
DegradeCheckAllowTimes uint16 `default:"10" yaml:"degrade_check_allow_times" json:"degrade_check_allow_times,omitempty"` | |||
DegradeCheckPeriod uint16 `default:"2000" yaml:"degrade_check_period" json:"degrade_check_period,omitempty"` | |||
} | |||
func GetDefaultTmConfig() TMConfig { | |||
return TMConfig{ | |||
CommitRetryCount: 5, | |||
RollbackRetryCount: 5, | |||
DefaultGlobalTransactionTimeout: 60000, | |||
DegradeCheck: false, | |||
DegradeCheckAllowTimes: 10, | |||
DegradeCheckPeriod: 2000, | |||
} | |||
} |
@@ -57,7 +57,6 @@ func (client *GettyRemoting) SendASync(msg message.RpcMessage) error { | |||
return err | |||
} | |||
// TODO 待重构 | |||
func (client *GettyRemoting) sendAsync(session getty.Session, msg message.RpcMessage, timeout time.Duration) (interface{}, error) { | |||
var err error | |||
if session == nil || session.IsClosed() { | |||
@@ -37,7 +37,7 @@ func newRpcClient() *RpcClient { | |||
} | |||
func (c *RpcClient) init() { | |||
addressList := getAvailServerList(c.conf) | |||
addressList := getAvailServerList() | |||
if len(addressList) == 0 { | |||
log.Warn("no have valid seata server list") | |||
} | |||
@@ -54,7 +54,7 @@ func (c *RpcClient) init() { | |||
} | |||
// todo mock | |||
func getAvailServerList(config *config.ClientConfig) []string { | |||
func getAvailServerList() []string { | |||
return []string{"127.0.0.1:8091"} | |||
} | |||
@@ -27,12 +27,6 @@ type TCCResource struct { | |||
ResourceGroupId string `default:"DEFAULT"` | |||
AppName string | |||
ActionName string | |||
//TargetBean interface{} | |||
//PrepareMethod reflect.Method | |||
//CommitMethodName string | |||
//CommitMethod reflect.Method | |||
//RollbackMethodName string | |||
//RollbackMethod reflect.Method | |||
} | |||
func (t *TCCResource) GetResourceGroupId() string { | |||