Skip to content

Commit

Permalink
config: set max token limit to 1M (pingcap#53361)
Browse files Browse the repository at this point in the history
  • Loading branch information
djshow832 authored and terry1purcell committed May 17, 2024
1 parent 987e0df commit 61809f8
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/config/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ go_test(
data = glob(["**"]),
embed = [":config"],
flaky = True,
shard_count = 24,
shard_count = 25,
deps = [
"//pkg/testkit/testsetup",
"//pkg/util/logutil",
Expand Down
4 changes: 4 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ const (
DefAuthTokenRefreshInterval = time.Hour
// EnvVarKeyspaceName is the system env name for keyspace name.
EnvVarKeyspaceName = "KEYSPACE_NAME"
// MaxTokenLimit is the max token limit value.
MaxTokenLimit = 1024 * 1024
)

// Valid config maps
Expand Down Expand Up @@ -1275,6 +1277,8 @@ func (c *Config) Load(confFile string) error {
}
if c.TokenLimit == 0 {
c.TokenLimit = 1000
} else if c.TokenLimit > MaxTokenLimit {
c.TokenLimit = MaxTokenLimit
}
// If any items in confFile file are not mapped into the Config struct, issue
// an error and stop the server from starting.
Expand Down
38 changes: 38 additions & 0 deletions pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1173,6 +1173,44 @@ func TestTableColumnCountLimit(t *testing.T) {
checkValid(DefMaxOfTableColumnCountLimit+1, false)
}

func TestTokenLimit(t *testing.T) {
storeDir := t.TempDir()
configFile := filepath.Join(storeDir, "config.toml")
f, err := os.Create(configFile)
require.NoError(t, err)
defer func(configFile string) {
require.NoError(t, os.Remove(configFile))
}(configFile)

tests := []struct {
tokenLimit uint
expectedTokenLimit uint
}{
{
0,
1000,
},
{
99999999999,
MaxTokenLimit,
},
}

for _, test := range tests {
require.NoError(t, f.Truncate(0))
_, err = f.Seek(0, 0)
require.NoError(t, err)
_, err = f.WriteString(fmt.Sprintf(`
token-limit = %d
`, test.tokenLimit))
require.NoError(t, err)
require.NoError(t, f.Sync())
conf := NewConfig()
require.NoError(t, conf.Load(configFile))
require.Equal(t, test.expectedTokenLimit, conf.TokenLimit)
}
}

func TestEncodeDefTempStorageDir(t *testing.T) {
tests := []struct {
host string
Expand Down

0 comments on commit 61809f8

Please sign in to comment.