Skip to content

Commit

Permalink
json unmarshal will convert number to float64
Browse files Browse the repository at this point in the history
Signed-off-by: husharp <[email protected]>
  • Loading branch information
HuSharp committed Mar 26, 2024
1 parent 39108f7 commit 55f5d42
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
12 changes: 11 additions & 1 deletion server/config/persist_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -876,7 +876,17 @@ func (o *PersistOptions) getTTLUint(key string) (uint64, bool, error) {
return 0, false, nil
}
r, err := strconv.ParseUint(stringForm, 10, 64)
return r, true, err
if err == nil {
return r, true, nil
}
// try to parse float64
// json unmarshal will convert number(such as `uint64(math.MaxInt32)`) to float64
f, err := strconv.ParseFloat(stringForm, 64)
if err != nil {
println("parse float64 failed")
return 0, false, err
}
return uint64(f), true, nil
}

func (o *PersistOptions) getTTLUintOr(key string, defaultValue uint64) uint64 {
Expand Down
9 changes: 9 additions & 0 deletions tests/integrations/client/http_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,15 @@ func (suite *httpClientTestSuite) checkConfig(mode mode, client pd.Client) {
resp, err = env.cluster.GetEtcdClient().Get(env.ctx, sc.TTLConfigPrefix+"/schedule.leader-schedule-limit")
re.NoError(err)
re.Empty(resp.Kvs)

// Test the config with TTL for float64.
newConfig = map[string]any{
"schedule.max-pending-peer-count": uint64(math.MaxInt32),
}
err = client.SetConfig(env.ctx, newConfig, 4)
re.NoError(err)
c = env.cluster.GetLeaderServer().GetRaftCluster().GetOpts().GetMaxPendingPeerCount()
re.Equal(uint64(math.MaxInt32), c)
}

func (suite *httpClientTestSuite) TestScheduleConfig() {
Expand Down

0 comments on commit 55f5d42

Please sign in to comment.