From d1ca24b9cd466f0f4901e77e2e27246bd106bd5e Mon Sep 17 00:00:00 2001 From: liushao <505786909@qq.com> Date: Sat, 10 Dec 2022 20:20:55 +0800 Subject: [PATCH 1/8] feat(pkg/client,pkg/config):tm config --- pkg/client/config.go | 11 ++++++---- pkg/config/client_config.go | 40 +++++++++++++++++++++++++++---------- 2 files changed, 36 insertions(+), 15 deletions(-) diff --git a/pkg/client/config.go b/pkg/client/config.go index 584423fd1..e425f51f3 100644 --- a/pkg/client/config.go +++ b/pkg/client/config.go @@ -26,6 +26,8 @@ import ( "runtime" "strings" + "github.com/seata/seata-go/pkg/config" + "github.com/knadh/koanf" "github.com/knadh/koanf/parsers/json" "github.com/knadh/koanf/parsers/toml" @@ -48,11 +50,13 @@ const ( ) type Config struct { - TCCConfig tcc.Config `yaml:"tcc" json:"tcc" koanf:"tcc"` + TCCConfig tcc.Config `yaml:"tcc" json:"tcc" koanf:"tcc"` + ClientConfig config.ClientConf `yaml:"client" json:"client" koanf:"client"` } func (c *Config) RegisterFlags(f *flag.FlagSet) { c.TCCConfig.FenceConfig.RegisterFlagsWithPrefix("tcc", f) + c.ClientConfig.RegisterFlagsWithPrefix("client", f) } type loaderConf struct { @@ -108,7 +112,7 @@ func getJsonConfigResolver(bytes []byte) *koanf.Koanf { return k } -//resolverFilePath resolver file path +// resolverFilePath resolver file path // eg: give a ./conf/seatago.yaml return seatago and yaml func resolverFilePath(path string) (name, suffix string) { paths := strings.Split(path, "/") @@ -175,7 +179,6 @@ func newLoaderConf(configFilePath string) *loaderConf { // absolutePath get absolut path func absolutePath(inPath string) string { - if inPath == "$HOME" || strings.HasPrefix(inPath, "$HOME"+string(os.PathSeparator)) { inPath = userHomeDir() + inPath[5:] } @@ -192,7 +195,7 @@ func absolutePath(inPath string) string { return "" } -//userHomeDir get gopath +// userHomeDir get gopath func userHomeDir() string { if runtime.GOOS == "windows" { home := os.Getenv("HOMEDRIVE") + os.Getenv("HOMEPATH") diff --git a/pkg/config/client_config.go b/pkg/config/client_config.go index 4e9ffa8a8..2097f407f 100644 --- a/pkg/config/client_config.go +++ b/pkg/config/client_config.go @@ -18,6 +18,7 @@ package config import ( + "flag" "time" ) @@ -82,13 +83,23 @@ type RmConf struct { } 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"` + CommitRetryCount int `yaml:"commit-retry-count" json:"commit-retry-count,omitempty" property:"commit-retry-count" koanf:"commit-retry-count"` + RollbackRetryCount int `yaml:"rollback-retry-count" json:"rollback-retry-count,omitempty" property:"rollback-retry-count" koanf:"rollback-retry-count"` + DefaultGlobalTransactionTimeout time.Duration `yaml:"default-global-transaction-timeout" json:"default-global-transaction-timeout,omitempty" property:"default-global-transaction-timeout" koanf:"default-global-transaction-timeout"` + DegradeCheck bool `yaml:"degrade-check" json:"degrade-check,omitempty" property:"degrade-check" koanf:"degrade-check"` + DegradeCheckPeriod int `yaml:"degrade-check-period" json:"degrade-check-period,omitempty" property:"degrade-check-period" koanf:"degrade-check-period"` + DegradeCheckAllowTimes time.Duration `yaml:"degrade-check-allow-times" json:"degrade-check-allow-times,omitempty" property:"degrade-check-allow-times" koanf:"degrade-check-allow-times"` + InterceptorOrder int `yaml:"interceptor-order" json:"interceptor-order,omitempty" property:"interceptor-order" koanf:"interceptor-order"` +} + +func (cfg *TmConf) RegisterFlagsWithPrefix(prefix string, f *flag.FlagSet) { + f.IntVar(&cfg.CommitRetryCount, prefix+".commit-retry-count", 5, "The maximum number of retries when commit global transaction.") + f.IntVar(&cfg.RollbackRetryCount, prefix+".rollback-retry-count", 5, "The maximum number of retries when rollback global transaction.") + f.DurationVar(&cfg.DefaultGlobalTransactionTimeout, prefix+".default-global-transaction-timeout", 10*time.Second, "The timeout for a global transaction.") + f.BoolVar(&cfg.DegradeCheck, prefix+".degrade-check", false, "The switch for degrade check.") + f.IntVar(&cfg.DegradeCheckPeriod, prefix+".degrade-check-period", 2000, "The period of degrade checking.") + f.DurationVar(&cfg.DegradeCheckAllowTimes, prefix+".degrade-check-allow-times", 10*time.Second, "The duration allowed or degrade checking.") + f.IntVar(&cfg.InterceptorOrder, prefix+".interceptor-order", -2147482648, "The order of interceptor.") } type Undo struct { @@ -105,8 +116,15 @@ type LoadBalance struct { } 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"` + Rmconf RmConf `yaml:"rm" json:"rm,omitempty" property:"rm" koanf:"rm"` + Tmconf TmConf `yaml:"tm" json:"tm,omitempty" property:"tm" koanf:"tm"` + Undo Undo `yaml:"undo" json:"undo,omitempty" property:"undo" koanf:"undo"` + LoadBalance LoadBalance `yaml:"load-balance" json:"load-balance,omitempty" property:"load-balance" koanf:"load-balance"` +} + +func (c *ClientConf) RegisterFlagsWithPrefix(prefix string, f *flag.FlagSet) { + // TODO: RmConf RegisterFlagsWithPrefix + // TODO: Undo RegisterFlagsWithPrefix + // TODO: LoadBalance RegisterFlagsWithPrefix + c.Tmconf.RegisterFlagsWithPrefix(prefix+".tm", f) } From 6ebb2d3e558a34f0d9a0e30eae83ce21a8feffdc Mon Sep 17 00:00:00 2001 From: liushao <505786909@qq.com> Date: Sat, 10 Dec 2022 20:26:05 +0800 Subject: [PATCH 2/8] fix(pkg/config):correct spelling --- pkg/config/client_config.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/config/client_config.go b/pkg/config/client_config.go index 2097f407f..211e5c2a3 100644 --- a/pkg/config/client_config.go +++ b/pkg/config/client_config.go @@ -97,8 +97,8 @@ func (cfg *TmConf) RegisterFlagsWithPrefix(prefix string, f *flag.FlagSet) { f.IntVar(&cfg.RollbackRetryCount, prefix+".rollback-retry-count", 5, "The maximum number of retries when rollback global transaction.") f.DurationVar(&cfg.DefaultGlobalTransactionTimeout, prefix+".default-global-transaction-timeout", 10*time.Second, "The timeout for a global transaction.") f.BoolVar(&cfg.DegradeCheck, prefix+".degrade-check", false, "The switch for degrade check.") - f.IntVar(&cfg.DegradeCheckPeriod, prefix+".degrade-check-period", 2000, "The period of degrade checking.") - f.DurationVar(&cfg.DegradeCheckAllowTimes, prefix+".degrade-check-allow-times", 10*time.Second, "The duration allowed or degrade checking.") + f.IntVar(&cfg.DegradeCheckPeriod, prefix+".degrade-check-period", 2000, "The period for degrade checking.") + f.DurationVar(&cfg.DegradeCheckAllowTimes, prefix+".degrade-check-allow-times", 10*time.Second, "The duration allowed for degrade checking.") f.IntVar(&cfg.InterceptorOrder, prefix+".interceptor-order", -2147482648, "The order of interceptor.") } From 7d05415f00fcbf5aecc0abac329ebe3c67d5f1d9 Mon Sep 17 00:00:00 2001 From: liushao <505786909@qq.com> Date: Sat, 10 Dec 2022 20:54:13 +0800 Subject: [PATCH 3/8] refactor(client,config,tm): move tm config code into tm module 1. revert pkg/config/client_config.go . 2. tm config ut . --- pkg/client/config.go | 17 +++++++++++++--- pkg/client/config_test.go | 6 ++++++ pkg/config/client_config.go | 40 ++++++++++--------------------------- pkg/tm/config.go | 26 ++++++++++++++++++++++++ 4 files changed, 57 insertions(+), 32 deletions(-) create mode 100644 pkg/tm/config.go diff --git a/pkg/client/config.go b/pkg/client/config.go index e425f51f3..de369385d 100644 --- a/pkg/client/config.go +++ b/pkg/client/config.go @@ -26,7 +26,7 @@ import ( "runtime" "strings" - "github.com/seata/seata-go/pkg/config" + "github.com/seata/seata-go/pkg/tm" "github.com/knadh/koanf" "github.com/knadh/koanf/parsers/json" @@ -49,9 +49,20 @@ const ( ymlSuffix = "yml" ) +type ClientConf struct { + Tmconf tm.TmConf `yaml:"tm" json:"tm,omitempty" property:"tm"` +} + +func (c *ClientConf) RegisterFlagsWithPrefix(prefix string, f *flag.FlagSet) { + // TODO: RmConf RegisterFlagsWithPrefix + // TODO: Undo RegisterFlagsWithPrefix + // TODO: LoadBalance RegisterFlagsWithPrefix + c.Tmconf.RegisterFlagsWithPrefix(prefix+".tm", f) +} + type Config struct { - TCCConfig tcc.Config `yaml:"tcc" json:"tcc" koanf:"tcc"` - ClientConfig config.ClientConf `yaml:"client" json:"client" koanf:"client"` + TCCConfig tcc.Config `yaml:"tcc" json:"tcc" koanf:"tcc"` + ClientConfig ClientConf `yaml:"client" json:"client" koanf:"client"` } func (c *Config) RegisterFlags(f *flag.FlagSet) { diff --git a/pkg/client/config_test.go b/pkg/client/config_test.go index 9e53a6f82..108c5bc54 100644 --- a/pkg/client/config_test.go +++ b/pkg/client/config_test.go @@ -34,6 +34,12 @@ func TestLoadPath(t *testing.T) { assert.Equal(t, "tcc_fence_log_test", cfg.TCCConfig.FenceConfig.LogTableName) assert.Equal(t, time.Second*60, cfg.TCCConfig.FenceConfig.CleanPeriod) + + assert.NotNil(t, cfg.ClientConfig) + assert.NotNil(t, cfg.ClientConfig.Tmconf) + assert.Equal(t, 5, cfg.ClientConfig.Tmconf.CommitRetryCount) + assert.Equal(t, time.Second*10, cfg.ClientConfig.Tmconf.DefaultGlobalTransactionTimeout) + // reset flag.CommandLine flag.CommandLine = flag.NewFlagSet(os.Args[0], flag.ExitOnError) } diff --git a/pkg/config/client_config.go b/pkg/config/client_config.go index 211e5c2a3..4e9ffa8a8 100644 --- a/pkg/config/client_config.go +++ b/pkg/config/client_config.go @@ -18,7 +18,6 @@ package config import ( - "flag" "time" ) @@ -83,23 +82,13 @@ type RmConf struct { } type TmConf struct { - CommitRetryCount int `yaml:"commit-retry-count" json:"commit-retry-count,omitempty" property:"commit-retry-count" koanf:"commit-retry-count"` - RollbackRetryCount int `yaml:"rollback-retry-count" json:"rollback-retry-count,omitempty" property:"rollback-retry-count" koanf:"rollback-retry-count"` - DefaultGlobalTransactionTimeout time.Duration `yaml:"default-global-transaction-timeout" json:"default-global-transaction-timeout,omitempty" property:"default-global-transaction-timeout" koanf:"default-global-transaction-timeout"` - DegradeCheck bool `yaml:"degrade-check" json:"degrade-check,omitempty" property:"degrade-check" koanf:"degrade-check"` - DegradeCheckPeriod int `yaml:"degrade-check-period" json:"degrade-check-period,omitempty" property:"degrade-check-period" koanf:"degrade-check-period"` - DegradeCheckAllowTimes time.Duration `yaml:"degrade-check-allow-times" json:"degrade-check-allow-times,omitempty" property:"degrade-check-allow-times" koanf:"degrade-check-allow-times"` - InterceptorOrder int `yaml:"interceptor-order" json:"interceptor-order,omitempty" property:"interceptor-order" koanf:"interceptor-order"` -} - -func (cfg *TmConf) RegisterFlagsWithPrefix(prefix string, f *flag.FlagSet) { - f.IntVar(&cfg.CommitRetryCount, prefix+".commit-retry-count", 5, "The maximum number of retries when commit global transaction.") - f.IntVar(&cfg.RollbackRetryCount, prefix+".rollback-retry-count", 5, "The maximum number of retries when rollback global transaction.") - f.DurationVar(&cfg.DefaultGlobalTransactionTimeout, prefix+".default-global-transaction-timeout", 10*time.Second, "The timeout for a global transaction.") - f.BoolVar(&cfg.DegradeCheck, prefix+".degrade-check", false, "The switch for degrade check.") - f.IntVar(&cfg.DegradeCheckPeriod, prefix+".degrade-check-period", 2000, "The period for degrade checking.") - f.DurationVar(&cfg.DegradeCheckAllowTimes, prefix+".degrade-check-allow-times", 10*time.Second, "The duration allowed for degrade checking.") - f.IntVar(&cfg.InterceptorOrder, prefix+".interceptor-order", -2147482648, "The order of interceptor.") + 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 { @@ -116,15 +105,8 @@ type LoadBalance struct { } type ClientConf struct { - Rmconf RmConf `yaml:"rm" json:"rm,omitempty" property:"rm" koanf:"rm"` - Tmconf TmConf `yaml:"tm" json:"tm,omitempty" property:"tm" koanf:"tm"` - Undo Undo `yaml:"undo" json:"undo,omitempty" property:"undo" koanf:"undo"` - LoadBalance LoadBalance `yaml:"load-balance" json:"load-balance,omitempty" property:"load-balance" koanf:"load-balance"` -} - -func (c *ClientConf) RegisterFlagsWithPrefix(prefix string, f *flag.FlagSet) { - // TODO: RmConf RegisterFlagsWithPrefix - // TODO: Undo RegisterFlagsWithPrefix - // TODO: LoadBalance RegisterFlagsWithPrefix - c.Tmconf.RegisterFlagsWithPrefix(prefix+".tm", f) + 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"` } diff --git a/pkg/tm/config.go b/pkg/tm/config.go new file mode 100644 index 000000000..4c4496187 --- /dev/null +++ b/pkg/tm/config.go @@ -0,0 +1,26 @@ +package tm + +import ( + "flag" + "time" +) + +type TmConf struct { + CommitRetryCount int `yaml:"commit-retry-count" json:"commit-retry-count,omitempty" property:"commit-retry-count" koanf:"commit-retry-count"` + RollbackRetryCount int `yaml:"rollback-retry-count" json:"rollback-retry-count,omitempty" property:"rollback-retry-count" koanf:"rollback-retry-count"` + DefaultGlobalTransactionTimeout time.Duration `yaml:"default-global-transaction-timeout" json:"default-global-transaction-timeout,omitempty" property:"default-global-transaction-timeout" koanf:"default-global-transaction-timeout"` + DegradeCheck bool `yaml:"degrade-check" json:"degrade-check,omitempty" property:"degrade-check" koanf:"degrade-check"` + DegradeCheckPeriod int `yaml:"degrade-check-period" json:"degrade-check-period,omitempty" property:"degrade-check-period" koanf:"degrade-check-period"` + DegradeCheckAllowTimes time.Duration `yaml:"degrade-check-allow-times" json:"degrade-check-allow-times,omitempty" property:"degrade-check-allow-times" koanf:"degrade-check-allow-times"` + InterceptorOrder int `yaml:"interceptor-order" json:"interceptor-order,omitempty" property:"interceptor-order" koanf:"interceptor-order"` +} + +func (cfg *TmConf) RegisterFlagsWithPrefix(prefix string, f *flag.FlagSet) { + f.IntVar(&cfg.CommitRetryCount, prefix+".commit-retry-count", 5, "The maximum number of retries when commit global transaction.") + f.IntVar(&cfg.RollbackRetryCount, prefix+".rollback-retry-count", 5, "The maximum number of retries when rollback global transaction.") + f.DurationVar(&cfg.DefaultGlobalTransactionTimeout, prefix+".default-global-transaction-timeout", 10*time.Second, "The timeout for a global transaction.") + f.BoolVar(&cfg.DegradeCheck, prefix+".degrade-check", false, "The switch for degrade check.") + f.IntVar(&cfg.DegradeCheckPeriod, prefix+".degrade-check-period", 2000, "The period for degrade checking.") + f.DurationVar(&cfg.DegradeCheckAllowTimes, prefix+".degrade-check-allow-times", 10*time.Second, "The duration allowed for degrade checking.") + f.IntVar(&cfg.InterceptorOrder, prefix+".interceptor-order", -2147482648, "The order of interceptor.") +} From a2e0c1d931638e12673eb4df74cb093e37a19111 Mon Sep 17 00:00:00 2001 From: liushao <505786909@qq.com> Date: Sat, 10 Dec 2022 20:55:38 +0800 Subject: [PATCH 4/8] refactor(client): add koanf tag for ClientConfig.TmConfig --- pkg/client/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/client/config.go b/pkg/client/config.go index de369385d..1f848e5f0 100644 --- a/pkg/client/config.go +++ b/pkg/client/config.go @@ -50,7 +50,7 @@ const ( ) type ClientConf struct { - Tmconf tm.TmConf `yaml:"tm" json:"tm,omitempty" property:"tm"` + Tmconf tm.TmConf `yaml:"tm" json:"tm,omitempty" property:"tm" koanf:"tm"` } func (c *ClientConf) RegisterFlagsWithPrefix(prefix string, f *flag.FlagSet) { From ef1df34f2974ac4bad8837631abf26adb8becd44 Mon Sep 17 00:00:00 2001 From: liushao <505786909@qq.com> Date: Sat, 10 Dec 2022 21:00:15 +0800 Subject: [PATCH 5/8] test(client): add json string unit test code for tm config --- pkg/client/config_test.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pkg/client/config_test.go b/pkg/client/config_test.go index 108c5bc54..32aefab5a 100644 --- a/pkg/client/config_test.go +++ b/pkg/client/config_test.go @@ -45,7 +45,7 @@ func TestLoadPath(t *testing.T) { } func TestLoadJson(t *testing.T) { - confJson := `{"tcc":{"fence":{"log-table-name":"tcc_fence_log_test2","clean-period":80000000000}}}` + confJson := `{"client":{"tm":{"commit-retry-count":5,"default-global-transaction-timeout":"10s"}},"tcc":{"fence":{"log-table-name":"tcc_fence_log_test2","clean-period":80000000000}}}` cfg := LoadJson([]byte(confJson)) assert.NotNil(t, cfg) assert.NotNil(t, cfg.TCCConfig) @@ -53,6 +53,11 @@ func TestLoadJson(t *testing.T) { assert.Equal(t, "tcc_fence_log_test2", cfg.TCCConfig.FenceConfig.LogTableName) assert.Equal(t, time.Second*80, cfg.TCCConfig.FenceConfig.CleanPeriod) + + assert.NotNil(t, cfg.ClientConfig) + assert.NotNil(t, cfg.ClientConfig.Tmconf) + assert.Equal(t, 5, cfg.ClientConfig.Tmconf.CommitRetryCount) + assert.Equal(t, time.Second*10, cfg.ClientConfig.Tmconf.DefaultGlobalTransactionTimeout) // reset flag.CommandLine flag.CommandLine = flag.NewFlagSet(os.Args[0], flag.ExitOnError) } From fb0876d9fd5970f11f3e9e99bd2f9e4df6cdc0f8 Mon Sep 17 00:00:00 2001 From: liushao <505786909@qq.com> Date: Sun, 11 Dec 2022 13:33:05 +0800 Subject: [PATCH 6/8] refactor(pkg,testdata): optimize struct name,default value,unit test 1. Rename struct TmConf to TmConfig. 2. Set the default value of global-transation-timeout to 60s. 3. Perfecting the unit test for TmConfig, cover all configuration items. 4. Execute goimports.sh in project root path. --- pkg/client/config.go | 4 +- pkg/client/config_test.go | 25 +++++++++---- .../builder/mysql_insert_undo_log_builder.go | 2 +- pkg/tm/config.go | 37 ++++++++++++++----- testdata/conf/seatago.yml | 2 +- 5 files changed, 49 insertions(+), 21 deletions(-) diff --git a/pkg/client/config.go b/pkg/client/config.go index 1f848e5f0..4e72a5b28 100644 --- a/pkg/client/config.go +++ b/pkg/client/config.go @@ -50,14 +50,14 @@ const ( ) type ClientConf struct { - Tmconf tm.TmConf `yaml:"tm" json:"tm,omitempty" property:"tm" koanf:"tm"` + TmConfig tm.TmConfig `yaml:"tm" json:"tm,omitempty" property:"tm" koanf:"tm"` } func (c *ClientConf) RegisterFlagsWithPrefix(prefix string, f *flag.FlagSet) { // TODO: RmConf RegisterFlagsWithPrefix // TODO: Undo RegisterFlagsWithPrefix // TODO: LoadBalance RegisterFlagsWithPrefix - c.Tmconf.RegisterFlagsWithPrefix(prefix+".tm", f) + c.TmConfig.RegisterFlagsWithPrefix(prefix+".tm", f) } type Config struct { diff --git a/pkg/client/config_test.go b/pkg/client/config_test.go index 32aefab5a..06dd38d0c 100644 --- a/pkg/client/config_test.go +++ b/pkg/client/config_test.go @@ -36,16 +36,21 @@ func TestLoadPath(t *testing.T) { assert.Equal(t, time.Second*60, cfg.TCCConfig.FenceConfig.CleanPeriod) assert.NotNil(t, cfg.ClientConfig) - assert.NotNil(t, cfg.ClientConfig.Tmconf) - assert.Equal(t, 5, cfg.ClientConfig.Tmconf.CommitRetryCount) - assert.Equal(t, time.Second*10, cfg.ClientConfig.Tmconf.DefaultGlobalTransactionTimeout) + assert.NotNil(t, cfg.ClientConfig.TmConfig) + assert.Equal(t, 5, cfg.ClientConfig.TmConfig.CommitRetryCount) + assert.Equal(t, 5, cfg.ClientConfig.TmConfig.RollbackRetryCount) + assert.Equal(t, time.Second*60, cfg.ClientConfig.TmConfig.DefaultGlobalTransactionTimeout) + assert.Equal(t, false, cfg.ClientConfig.TmConfig.DegradeCheck) + assert.Equal(t, 2000, cfg.ClientConfig.TmConfig.DegradeCheckPeriod) + assert.Equal(t, time.Second*10, cfg.ClientConfig.TmConfig.DegradeCheckAllowTimes) + assert.Equal(t, -2147482648, cfg.ClientConfig.TmConfig.InterceptorOrder) // reset flag.CommandLine flag.CommandLine = flag.NewFlagSet(os.Args[0], flag.ExitOnError) } func TestLoadJson(t *testing.T) { - confJson := `{"client":{"tm":{"commit-retry-count":5,"default-global-transaction-timeout":"10s"}},"tcc":{"fence":{"log-table-name":"tcc_fence_log_test2","clean-period":80000000000}}}` + confJson := `{"client":{"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}},"tcc":{"fence":{"log-table-name":"tcc_fence_log_test2","clean-period":80000000000}}}` cfg := LoadJson([]byte(confJson)) assert.NotNil(t, cfg) assert.NotNil(t, cfg.TCCConfig) @@ -55,9 +60,15 @@ func TestLoadJson(t *testing.T) { assert.Equal(t, time.Second*80, cfg.TCCConfig.FenceConfig.CleanPeriod) assert.NotNil(t, cfg.ClientConfig) - assert.NotNil(t, cfg.ClientConfig.Tmconf) - assert.Equal(t, 5, cfg.ClientConfig.Tmconf.CommitRetryCount) - assert.Equal(t, time.Second*10, cfg.ClientConfig.Tmconf.DefaultGlobalTransactionTimeout) + assert.NotNil(t, cfg.ClientConfig.TmConfig) + assert.Equal(t, 5, cfg.ClientConfig.TmConfig.CommitRetryCount) + assert.Equal(t, 5, cfg.ClientConfig.TmConfig.RollbackRetryCount) + assert.Equal(t, time.Second*60, cfg.ClientConfig.TmConfig.DefaultGlobalTransactionTimeout) + assert.Equal(t, false, cfg.ClientConfig.TmConfig.DegradeCheck) + assert.Equal(t, 2000, cfg.ClientConfig.TmConfig.DegradeCheckPeriod) + assert.Equal(t, time.Second*10, cfg.ClientConfig.TmConfig.DegradeCheckAllowTimes) + assert.Equal(t, -2147482648, cfg.ClientConfig.TmConfig.InterceptorOrder) + // reset flag.CommandLine flag.CommandLine = flag.NewFlagSet(os.Args[0], flag.ExitOnError) } diff --git a/pkg/datasource/sql/undo/builder/mysql_insert_undo_log_builder.go b/pkg/datasource/sql/undo/builder/mysql_insert_undo_log_builder.go index af434e5a8..de2d998d6 100644 --- a/pkg/datasource/sql/undo/builder/mysql_insert_undo_log_builder.go +++ b/pkg/datasource/sql/undo/builder/mysql_insert_undo_log_builder.go @@ -186,7 +186,7 @@ func (u *MySQLInsertUndoLogBuilder) getPkValues(execCtx *types.ExecContext, pars return pkValuesMap, nil } -//containsPK the columns contains table meta pk +// containsPK the columns contains table meta pk func (u *MySQLInsertUndoLogBuilder) containsPK(meta types.TableMeta, parseCtx *types.ParseContext) bool { pkColumnNameList := meta.GetPrimaryKeyOnlyName() if len(pkColumnNameList) == 0 { diff --git a/pkg/tm/config.go b/pkg/tm/config.go index 4c4496187..b940910c3 100644 --- a/pkg/tm/config.go +++ b/pkg/tm/config.go @@ -1,3 +1,20 @@ +/* + * 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 tm import ( @@ -5,20 +22,20 @@ import ( "time" ) -type TmConf struct { - CommitRetryCount int `yaml:"commit-retry-count" json:"commit-retry-count,omitempty" property:"commit-retry-count" koanf:"commit-retry-count"` - RollbackRetryCount int `yaml:"rollback-retry-count" json:"rollback-retry-count,omitempty" property:"rollback-retry-count" koanf:"rollback-retry-count"` - DefaultGlobalTransactionTimeout time.Duration `yaml:"default-global-transaction-timeout" json:"default-global-transaction-timeout,omitempty" property:"default-global-transaction-timeout" koanf:"default-global-transaction-timeout"` - DegradeCheck bool `yaml:"degrade-check" json:"degrade-check,omitempty" property:"degrade-check" koanf:"degrade-check"` - DegradeCheckPeriod int `yaml:"degrade-check-period" json:"degrade-check-period,omitempty" property:"degrade-check-period" koanf:"degrade-check-period"` - DegradeCheckAllowTimes time.Duration `yaml:"degrade-check-allow-times" json:"degrade-check-allow-times,omitempty" property:"degrade-check-allow-times" koanf:"degrade-check-allow-times"` - InterceptorOrder int `yaml:"interceptor-order" json:"interceptor-order,omitempty" property:"interceptor-order" koanf:"interceptor-order"` +type TmConfig struct { + CommitRetryCount int `yaml:"commit-retry-count" json:"commit-retry-count" koanf:"commit-retry-count"` + RollbackRetryCount int `yaml:"rollback-retry-count" json:"rollback-retry-count" koanf:"rollback-retry-count"` + DefaultGlobalTransactionTimeout time.Duration `yaml:"default-global-transaction-timeout" json:"default-global-transaction-timeout,omitempty" koanf:"default-global-transaction-timeout"` + DegradeCheck bool `yaml:"degrade-check" json:"degrade-check" koanf:"degrade-check"` + DegradeCheckPeriod int `yaml:"degrade-check-period" json:"degrade-check-period" koanf:"degrade-check-period"` + DegradeCheckAllowTimes time.Duration `yaml:"degrade-check-allow-times" json:"degrade-check-allow-times" koanf:"degrade-check-allow-times"` + InterceptorOrder int `yaml:"interceptor-order" json:"interceptor-order" koanf:"interceptor-order"` } -func (cfg *TmConf) RegisterFlagsWithPrefix(prefix string, f *flag.FlagSet) { +func (cfg *TmConfig) RegisterFlagsWithPrefix(prefix string, f *flag.FlagSet) { f.IntVar(&cfg.CommitRetryCount, prefix+".commit-retry-count", 5, "The maximum number of retries when commit global transaction.") f.IntVar(&cfg.RollbackRetryCount, prefix+".rollback-retry-count", 5, "The maximum number of retries when rollback global transaction.") - f.DurationVar(&cfg.DefaultGlobalTransactionTimeout, prefix+".default-global-transaction-timeout", 10*time.Second, "The timeout for a global transaction.") + f.DurationVar(&cfg.DefaultGlobalTransactionTimeout, prefix+".default-global-transaction-timeout", 60*time.Second, "The timeout for a global transaction.") f.BoolVar(&cfg.DegradeCheck, prefix+".degrade-check", false, "The switch for degrade check.") f.IntVar(&cfg.DegradeCheckPeriod, prefix+".degrade-check-period", 2000, "The period for degrade checking.") f.DurationVar(&cfg.DegradeCheckAllowTimes, prefix+".degrade-check-allow-times", 10*time.Second, "The duration allowed for degrade checking.") diff --git a/testdata/conf/seatago.yml b/testdata/conf/seatago.yml index 1b29f28a9..92c46eab6 100644 --- a/testdata/conf/seatago.yml +++ b/testdata/conf/seatago.yml @@ -50,7 +50,7 @@ seata: tm: commit-retry-count: 5 rollback-retry-count: 5 - default-global-transaction-timeout: 10s + default-global-transaction-timeout: 60s degrade-check: false degrade-check-period: 2000 degrade-check-allow-times: 10s From bd2440c7154f25ced0b139821a5f20dc1316b7df Mon Sep 17 00:00:00 2001 From: liushao <505786909@qq.com> Date: Mon, 12 Dec 2022 09:17:25 +0800 Subject: [PATCH 7/8] refactor(pkg/client): Rename struct ClientConf to ClientConfig. --- pkg/client/config.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/client/config.go b/pkg/client/config.go index 4e72a5b28..f5aad74e6 100644 --- a/pkg/client/config.go +++ b/pkg/client/config.go @@ -49,11 +49,11 @@ const ( ymlSuffix = "yml" ) -type ClientConf struct { +type ClientConfig struct { TmConfig tm.TmConfig `yaml:"tm" json:"tm,omitempty" property:"tm" koanf:"tm"` } -func (c *ClientConf) RegisterFlagsWithPrefix(prefix string, f *flag.FlagSet) { +func (c *ClientConfig) RegisterFlagsWithPrefix(prefix string, f *flag.FlagSet) { // TODO: RmConf RegisterFlagsWithPrefix // TODO: Undo RegisterFlagsWithPrefix // TODO: LoadBalance RegisterFlagsWithPrefix @@ -61,8 +61,8 @@ func (c *ClientConf) RegisterFlagsWithPrefix(prefix string, f *flag.FlagSet) { } type Config struct { - TCCConfig tcc.Config `yaml:"tcc" json:"tcc" koanf:"tcc"` - ClientConfig ClientConf `yaml:"client" json:"client" koanf:"client"` + TCCConfig tcc.Config `yaml:"tcc" json:"tcc" koanf:"tcc"` + ClientConfig ClientConfig `yaml:"client" json:"client" koanf:"client"` } func (c *Config) RegisterFlags(f *flag.FlagSet) { From 8de613343d08e7be2aeb2b9791ab92ffb21fe84c Mon Sep 17 00:00:00 2001 From: liushao <505786909@qq.com> Date: Mon, 12 Dec 2022 17:33:35 +0800 Subject: [PATCH 8/8] refactor(pkg/client): remove property tag for ClientConfig --- pkg/client/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/client/config.go b/pkg/client/config.go index f5aad74e6..73e6e808a 100644 --- a/pkg/client/config.go +++ b/pkg/client/config.go @@ -50,7 +50,7 @@ const ( ) type ClientConfig struct { - TmConfig tm.TmConfig `yaml:"tm" json:"tm,omitempty" property:"tm" koanf:"tm"` + TmConfig tm.TmConfig `yaml:"tm" json:"tm,omitempty" koanf:"tm"` } func (c *ClientConfig) RegisterFlagsWithPrefix(prefix string, f *flag.FlagSet) {