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