Skip to content

Commit

Permalink
Merge pull request #6 from pingcap/master
Browse files Browse the repository at this point in the history
fix get hot store (tikv#1487)
  • Loading branch information
bradyjoestar authored Apr 1, 2019
2 parents 329082d + 56f4100 commit 9b6022d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion server/api/hot_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (h *hotStatusHandler) GetHotStores(w http.ResponseWriter, r *http.Request)
bytesWriteStats := h.GetHotBytesWriteStores()
bytesReadStats := h.GetHotBytesReadStores()
keysWriteStats := h.GetHotKeysWriteStores()
keysReadStats := h.GetHotKeysWriteStores()
keysReadStats := h.GetHotKeysReadStores()

stats := HotStoreStats{
BytesWriteStats: bytesWriteStats,
Expand Down
2 changes: 1 addition & 1 deletion server/schedule/mockcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ func (mc *MockCluster) UpdateStorageWrittenBytes(storeID uint64, bytesWritten ui
func (mc *MockCluster) UpdateStorageReadBytes(storeID uint64, bytesRead uint64) {
store := mc.GetStore(storeID)
newStats := proto.Clone(store.GetStoreStats()).(*pdpb.StoreStats)
newStats.BytesWritten = bytesRead
newStats.BytesRead = bytesRead
now := time.Now().Second()
interval := &pdpb.TimeInterval{StartTimestamp: uint64(now - storeHeartBeatReportInterval), EndTimestamp: uint64(now)}
newStats.Interval = interval
Expand Down
11 changes: 10 additions & 1 deletion tests/cmd/pdctl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1136,11 +1136,17 @@ func (s *cmdTestSuite) TestHot(c *C) {

ss, err := leaderServer.GetStore(1)
c.Assert(err, IsNil)
bytesWritten := uint64(8 * 1024 * 1024)
now := time.Now().Second()
interval := &pdpb.TimeInterval{StartTimestamp: uint64(now - 10), EndTimestamp: uint64(now)}
newStats := proto.Clone(ss.GetStoreStats()).(*pdpb.StoreStats)
bytesWritten := uint64(8 * 1024 * 1024)
bytesRead := uint64(16 * 1024 * 1024)
keysWritten := uint64(2000)
keysRead := uint64(4000)
newStats.BytesWritten = bytesWritten
newStats.BytesRead = bytesRead
newStats.KeysWritten = keysWritten
newStats.KeysRead = keysRead
newStats.Interval = interval
newStore := ss.Clone(core.SetStoreStats(newStats))
newStore.GetRollingStoreStats().Observe(newStore.GetStoreStats())
Expand All @@ -1163,6 +1169,9 @@ func (s *cmdTestSuite) TestHot(c *C) {
hotStores := api.HotStoreStats{}
c.Assert(json.Unmarshal(output, &hotStores), IsNil)
c.Assert(hotStores.BytesWriteStats[1], Equals, bytesWritten/10)
c.Assert(hotStores.BytesReadStats[1], Equals, bytesRead/10)
c.Assert(hotStores.KeysWriteStats[1], Equals, keysWritten/10)
c.Assert(hotStores.KeysReadStats[1], Equals, keysRead/10)
}

func initCommand() *cobra.Command {
Expand Down

0 comments on commit 9b6022d

Please sign in to comment.