Skip to content

Commit 9c4f3c5

Browse files
djshow832RidRisR
authored andcommitted
config: set max token limit to 1M (pingcap#53361)
close pingcap#53312
1 parent 8a1feed commit 9c4f3c5

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

pkg/config/BUILD.bazel

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ go_test(
3737
data = glob(["**"]),
3838
embed = [":config"],
3939
flaky = True,
40-
shard_count = 24,
40+
shard_count = 25,
4141
deps = [
4242
"//pkg/testkit/testsetup",
4343
"//pkg/util/logutil",

pkg/config/config.go

+4
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ const (
9797
DefAuthTokenRefreshInterval = time.Hour
9898
// EnvVarKeyspaceName is the system env name for keyspace name.
9999
EnvVarKeyspaceName = "KEYSPACE_NAME"
100+
// MaxTokenLimit is the max token limit value.
101+
MaxTokenLimit = 1024 * 1024
100102
)
101103

102104
// Valid config maps
@@ -1275,6 +1277,8 @@ func (c *Config) Load(confFile string) error {
12751277
}
12761278
if c.TokenLimit == 0 {
12771279
c.TokenLimit = 1000
1280+
} else if c.TokenLimit > MaxTokenLimit {
1281+
c.TokenLimit = MaxTokenLimit
12781282
}
12791283
// If any items in confFile file are not mapped into the Config struct, issue
12801284
// an error and stop the server from starting.

pkg/config/config_test.go

+38
Original file line numberDiff line numberDiff line change
@@ -1173,6 +1173,44 @@ func TestTableColumnCountLimit(t *testing.T) {
11731173
checkValid(DefMaxOfTableColumnCountLimit+1, false)
11741174
}
11751175

1176+
func TestTokenLimit(t *testing.T) {
1177+
storeDir := t.TempDir()
1178+
configFile := filepath.Join(storeDir, "config.toml")
1179+
f, err := os.Create(configFile)
1180+
require.NoError(t, err)
1181+
defer func(configFile string) {
1182+
require.NoError(t, os.Remove(configFile))
1183+
}(configFile)
1184+
1185+
tests := []struct {
1186+
tokenLimit uint
1187+
expectedTokenLimit uint
1188+
}{
1189+
{
1190+
0,
1191+
1000,
1192+
},
1193+
{
1194+
99999999999,
1195+
MaxTokenLimit,
1196+
},
1197+
}
1198+
1199+
for _, test := range tests {
1200+
require.NoError(t, f.Truncate(0))
1201+
_, err = f.Seek(0, 0)
1202+
require.NoError(t, err)
1203+
_, err = f.WriteString(fmt.Sprintf(`
1204+
token-limit = %d
1205+
`, test.tokenLimit))
1206+
require.NoError(t, err)
1207+
require.NoError(t, f.Sync())
1208+
conf := NewConfig()
1209+
require.NoError(t, conf.Load(configFile))
1210+
require.Equal(t, test.expectedTokenLimit, conf.TokenLimit)
1211+
}
1212+
}
1213+
11761214
func TestEncodeDefTempStorageDir(t *testing.T) {
11771215
tests := []struct {
11781216
host string

0 commit comments

Comments
 (0)