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: set max token limit to 1M #53361

Merged
merged 1 commit into from
May 17, 2024
Merged
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
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