Browse Source

feat:add yml config (#285)

add yml config
tags/v1.0.2-rc2
zhangym GitHub 2 years ago
parent
commit
52eafdae47
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 726 additions and 12 deletions
  1. +156
    -0
      conf/seata_config.yml
  2. +56
    -0
      pkg/config/client_config.go
  3. +34
    -0
      pkg/config/config_config.go
  4. +23
    -0
      pkg/config/configurator.go
  5. +19
    -0
      pkg/config/doc.go
  6. +28
    -12
      pkg/config/getty_config.go
  7. +22
    -0
      pkg/config/log_config.go
  8. +49
    -0
      pkg/config/parser/configuration_parser.go
  9. +38
    -0
      pkg/config/parser/configuration_parser_test.go
  10. +38
    -0
      pkg/config/registry_config.go
  11. +72
    -0
      pkg/config/seata_config.go
  12. +129
    -0
      pkg/config/seata_config_test.go
  13. +33
    -0
      pkg/config/service_config.go
  14. +29
    -0
      pkg/config/tcc_config.go

+ 156
- 0
conf/seata_config.yml View File

@@ -0,0 +1,156 @@
# 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: 10s
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: 64
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: 3s
# TM send request timeout
rpc-tm-request-timeout: 3s
# 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

clean-period: 60s
# getty configuration
getty-session-param:
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: 1s
tcp-write-timeout: 5s
wait-timeout: 1s
max-msg-len: 16498688
session-name: client

+ 56
- 0
pkg/config/client_config.go View File

@@ -54,3 +54,59 @@ func GetDefaultClientConfig(applicationID string) *ClientConfig {
GettyConfig: GetDefaultGettyConfig(),
}
}

type Compress struct {
Enable bool `yaml:"enable" json:"enable,omitempty" property:"enable"`
Type string `yaml:"type" json:"type,omitempty" property:"type"`
Threshold int `yaml:"threshold" json:"threshold,omitempty" property:"threshold"`
}

type Lock struct {
RetryInterval int `yaml:"retry-interval" json:"retry-interval,omitempty" property:"retry-interval"`
RetryTimes time.Duration `yaml:"retry-times" json:"retry-times,omitempty" property:"retry-times"`
RetryPolicyBranchRollbackOnConflict bool `yaml:"retry-policy-branch-rollback-on-conflict" json:"retry-policy-branch-rollback-on-conflict,omitempty" property:"retry-policy-branch-rollback-on-conflict"`
}

type RmConf struct {
AsyncCommitBufferLimit int `yaml:"async-commit-buffer-limit" json:"async-commit-buffer-limit,omitempty" property:"async-commit-buffer-limit"`
ReportRetryCount int `yaml:"report-retry-count" json:"report-retry-count,omitempty" property:"report-retry-count"`
TableMetaCheckEnable bool `yaml:"table-meta-check-enable" json:"table-meta-check-enable,omitempty" property:"table-meta-check-enable"`
ReportSuccessEnable bool `yaml:"report-success-enable" json:"report-success-enable,omitempty" property:"report-success-enable"`
SagaBranchRegisterEnable bool `yaml:"saga-branch-register-enable" json:"saga-branch-register-enable,omitempty" property:"saga-branch-register-enable"`
SagaJSONParser string `yaml:"saga-json-parser" json:"saga-json-parser,omitempty" property:"saga-json-parser"`
SagaRetryPersistModeUpdate bool `yaml:"saga-retry-persist-mode-update" json:"saga-retry-persist-mode-update,omitempty" property:"saga-retry-persist-mode-update"`
SagaCompensatePersistModeUpdate bool `yaml:"saga-compensate-persist-mode-update" json:"saga-compensate-persist-mode-update,omitempty" property:"saga-compensate-persist-mode-update"`
TccActionInterceptorOrder int `yaml:"tcc-action-interceptor-order" json:"tcc-action-interceptor-order,omitempty" property:"tcc-action-interceptor-order"`
SQLParserType string `yaml:"sql-parser-type" json:"sql-parser-type,omitempty" property:"sql-parser-type"`
Lock Lock `yaml:"lock" json:"lock,omitempty" property:"lock"`
}

type TmConf struct {
CommitRetryCount int `yaml:"commit-retry-count" json:"commit-retry-count,omitempty" property:"commit-retry-count"`
RollbackRetryCount int `yaml:"rollback-retry-count" json:"rollback-retry-count,omitempty" property:"rollback-retry-count"`
DefaultGlobalTransactionTimeout time.Duration `yaml:"default-global-transaction-timeout" json:"default-global-transaction-timeout,omitempty" property:"default-global-transaction-timeout"`
DegradeCheck bool `yaml:"degrade-check" json:"degrade-check,omitempty" property:"degrade-check"`
DegradeCheckPeriod int `yaml:"degrade-check-period" json:"degrade-check-period,omitempty" property:"degrade-check-period"`
DegradeCheckAllowTimes time.Duration `yaml:"degrade-check-allow-times" json:"degrade-check-allow-times,omitempty" property:"degrade-check-allow-times"`
InterceptorOrder int `yaml:"interceptor-order" json:"interceptor-order,omitempty" property:"interceptor-order"`
}

type Undo struct {
DataValidation bool `yaml:"data-validation" json:"data-validation,omitempty" property:"data-validation"`
LogSerialization string `yaml:"log-serialization" json:"log-serialization,omitempty" property:"log-serialization"`
LogTable string `yaml:"log-table" json:"log-table,omitempty" property:"log-table"`
OnlyCareUpdateColumns bool `yaml:"only-care-update-columns" json:"only-care-update-columns,omitempty" property:"only-care-update-columns"`
Compress Compress `yaml:"compress" json:"compress,omitempty" property:"compress"`
}

type LoadBalance struct {
Type string `yaml:"type" json:"type,omitempty" property:"type"`
VirtualNodes int `yaml:"virtual-nodes" json:"virtual-nodes,omitempty" property:"virtual-nodes"`
}

type ClientConf struct {
Rmconf RmConf `yaml:"rm" json:"rm,omitempty" property:"rm"`
Tmconf TmConf `yaml:"tm" json:"tm,omitempty" property:"tm"`
Undo Undo `yaml:"undo" json:"undo,omitempty" property:"undo"`
LoadBalance LoadBalance `yaml:"load-balance" json:"load-balance,omitempty" property:"load-balance"`
}

+ 34
- 0
pkg/config/config_config.go View File

@@ -0,0 +1,34 @@
/*
* 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.
*/

package config

type NacosConfig struct {
Namespace string `yaml:"namespace" json:"namespace,omitempty" property:"namespace"`
ServerAddr string `yaml:"server-addr" json:"server-addr,omitempty" property:"server-addr"`
Group string `yaml:"group" json:"group,omitempty" property:"group"`
Username string `yaml:"username" json:"username,omitempty" property:"username"`
Password string `yaml:"password" json:"password,omitempty" property:"password"`
DataID string `yaml:"data-id" json:"data-id,omitempty" property:"data-id"`
}

// Config is Configuration Center configuration file
type Config struct {
Type string `yaml:"type" json:"type,omitempty" property:"type"`
File File `yaml:"file" json:"file,omitempty" property:"file"`
Nacos NacosConfig `yaml:"nacos" json:"nacos,omitempty" property:"nacos"`
}

+ 23
- 0
pkg/config/configurator.go View File

@@ -0,0 +1,23 @@
/*
* 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.
*/

package config

// Configurator is the interface which wraps GetSeataConfig
type Configurator interface {
GetSeataConfig() *SeataConf
}

+ 19
- 0
pkg/config/doc.go View File

@@ -0,0 +1,19 @@
/*
* 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.
*/

// package config defines interfaces to be implemented by Config
package config

+ 28
- 12
pkg/config/getty_config.go View File

@@ -58,18 +58,34 @@ func GetDefaultGettyConfig() GettyConfig {
}
}

// GettySessionParam getty session param
type Shutdown struct {
Wait time.Duration `yaml:"wait" json:"wait,omitempty" property:"wait"`
}

type Transport struct {
Shutdown Shutdown `yaml:"shutdown" json:"shutdown,omitempty" property:"shutdown"`
Type string `yaml:"type" json:"type,omitempty" property:"type"`
Server string `yaml:"server" json:"server,omitempty" property:"server"`
Heartbeat bool `yaml:"heartbeat" json:"heartbeat,omitempty" property:"heartbeat"`
Serialization string `yaml:"serialization" json:"serialization,omitempty" property:"serialization"`
Compressor string `yaml:"compressor" json:"compressor,omitempty" property:"compressor"`
EnableTmClientBatchSendRequest bool `yaml:"enable-tm-client-batch-send-request" json:"enable-tm-client-batch-send-request,omitempty" property:"enable-tm-client-batch-send-request"`
EnableRmClientBatchSendRequest bool `yaml:"enable-rm-client-batch-send-request" json:"enable-rm-client-batch-send-request,omitempty" property:"enable-rm-client-batch-send-request"`
RPCRmRequestTimeout time.Duration `yaml:"rpc-rm-request-timeout" json:"rpc-rm-request-timeout,omitempty" property:"rpc-rm-request-timeout"`
RPCTmRequestTimeout time.Duration `yaml:"rpc-tm-request-timeout" json:"rpc-tm-request-timeout,omitempty" property:"rpc-tm-request-timeout"`
}

type GettySessionParam struct {
CompressEncoding bool `default:"false" yaml:"compress_encoding" json:"compress_encoding,omitempty"`
TCPNoDelay bool `default:"true" yaml:"tcp_no_delay" json:"tcp_no_delay,omitempty"`
TCPKeepAlive bool `default:"true" yaml:"tcp_keep_alive" json:"tcp_keep_alive,omitempty"`
KeepAlivePeriod time.Duration `default:"180" yaml:"keep_alive_period" json:"keep_alive_period,omitempty"`
CompressEncoding bool `yaml:"compress-encoding" json:"compress-encoding,omitempty" property:"compress-encoding"`
TCPNoDelay bool `yaml:"tcp-no-delay" json:"tcp-no-delay,omitempty" property:"tcp-no-delay"`
TCPKeepAlive bool `yaml:"tcp-keep-alive" json:"tcp-keep-alive,omitempty" property:"tcp-keep-alive"`
KeepAlivePeriod time.Duration `yaml:"keep-alive-period" json:"keep-alive-period,omitempty" property:"keep-alive-period"`
TCPRBufSize int `yaml:"tcp-r-buf-size" json:"tcp-r-buf-size,omitempty" property:"tcp-r-buf-size"`
TCPWBufSize int `yaml:"tcp-w-buf-size" json:"tcp-w-buf-size,omitempty" property:"tcp-w-buf-size"`
TCPReadTimeout time.Duration `yaml:"tcp-read-timeout" json:"tcp-read-timeout,omitempty" property:"tcp-read-timeout"`
TCPWriteTimeout time.Duration `yaml:"tcp-write-timeout" json:"tcp-write-timeout,omitempty" property:"tcp-write-timeout"`
WaitTimeout time.Duration `yaml:"wait-timeout" json:"wait-timeout,omitempty" property:"wait-timeout"`
MaxMsgLen int `yaml:"max-msg-len" json:"max-msg-len,omitempty" property:"max-msg-len"`
SessionName string `yaml:"session-name" json:"session-name,omitempty" property:"session-name"`
CronPeriod time.Duration `default:"1" yaml:"cron_period" json:"cron_period,omitempty"`
TCPRBufSize int `default:"262144" yaml:"tcp_r_buf_size" json:"tcp_r_buf_size,omitempty"`
TCPWBufSize int `default:"65536" yaml:"tcp_w_buf_size" json:"tcp_w_buf_size,omitempty"`
TCPReadTimeout time.Duration `default:"1" yaml:"tcp_read_timeout" json:"tcp_read_timeout,omitempty"`
TCPWriteTimeout time.Duration `default:"5" yaml:"tcp_write_timeout" json:"tcp_write_timeout,omitempty"`
WaitTimeout time.Duration `default:"7" yaml:"wait_timeout" json:"wait_timeout,omitempty"`
MaxMsgLen int `default:"4096" yaml:"max_msg_len" json:"max_msg_len,omitempty"`
SessionName string `default:"rpc" yaml:"session_name" json:"session_name,omitempty"`
}

+ 22
- 0
pkg/config/log_config.go View File

@@ -0,0 +1,22 @@
/*
* 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.
*/

package config

type LogConf struct {
ExceptionRate int `yaml:"exception-rate" json:"exception-rate,omitempty" property:"exception-rate"`
}

+ 49
- 0
pkg/config/parser/configuration_parser.go View File

@@ -0,0 +1,49 @@
/*
* 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.
*/

package parser

import (
"io/ioutil"
"path"

"github.com/pkg/errors"
"gopkg.in/yaml.v2"
)

// ConfigurationParser interface
type ConfigurationParser interface {
Parse(string) (map[string]string, error)
}

// LoadYMLConfig Load yml config byte from file check file type is *.yml or *.yaml`
func LoadYMLConfig(confProFile string) ([]byte, error) {
if len(confProFile) == 0 {
return nil, errors.Errorf("application configure(provider) file name is nil")
}

if path.Ext(confProFile) != ".yml" && path.Ext(confProFile) != ".yaml" {
return nil, errors.Errorf("application configure file name{%v} suffix must be .yml or .yaml", confProFile)
}

return ioutil.ReadFile(confProFile)
}

// UnmarshalYML unmarshals decodes the first document found within the in byte slice and assigns decoded values into the out value.
func UnmarshalYML(data []byte, out interface{}) error {
return yaml.Unmarshal(data, out)
}

+ 38
- 0
pkg/config/parser/configuration_parser_test.go View File

@@ -0,0 +1,38 @@
/*
* 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.
*/

package parser

import (
"path/filepath"
"testing"

"github.com/seata/seata-go/pkg/util/log"
"github.com/stretchr/testify/assert"
)

func TestLoadYMLConfig(t *testing.T) {
conPath, err := filepath.Abs("../../../conf/seata_config.yml")
if err != nil {
log.Infof(err.Error())
}
confBytes, err := LoadYMLConfig(conPath)
if err != nil {
log.Infof(err.Error())
}
assert.NotEmpty(t, confBytes)
}

+ 38
- 0
pkg/config/registry_config.go View File

@@ -0,0 +1,38 @@
/*
* 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.
*/

package config

type File struct {
Name string `yaml:"name" json:"name,omitempty" property:"name"`
}

type NacosRegistry struct {
Application string `yaml:"application" json:"application,omitempty" property:"application"`
ServerAddr string `yaml:"server-addr" json:"server-addr,omitempty" property:"server-addr"`
Group string `yaml:"group" json:"group,omitempty" property:"group"`
Namespace string `yaml:"namespace" json:"namespace,omitempty" property:"namespace"`
Username string `yaml:"username" json:"username,omitempty" property:"username"`
Password string `yaml:"password" json:"password,omitempty" property:"password"`
}

// Registry is Registration Center configuration file
type Registry struct {
Type string `yaml:"type" json:"type,omitempty" property:"type"`
File File `yaml:"file" json:"file,omitempty" property:"file"`
Nacos NacosRegistry `yaml:"nacos" json:"nacos,omitempty" property:"nacos"`
}

+ 72
- 0
pkg/config/seata_config.go View File

@@ -0,0 +1,72 @@
/*
* 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.
*/

package config

import (
"path/filepath"

"github.com/seata/seata-go/pkg/config/parser"
"github.com/seata/seata-go/pkg/util/log"
)

var (
DefaultSeataConf SeataConf
)

// SeataConf is seata config object
type SeataConf struct {
Seata Seata `default:"" yaml:"" json:"seata"`
}

// Init seata configurator
func Init() error {
configPath, err := filepath.Abs("../../conf/seata_config.yml")
if err != nil {
log.Errorf("Init seata config error [get config file path error]: {%#v}", err.Error())
return err
}
configByte, err := parser.LoadYMLConfig(configPath)
if err != nil {
log.Errorf("Init seata config error [load yml file error]: {%#v}", err.Error())
return err
}
err = parser.UnmarshalYML(configByte, &DefaultSeataConf)
if err != nil {
log.Errorf("Init seata config error [unmarshal yml to seataconf error]:{%#v}", err.Error())
return err
}
return nil
}

type Seata struct {
Enabled bool `yaml:"enabled" json:"enabled,omitempty" property:"enabled"`
ApplicationID string `yaml:"application-id" json:"application-id,omitempty" property:"application-id"`
TxServiceGroup string `yaml:"tx-service-group" json:"tx-service-group,omitempty" property:"tx-service-group"`
AccessKey string `yaml:"access-key" json:"access-key,omitempty" property:"access-key"`
SecretKey string `yaml:"secret-key" json:"secret-key,omitempty" property:"secret-key"`
EnableAutoDataSourceProxy bool `yaml:"enable-auto-data-source-proxy" json:"enable-auto-data-source-proxy,omitempty" property:"enable-auto-data-source-proxy"`
DataSourceProxyMode string `yaml:"data-source-proxy-mode" json:"data-source-proxy-mode,omitempty" property:"data-source-proxy-mode"`
ClientConf ClientConf `yaml:"client" json:"client,omitempty" property:"client"`
Service Service `yaml:"service" json:"service,omitempty" property:"service"`
Transport Transport `yaml:"transport" json:"transport,omitempty" property:"transport"`
Config Config `yaml:"config" json:"config,omitempty" property:"config"`
Registry Registry `yaml:"registry" json:"registry,omitempty" property:"registry"`
LogConf LogConf `yaml:"log" json:"log,omitempty" property:"log"`
TccConf TccConf `yaml:"tcc" json:"tcc,omitempty" property:"tcc"`
GettySessionParam GettySessionParam `yaml:"getty-session-param" json:"getty-session-param,omitempty" property:"getty-session-param"`
}

+ 129
- 0
pkg/config/seata_config_test.go View File

@@ -0,0 +1,129 @@
/*
* 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.
*/

package config

import (
"testing"
"time"

"github.com/stretchr/testify/assert"
)

func TestInit(t *testing.T) {
Init()
assert.Equal(t, DefaultSeataConf.Seata.Enabled, true)
assert.Equal(t, DefaultSeataConf.Seata.ApplicationID, "applicationName")
assert.Equal(t, DefaultSeataConf.Seata.TxServiceGroup, "default_tx_group")
assert.Equal(t, DefaultSeataConf.Seata.AccessKey, "aliyunAccessKey")
assert.Equal(t, DefaultSeataConf.Seata.SecretKey, "aliyunSecretKey")
assert.Equal(t, DefaultSeataConf.Seata.EnableAutoDataSourceProxy, true)
assert.Equal(t, DefaultSeataConf.Seata.DataSourceProxyMode, "AT")

// client
// rm
assert.Equal(t, DefaultSeataConf.Seata.ClientConf.Rmconf.AsyncCommitBufferLimit, 10000)
assert.Equal(t, DefaultSeataConf.Seata.ClientConf.Rmconf.ReportRetryCount, 5)
assert.Equal(t, DefaultSeataConf.Seata.ClientConf.Rmconf.TableMetaCheckEnable, false)
assert.Equal(t, DefaultSeataConf.Seata.ClientConf.Rmconf.ReportSuccessEnable, false)
assert.Equal(t, DefaultSeataConf.Seata.ClientConf.Rmconf.SagaBranchRegisterEnable, false)
assert.Equal(t, DefaultSeataConf.Seata.ClientConf.Rmconf.SagaJSONParser, "fastjson")
assert.Equal(t, DefaultSeataConf.Seata.ClientConf.Rmconf.SagaRetryPersistModeUpdate, false)
assert.Equal(t, DefaultSeataConf.Seata.ClientConf.Rmconf.SagaCompensatePersistModeUpdate, false)
assert.Equal(t, DefaultSeataConf.Seata.ClientConf.Rmconf.TccActionInterceptorOrder, -2147482648)
assert.Equal(t, DefaultSeataConf.Seata.ClientConf.Rmconf.SQLParserType, "druid")
assert.Equal(t, DefaultSeataConf.Seata.ClientConf.Rmconf.Lock.RetryInterval, 10)
assert.Equal(t, DefaultSeataConf.Seata.ClientConf.Rmconf.Lock.RetryTimes, time.Duration(30_000_000_000))
assert.Equal(t, DefaultSeataConf.Seata.ClientConf.Rmconf.Lock.RetryPolicyBranchRollbackOnConflict, true)
// tm
assert.Equal(t, DefaultSeataConf.Seata.ClientConf.Tmconf.CommitRetryCount, 5)
assert.Equal(t, DefaultSeataConf.Seata.ClientConf.Tmconf.RollbackRetryCount, 5)
assert.Equal(t, DefaultSeataConf.Seata.ClientConf.Tmconf.DefaultGlobalTransactionTimeout, time.Duration(10_000_000_000))
assert.Equal(t, DefaultSeataConf.Seata.ClientConf.Tmconf.DegradeCheck, false)
assert.Equal(t, DefaultSeataConf.Seata.ClientConf.Tmconf.DegradeCheckPeriod, 2000)
assert.Equal(t, DefaultSeataConf.Seata.ClientConf.Tmconf.DegradeCheckAllowTimes, time.Duration(10_000_000_000))
assert.Equal(t, DefaultSeataConf.Seata.ClientConf.Tmconf.InterceptorOrder, -2147482648)
// undo
assert.Equal(t, DefaultSeataConf.Seata.ClientConf.Undo.DataValidation, true)
assert.Equal(t, DefaultSeataConf.Seata.ClientConf.Undo.LogSerialization, "jackson")
assert.Equal(t, DefaultSeataConf.Seata.ClientConf.Undo.LogTable, "undo_log")
assert.Equal(t, DefaultSeataConf.Seata.ClientConf.Undo.OnlyCareUpdateColumns, true)
assert.Equal(t, DefaultSeataConf.Seata.ClientConf.Undo.Compress.Enable, true)
assert.Equal(t, DefaultSeataConf.Seata.ClientConf.Undo.Compress.Type, "zip")
assert.Equal(t, DefaultSeataConf.Seata.ClientConf.Undo.Compress.Threshold, 64)
// load-balance
assert.Equal(t, DefaultSeataConf.Seata.ClientConf.LoadBalance.Type, "RandomLoadBalance")
assert.Equal(t, DefaultSeataConf.Seata.ClientConf.LoadBalance.VirtualNodes, 10)

// service
assert.Equal(t, DefaultSeataConf.Seata.Service.VgroupMapping.DefaultTxGroup, "default")
assert.Equal(t, DefaultSeataConf.Seata.Service.Grouplist.Default, "127.0.0.1:8091")
assert.Equal(t, DefaultSeataConf.Seata.Service.EnableDegrade, false)
assert.Equal(t, DefaultSeataConf.Seata.Service.DisableGlobalTransaction, false)

// transport
assert.Equal(t, DefaultSeataConf.Seata.Transport.Shutdown.Wait, time.Duration(3_000_000_000))
assert.Equal(t, DefaultSeataConf.Seata.Transport.Type, "TCP")
assert.Equal(t, DefaultSeataConf.Seata.Transport.Server, "NIO")
assert.Equal(t, DefaultSeataConf.Seata.Transport.Heartbeat, true)
assert.Equal(t, DefaultSeataConf.Seata.Transport.Serialization, "seata")
assert.Equal(t, DefaultSeataConf.Seata.Transport.Compressor, "none")
assert.Equal(t, DefaultSeataConf.Seata.Transport.EnableTmClientBatchSendRequest, false)
assert.Equal(t, DefaultSeataConf.Seata.Transport.EnableRmClientBatchSendRequest, true)
assert.Equal(t, DefaultSeataConf.Seata.Transport.RPCRmRequestTimeout, time.Duration(3_000_000_000))
assert.Equal(t, DefaultSeataConf.Seata.Transport.RPCTmRequestTimeout, time.Duration(3_000_000_000))

// config
assert.Equal(t, DefaultSeataConf.Seata.Config.Type, "file")
assert.Equal(t, DefaultSeataConf.Seata.Config.File.Name, "config.conf")
assert.Equal(t, DefaultSeataConf.Seata.Config.Nacos.Namespace, "")
assert.Equal(t, DefaultSeataConf.Seata.Config.Nacos.ServerAddr, "127.0.0.1:8848")
assert.Equal(t, DefaultSeataConf.Seata.Config.Nacos.Group, "SEATA_GROUP")
assert.Equal(t, DefaultSeataConf.Seata.Config.Nacos.Username, "")
assert.Equal(t, DefaultSeataConf.Seata.Config.Nacos.Password, "")
assert.Equal(t, DefaultSeataConf.Seata.Config.Nacos.DataID, "seata.properties")

// registry
assert.Equal(t, DefaultSeataConf.Seata.Registry.Type, "file")
assert.Equal(t, DefaultSeataConf.Seata.Registry.File.Name, "registry.conf")
assert.Equal(t, DefaultSeataConf.Seata.Registry.Nacos.Application, "seata-server")
assert.Equal(t, DefaultSeataConf.Seata.Registry.Nacos.ServerAddr, "127.0.0.1:8848")
assert.Equal(t, DefaultSeataConf.Seata.Registry.Nacos.Group, "SEATA_GROUP")
assert.Equal(t, DefaultSeataConf.Seata.Registry.Nacos.Namespace, "")
assert.Equal(t, DefaultSeataConf.Seata.Registry.Nacos.Username, "")
assert.Equal(t, DefaultSeataConf.Seata.Registry.Nacos.Password, "")

// log
assert.Equal(t, DefaultSeataConf.Seata.LogConf.ExceptionRate, 100)

// tcc
assert.Equal(t, DefaultSeataConf.Seata.TccConf.Fence.LogTableName, "tcc_fence_log")
assert.Equal(t, DefaultSeataConf.Seata.TccConf.Fence.CleanPeriod, time.Duration(60_000_000_000))

// getty-session-param
assert.Equal(t, DefaultSeataConf.Seata.GettySessionParam.CompressEncoding, false)
assert.Equal(t, DefaultSeataConf.Seata.GettySessionParam.TCPNoDelay, true)
assert.Equal(t, DefaultSeataConf.Seata.GettySessionParam.TCPKeepAlive, true)
assert.Equal(t, DefaultSeataConf.Seata.GettySessionParam.KeepAlivePeriod, time.Duration(120_000_000_000))
assert.Equal(t, DefaultSeataConf.Seata.GettySessionParam.TCPRBufSize, 262144)
assert.Equal(t, DefaultSeataConf.Seata.GettySessionParam.TCPWBufSize, 65536)
assert.Equal(t, DefaultSeataConf.Seata.GettySessionParam.TCPReadTimeout, time.Duration(1_000_000_000))
assert.Equal(t, DefaultSeataConf.Seata.GettySessionParam.TCPWriteTimeout, time.Duration(5_000_000_000))
assert.Equal(t, DefaultSeataConf.Seata.GettySessionParam.WaitTimeout, time.Duration(1_000_000_000))
assert.Equal(t, DefaultSeataConf.Seata.GettySessionParam.MaxMsgLen, 16498688)
assert.Equal(t, DefaultSeataConf.Seata.GettySessionParam.SessionName, "client")
}

+ 33
- 0
pkg/config/service_config.go View File

@@ -0,0 +1,33 @@
/*
* 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.
*/

package config

type Grouplist struct {
Default string `yaml:"default" json:"default,omitempty" property:"default"`
}

type VgroupMapping struct {
DefaultTxGroup string `yaml:"default_tx_group" json:"default_tx_group,omitempty" property:"default_tx_group"`
}

type Service struct {
VgroupMapping VgroupMapping `yaml:"vgroup-mapping" json:"vgroup-mapping,omitempty" property:"vgroup-mapping"`
Grouplist Grouplist `yaml:"grouplist" json:"grouplist,omitempty" property:"grouplist"`
EnableDegrade bool `yaml:"enable-degrade" json:"enable-degrade,omitempty" property:"enable-degrade"`
DisableGlobalTransaction bool `yaml:"disable-global-transaction" json:"disable-global-transaction,omitempty" property:"disable-global-transaction"`
}

+ 29
- 0
pkg/config/tcc_config.go View File

@@ -0,0 +1,29 @@
/*
* 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.
*/

package config

import "time"

type Fence struct {
LogTableName string `yaml:"log-table-name" json:"log-table-name,omitempty" property:"log-table-name"`
CleanPeriod time.Duration `yaml:"clean-period" json:"clean-period,omitempty" property:"clean-period"`
}

type TccConf struct {
Fence Fence `yaml:"fence" json:"fence,omitempty" property:"fence"`
}

Loading…
Cancel
Save