Skip to content

Commit

Permalink
refactor: refactor the node stats (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
foreverneverer committed Dec 3, 2020
1 parent 72aa5c1 commit b582ad4
Show file tree
Hide file tree
Showing 28 changed files with 392 additions and 376 deletions.
1 change: 1 addition & 0 deletions check_and_format.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ if [ ! -f "${PROJECT_DIR}"/golangci-lint-1.29.0-linux-amd64/golangci-lint ]; the
fi

gofmt -l -w .
go mod tidy
golangci-lint-1.29.0-linux-amd64/golangci-lint run
4 changes: 2 additions & 2 deletions cmd/app_env.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
package cmd

import (
"github.com/pegasus-kv/admin-cli/executor"
"github.com/pegasus-kv/admin-cli/shell"
"fmt"

"github.com/desertbit/grumble"
"github.com/pegasus-kv/admin-cli/executor"
"github.com/pegasus-kv/admin-cli/shell"
)

// NOTE: some old-version servers may not support some of the keys.
Expand Down
4 changes: 2 additions & 2 deletions cmd/create_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
package cmd

import (
"github.com/pegasus-kv/admin-cli/executor"
"github.com/pegasus-kv/admin-cli/shell"
"fmt"

"github.com/desertbit/grumble"
"github.com/pegasus-kv/admin-cli/executor"
"github.com/pegasus-kv/admin-cli/shell"
)

func init() {
Expand Down
4 changes: 2 additions & 2 deletions cmd/drop_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
package cmd

import (
"github.com/pegasus-kv/admin-cli/executor"
"github.com/pegasus-kv/admin-cli/shell"
"fmt"

"github.com/desertbit/grumble"
"github.com/pegasus-kv/admin-cli/executor"
"github.com/pegasus-kv/admin-cli/shell"
)

func init() {
Expand Down
4 changes: 2 additions & 2 deletions cmd/duplication.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
package cmd

import (
"github.com/pegasus-kv/admin-cli/executor"
"github.com/pegasus-kv/admin-cli/shell"
"fmt"

"github.com/XiaoMi/pegasus-go-client/idl/admin"
"github.com/desertbit/grumble"
"github.com/pegasus-kv/admin-cli/executor"
"github.com/pegasus-kv/admin-cli/shell"
)

func init() {
Expand Down
2 changes: 1 addition & 1 deletion cmd/list_nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
package cmd

import (
"github.com/desertbit/grumble"
"github.com/pegasus-kv/admin-cli/executor"
"github.com/pegasus-kv/admin-cli/shell"
"github.com/desertbit/grumble"
)

func init() {
Expand Down
4 changes: 2 additions & 2 deletions cmd/meta_level.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
package cmd

import (
"github.com/pegasus-kv/admin-cli/executor"
"github.com/pegasus-kv/admin-cli/shell"
"fmt"

"github.com/desertbit/grumble"
"github.com/pegasus-kv/admin-cli/executor"
"github.com/pegasus-kv/admin-cli/shell"
)

var predefinedMetaLevel = []string{
Expand Down
2 changes: 1 addition & 1 deletion cmd/nodes_stat.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
package cmd

import (
"github.com/desertbit/grumble"
"github.com/pegasus-kv/admin-cli/executor"
"github.com/pegasus-kv/admin-cli/shell"
"github.com/desertbit/grumble"
)

func init() {
Expand Down
5 changes: 3 additions & 2 deletions cmd/recall_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@
package cmd

import (
"github.com/pegasus-kv/admin-cli/executor"
"github.com/pegasus-kv/admin-cli/shell"
"fmt"

"github.com/desertbit/grumble"
"github.com/pegasus-kv/admin-cli/executor"
"github.com/pegasus-kv/admin-cli/shell"
)

func init() {
Expand Down
4 changes: 2 additions & 2 deletions cmd/table_partition.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
package cmd

import (
"github.com/pegasus-kv/admin-cli/executor"
"github.com/pegasus-kv/admin-cli/shell"
"fmt"

"github.com/desertbit/grumble"
"github.com/pegasus-kv/admin-cli/executor"
"github.com/pegasus-kv/admin-cli/shell"
)

func init() {
Expand Down
2 changes: 1 addition & 1 deletion cmd/use.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
package cmd

import (
"github.com/pegasus-kv/admin-cli/shell"
"context"
"fmt"
"time"

"github.com/XiaoMi/pegasus-go-client/idl/admin"
"github.com/desertbit/grumble"
"github.com/pegasus-kv/admin-cli/shell"
)

var cachedTableNames []string
Expand Down
7 changes: 2 additions & 5 deletions executor/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
package executor

import (
"github.com/pegasus-kv/admin-cli/executor/util"
"context"
"fmt"
"io"
Expand All @@ -29,6 +28,7 @@ import (

"github.com/XiaoMi/pegasus-go-client/idl/admin"
"github.com/XiaoMi/pegasus-go-client/session"
"github.com/pegasus-kv/admin-cli/executor/util"
"github.com/pegasus-kv/collector/aggregate"
)

Expand Down Expand Up @@ -72,9 +72,6 @@ func NewClient(writer io.Writer, metaAddrs []string) *Client {
Writer: writer,
Meta: meta,
Nodes: util.NewPegasusNodeManager(metaAddrs, replicaAddrs),
Perf: aggregate.NewPerfClient(metaAddrs),
}
}

func (client *Client) GetPerfCounterClient(addr string) (*aggregate.PerfSession, error) {
return nil, nil
}
7 changes: 4 additions & 3 deletions executor/disk_balance.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,26 @@
package executor

import (
"github.com/pegasus-kv/admin-cli/helper"
"context"
"fmt"
"time"

"github.com/XiaoMi/pegasus-go-client/idl/radmin"
"github.com/XiaoMi/pegasus-go-client/session"
"github.com/pegasus-kv/admin-cli/executor/util"
)

func DiskMigrate(client *Client, replicaServer string, pidStr string, from string, to string) error {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
defer cancel()

var addr, err = helper.Resolve(replicaServer, helper.Host2Addr)
// TODO(jiashuo1) resolve need refactor
var addr, err = util.Resolve(replicaServer, util.Host2Addr)
if err == nil {
replicaServer = addr
}

pid, err := helper.Str2Gpid(pidStr)
pid, err := util.Str2Gpid(pidStr)
if err != nil {
return err
}
Expand Down
12 changes: 5 additions & 7 deletions executor/disk_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
package executor

import (
"github.com/pegasus-kv/admin-cli/helper"
"context"
"fmt"
"strconv"
Expand All @@ -30,6 +29,7 @@ import (
"github.com/XiaoMi/pegasus-go-client/idl/radmin"
"github.com/XiaoMi/pegasus-go-client/session"
"github.com/olekukonko/tablewriter"
"github.com/pegasus-kv/admin-cli/executor/util"
)

type DiskInfoType int32
Expand All @@ -40,11 +40,12 @@ const (
)

// QueryDiskInfo command
// TODO(jiashuo1) need refactor
func QueryDiskInfo(client *Client, infoType DiskInfoType, replicaServer string, tableName string, diskTag string) error {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
defer cancel()

var addr, err = helper.Resolve(replicaServer, helper.Host2Addr)
var addr, err = util.Resolve(replicaServer, util.Host2Addr)
if err == nil {
replicaServer = addr
}
Expand Down Expand Up @@ -92,10 +93,7 @@ func queryDiskCapacity(client *Client, replicaServer string, resp *radmin.QueryD
var nodeCapacityInfos []nodeCapacityStruct
var replicaCapacityInfos []replicaCapacityStruct

perfClient, err := client.GetPerfCounterClient(replicaServer)
if err != nil {
return err
}
perfSession := client.Nodes.GetPerfSession(replicaServer, session.NodeTypeReplica)

for _, diskInfo := range resp.DiskInfos {
// pass disk tag means query one disk detail capacity of replica
Expand All @@ -107,7 +105,7 @@ func queryDiskCapacity(client *Client, replicaServer string, resp *radmin.QueryD
replicaCapacityInfos = append(replicaCapacityInfos, replicaCapacityStruct{
Replica: gpidStr,
Status: replicaStatus,
Capacity: float64(helper.GetReplicaCounterValue(perfClient, "disk.storage.sst(MB)", gpidStr)),
Capacity: float64(util.GetPartitionStat(perfSession, "disk.storage.sst(MB)", gpidStr)),
})
}
}
Expand Down
2 changes: 1 addition & 1 deletion executor/list_nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ package executor
import (
"context"
"fmt"
"github.com/pegasus-kv/admin-cli/tabular"
"sort"
"strings"
"time"

"github.com/XiaoMi/pegasus-go-client/idl/admin"
"github.com/olekukonko/tablewriter"
"github.com/pegasus-kv/admin-cli/tabular"
)

type nodeInfoStruct struct {
Expand Down
2 changes: 1 addition & 1 deletion executor/list_tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/pegasus-kv/admin-cli/tabular"
"time"

"github.com/XiaoMi/pegasus-go-client/idl/admin"
"github.com/pegasus-kv/admin-cli/tabular"
)

// ListTables command.
Expand Down

0 comments on commit b582ad4

Please sign in to comment.