Skip to content

Commit

Permalink
infoschema: add TiFlash to cluster_info table (pingcap#16684)
Browse files Browse the repository at this point in the history
  • Loading branch information
leiysky authored Apr 22, 2020
1 parent 0974ef2 commit 264e943
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
2 changes: 1 addition & 1 deletion infoschema/perfschema/tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ func dataForRemoteProfile(ctx sessionctx.Context, nodeType, uri string, isGorout
)
switch nodeType {
case "tikv":
servers, err = infoschema.GetTiKVServerInfo(ctx)
servers, err = infoschema.GetStoreServerInfo(ctx)
case "pd":
servers, err = infoschema.GetPDServerInfo(ctx)
default:
Expand Down
26 changes: 21 additions & 5 deletions infoschema/tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (

"github.com/pingcap/errors"
"github.com/pingcap/failpoint"
"github.com/pingcap/kvproto/pkg/metapb"
"github.com/pingcap/parser/charset"
"github.com/pingcap/parser/model"
"github.com/pingcap/parser/mysql"
Expand Down Expand Up @@ -1166,7 +1167,7 @@ func GetClusterServerInfo(ctx sessionctx.Context) ([]ServerInfo, error) {

type retriever func(ctx sessionctx.Context) ([]ServerInfo, error)
var servers []ServerInfo
for _, r := range []retriever{GetTiDBServerInfo, GetPDServerInfo, GetTiKVServerInfo} {
for _, r := range []retriever{GetTiDBServerInfo, GetPDServerInfo, GetStoreServerInfo} {
nodes, err := r(ctx)
if err != nil {
return nil, err
Expand Down Expand Up @@ -1287,13 +1288,23 @@ func GetPDServerInfo(ctx sessionctx.Context) ([]ServerInfo, error) {
return servers, nil
}

// GetTiKVServerInfo returns all TiKV nodes information of cluster
func GetTiKVServerInfo(ctx sessionctx.Context) ([]ServerInfo, error) {
// GetStoreServerInfo returns all store nodes(TiKV or TiFlash) cluster information
func GetStoreServerInfo(ctx sessionctx.Context) ([]ServerInfo, error) {
isTiFlashStore := func(store *metapb.Store) bool {
isTiFlash := false
for _, label := range store.Labels {
if label.GetKey() == "engine" && label.GetValue() == "tiflash" {
isTiFlash = true
}
}
return isTiFlash
}

store := ctx.GetStore()
// Get TiKV servers info.
tikvStore, ok := store.(tikv.Storage)
if !ok {
return nil, errors.Errorf("%T is not an TiKV store instance", store)
return nil, errors.Errorf("%T is not an TiKV or TiFlash store instance", store)
}
pdClient := tikvStore.GetRegionCache().PDClient()
if pdClient == nil {
Expand All @@ -1305,7 +1316,12 @@ func GetTiKVServerInfo(ctx sessionctx.Context) ([]ServerInfo, error) {
}
var servers []ServerInfo
for _, store := range stores {
tp := tikv.GetStoreTypeByMeta(store).Name()
var tp string
if isTiFlashStore(store) {
tp = "tiflash"
} else {
tp = tikv.GetStoreTypeByMeta(store).Name()
}
servers = append(servers, ServerInfo{
ServerType: tp,
Address: store.Address,
Expand Down

0 comments on commit 264e943

Please sign in to comment.