Skip to content

Commit

Permalink
api: add replication status to region (#2340)
Browse files Browse the repository at this point in the history
Signed-off-by: disksing <[email protected]>
  • Loading branch information
disksing authored Apr 10, 2020
1 parent 3dc7c63 commit c84d31b
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions server/api/region.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/gorilla/mux"
"github.com/pingcap/kvproto/pkg/metapb"
"github.com/pingcap/kvproto/pkg/pdpb"
"github.com/pingcap/kvproto/pkg/replication_modepb"
"github.com/pingcap/pd/v4/server"
"github.com/pingcap/pd/v4/server/core"
"github.com/unrolled/render"
Expand All @@ -44,6 +45,24 @@ type RegionInfo struct {
ReadKeys uint64 `json:"read_keys"`
ApproximateSize int64 `json:"approximate_size"`
ApproximateKeys int64 `json:"approximate_keys"`

ReplicationStatus *ReplicationStatus `json:"replication_status,omitempty"`
}

// ReplicationStatus represents the replication mode status of the region.
type ReplicationStatus struct {
State string `json:"state"`
StateID uint64 `json:"state_id"`
}

func fromPBReplicationStatus(s *replication_modepb.RegionReplicationStatus) *ReplicationStatus {
if s == nil {
return nil
}
return &ReplicationStatus{
State: replication_modepb.RegionReplicationState_name[int32(s.GetState())],
StateID: s.GetStateId(),
}
}

// NewRegionInfo create a new api RegionInfo.
Expand Down Expand Up @@ -71,6 +90,7 @@ func InitRegion(r *core.RegionInfo, s *RegionInfo) *RegionInfo {
s.ReadKeys = r.GetKeysRead()
s.ApproximateSize = r.GetApproximateSize()
s.ApproximateKeys = r.GetApproximateKeys()
s.ReplicationStatus = fromPBReplicationStatus(r.GetReplicationStatus())

return s
}
Expand Down

0 comments on commit c84d31b

Please sign in to comment.