Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

config: validate DeadlockHistoryCapacity config item #29127

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,14 @@ func DefaultPessimisticTxn() PessimisticTxn {
}
}

// Valid validates the configuration for PessimisticTxn config.
func (cfg *PessimisticTxn) Valid() error {
if cfg.DeadlockHistoryCapacity > 10000 {
return fmt.Errorf("pessimistic-txn.deadlock-history-capacity can not be larger than 10000")
}
return nil
}

// Plugin is the config for plugin
type Plugin struct {
Dir string `toml:"dir" json:"dir"`
Expand Down Expand Up @@ -900,6 +908,10 @@ func (c *Config) Valid() error {
return err
}

if err := c.PessimisticTxn.Valid(); err != nil {
return err
}

if c.Performance.TxnTotalSizeLimit > 1<<40 {
return fmt.Errorf("txn-total-size-limit should be less than %d", 1<<40)
}
Expand Down
19 changes: 19 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,25 @@ func TestOOMActionValid(t *testing.T) {
}
}

func TestPessimisticTxnValid(t *testing.T) {
t.Parallel()

c1 := NewConfig()
tests := []struct {
pessimisticTxn PessimisticTxn
valid bool
}{
{PessimisticTxn{DeadlockHistoryCapacity: 10}, true},
{PessimisticTxn{DeadlockHistoryCapacity: 0}, true},
{PessimisticTxn{DeadlockHistoryCapacity: 10000}, true},
{PessimisticTxn{DeadlockHistoryCapacity: 10001}, false},
}
for _, tt := range tests {
c1.PessimisticTxn = tt.pessimisticTxn
require.Equal(t, tt.valid, c1.Valid() == nil)
}
}

func TestTxnTotalSizeLimitValid(t *testing.T) {
t.Parallel()

Expand Down