Repository: pingcap/tidb (Go)

Issue:
LeaderScore & LeaderWeight should be float64 which defined in PD
## Bug Report

[tidb/infoschema/tables.go#L821](https://github.com/pingcap/tidb/blob/b0a6481e353c28398667f41b900362cf3b0a1fd9/infoschema/tables.go#L821)
```go
		row[9].SetInt64(storeStat.Status.LeaderWeight)
		row[10].SetInt64(storeStat.Status.LeaderScore)
```
[pd/server/api/store.go#L46](https://github.com/pingcap/pd/blob/f2487bff10a023027df54dc2ea43cd257338b2a8/server/api/store.go#L46)
```go
	LeaderWeight       float64            `json:"leader_weight,omitempty"`
	LeaderScore        float64            `json:"leader_score,omitempty"`
```

The RegionWeight and RegionScore has been fixed already by https://github.com/pingcap/tidb/pull/11969

Please answer these questions before submitting your issue. Thanks!

1. What did you do?
If possible, provide a recipe for reproducing the error.
$ pd-ctl -d -u $PD_ENDPOINT store weight 1 955747467.2354442 955747467.2354442

mysql> select STORE_ID, REGION_SCORE, REGION_WEIGHT from INFORMATION_SCHEMA.TIKV_STORE_STATUS
Error like this:
(1105, 'json: cannot unmarshal number 955747467.2354442 into Go struct field StoreDetailStat.leader_weight of type int64')

2. What did you expect to see?



3. What did you see instead?



4. What version of TiDB are you using (`tidb-server -V` or run `select tidb_version();` on TiDB)?




Discussion:

Patch:
diff --git a/infoschema/tables.go b/infoschema/tables.go
index 31b1c00cd450a..d27dfed3371ba 100644
--- a/infoschema/tables.go
+++ b/infoschema/tables.go
@@ -590,8 +590,8 @@ var tableTiKVStoreStatusCols = []columnInfo{
 	{"CAPACITY", mysql.TypeVarchar, 64, 0, nil, nil},
 	{"AVAILABLE", mysql.TypeVarchar, 64, 0, nil, nil},
 	{"LEADER_COUNT", mysql.TypeLonglong, 21, 0, nil, nil},
-	{"LEADER_WEIGHT", mysql.TypeLonglong, 21, 0, nil, nil},
-	{"LEADER_SCORE", mysql.TypeLonglong, 21, 0, nil, nil},
+	{"LEADER_WEIGHT", mysql.TypeDouble, 22, 0, nil, nil},
+	{"LEADER_SCORE", mysql.TypeDouble, 22, 0, nil, nil},
 	{"LEADER_SIZE", mysql.TypeLonglong, 21, 0, nil, nil},
 	{"REGION_COUNT", mysql.TypeLonglong, 21, 0, nil, nil},
 	{"REGION_WEIGHT", mysql.TypeDouble, 22, 0, nil, nil},
@@ -818,8 +818,8 @@ func dataForTiKVStoreStatus(ctx sessionctx.Context) (records [][]types.Datum, er
 		row[6].SetString(storeStat.Status.Capacity)
 		row[7].SetString(storeStat.Status.Available)
 		row[8].SetInt64(storeStat.Status.LeaderCount)
-		row[9].SetInt64(storeStat.Status.LeaderWeight)
-		row[10].SetInt64(storeStat.Status.LeaderScore)
+		row[9].SetFloat64(storeStat.Status.LeaderWeight)
+		row[10].SetFloat64(storeStat.Status.LeaderScore)
 		row[11].SetInt64(storeStat.Status.LeaderSize)
 		row[12].SetInt64(storeStat.Status.RegionCount)
 		row[13].SetFloat64(storeStat.Status.RegionWeight)
diff --git a/store/helper/helper.go b/store/helper/helper.go
index 2cceec180d52f..e0d25737a6d79 100644
--- a/store/helper/helper.go
+++ b/store/helper/helper.go
@@ -657,8 +657,8 @@ type StoreDetailStat struct {
 	Capacity        string    `json:"capacity"`
 	Available       string    `json:"available"`
 	LeaderCount     int64     `json:"leader_count"`
-	LeaderWeight    int64     `json:"leader_weight"`
-	LeaderScore     int64     `json:"leader_score"`
+	LeaderWeight    float64   `json:"leader_weight"`
+	LeaderScore     float64   `json:"leader_score"`
 	LeaderSize      int64     `json:"leader_size"`
 	RegionCount     int64     `json:"region_count"`
 	RegionWeight    float64   `json:"region_weight"`


Test patch:
diff --git a/store/helper/helper_test.go b/store/helper/helper_test.go
index 0163434ca14d2..0d23d2b6ede0c 100644
--- a/store/helper/helper_test.go
+++ b/store/helper/helper_test.go
@@ -121,7 +121,7 @@ func (s *HelperTestSuite) TestTiKVStoresStat(c *C) {
 	c.Assert(err, IsNil, Commentf("err: %+v", err))
 	data, err := json.Marshal(stat)
 	c.Assert(err, IsNil)
-	c.Assert(string(data), Equals, `{"count":1,"stores":[{"store":{"id":1,"address":"127.0.0.1:20160","state":0,"state_name":"Up","version":"3.0.0-beta","labels":[{"key":"test","value":"test"}]},"status":{"capacity":"60 GiB","available":"100 GiB","leader_count":10,"leader_weight":1,"leader_score":1000,"leader_size":1000,"region_count":200,"region_weight":1,"region_score":1000,"region_size":1000,"start_ts":"2019-04-23T19:30:30+08:00","last_heartbeat_ts":"2019-04-23T19:31:30+08:00","uptime":"1h30m"}}]}`)
+	c.Assert(string(data), Equals, `{"count":1,"stores":[{"store":{"id":1,"address":"127.0.0.1:20160","state":0,"state_name":"Up","version":"3.0.0-beta","labels":[{"key":"test","value":"test"}]},"status":{"capacity":"60 GiB","available":"100 GiB","leader_count":10,"leader_weight":999999.999999,"leader_score":999999.999999,"leader_size":1000,"region_count":200,"region_weight":999999.999999,"region_score":999999.999999,"region_size":1000,"start_ts":"2019-04-23T19:30:30+08:00","last_heartbeat_ts":"2019-04-23T19:31:30+08:00","uptime":"1h30m"}}]}`)
 }
 
 func (s *HelperTestSuite) mockPDHTTPServer(c *C) {
@@ -369,12 +369,12 @@ func (s *HelperTestSuite) mockStoreStatResponse(w http.ResponseWriter, req *http
 					Capacity:        "60 GiB",
 					Available:       "100 GiB",
 					LeaderCount:     10,
-					LeaderWeight:    1,
-					LeaderScore:     1000,
+					LeaderWeight:    999999.999999,
+					LeaderScore:     999999.999999,
 					LeaderSize:      1000,
 					RegionCount:     200,
-					RegionWeight:    1,
-					RegionScore:     1000,
+					RegionWeight:    999999.999999,
+					RegionScore:     999999.999999,
 					RegionSize:      1000,
 					StartTs:         startTs,
 					LastHeartbeatTs: lastHeartbeatTs,