Skip to content

Commit

Permalink
Improve ListNodes
Browse files Browse the repository at this point in the history
  • Loading branch information
kingster committed Jul 27, 2021
1 parent 4429f9c commit ef8792d
Show file tree
Hide file tree
Showing 8 changed files with 296 additions and 286 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ endif
protoc:
@echo ">> generating proto code using Proto version $(PROTO_VER)"
@$(GO) get -u github.com/golang/protobuf/protoc-gen-go@$(PROTO_VER)
@for proto_dir in $(PROTOBUFS); do echo $$proto_dir; protoc --proto_path=./ --go_out=Mpkg/serverpb/api.proto=github.com/flipkart-incubator/dkv/pkg/serverpb,plugins=grpc,paths=source_relative:. $$proto_dir/*.proto || exit 1; done
@for proto_dir in $(PROTOBUFS); do echo $$proto_dir; protoc --proto_path=./ -I`go list -f '{{ .Dir }}' -m github.com/flipkart-incubator/nexus`/ --go_out=M.,plugins=grpc,paths=source_relative:. $$proto_dir/*.proto || exit 1; done

.PHONY: format
format:
Expand Down
17 changes: 7 additions & 10 deletions cmd/dkvctl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,25 +171,22 @@ func (c *cmd) removeNode(client *ctl.DKVClient, args ...string) {
}

func (c *cmd) listNodes(client *ctl.DKVClient, args ...string) {
if leader, nodes, err := client.ListNodes(); err != nil {
if leaderId, members, err := client.ListNodes(); err != nil {
fmt.Printf("Unable to retrieve the nodes of DKV cluster. Error: %v\n", err)
} else {
var ids []uint64
for id := range nodes {
if id != leader {
ids = append(ids, id)
}
for id := range members {
ids = append(ids, id)
}
sort.Slice(ids, func(i, j int) bool { return ids[i] < ids[j] })
if leaderURL, present := nodes[leader]; present {
fmt.Println("Current DKV cluster members:")
fmt.Printf("%x => %s (leader)\n", leader, leaderURL)
if _, present := members[leaderId]; present {
fmt.Println("Current cluster members:")
} else {
fmt.Println("WARNING: DKV cluster unhealthy, leader unknown")
fmt.Println("WARNING: Cluster unhealthy, leader unknown")
fmt.Println("Current cluster members:")
}
for _, id := range ids {
fmt.Printf("%x => %s\n", id, nodes[id])
fmt.Printf("%x => %s (%s) \n", id, members[id].NodeUrl, members[id].Status)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/dgraph-io/ristretto v0.0.3 // indirect
github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13 // indirect
github.com/flipkart-incubator/gorocksdb v0.0.0-20210507064827-a2162cb9a3f7
github.com/flipkart-incubator/nexus v0.0.0-20210724094430-c2257fe5cd26
github.com/flipkart-incubator/nexus v0.0.0-20210727093243-32ce0a3d3391
github.com/gogo/protobuf v1.3.1
github.com/golang/protobuf v1.5.2
github.com/golang/snappy v0.0.2 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ github.com/flipkart-incubator/nexus v0.0.0-20210724085037-962edd55822f h1:qtVsSG
github.com/flipkart-incubator/nexus v0.0.0-20210724085037-962edd55822f/go.mod h1:p8YOMx5k0TYnOxPB04t0lY6COMRAa7CdEUYo6QIm1y4=
github.com/flipkart-incubator/nexus v0.0.0-20210724094430-c2257fe5cd26 h1:/vSvaVxkVttzVdb2rHhJ6tRlRBOy+W2Lgk9BbK9ga8c=
github.com/flipkart-incubator/nexus v0.0.0-20210724094430-c2257fe5cd26/go.mod h1:p8YOMx5k0TYnOxPB04t0lY6COMRAa7CdEUYo6QIm1y4=
github.com/flipkart-incubator/nexus v0.0.0-20210727093243-32ce0a3d3391 h1:kVUSmwuKO5/X7eQyH+5fmmrP/0ZjzEXHF0arQpnbYBE=
github.com/flipkart-incubator/nexus v0.0.0-20210727093243-32ce0a3d3391/go.mod h1:p8YOMx5k0TYnOxPB04t0lY6COMRAa7CdEUYo6QIm1y4=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
Expand Down
4 changes: 2 additions & 2 deletions internal/sync/raftpb/rpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion pkg/ctl/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package ctl
import (
"context"
"errors"
"github.com/flipkart-incubator/nexus/models"
"io"
"time"

Expand Down Expand Up @@ -189,7 +190,7 @@ func (dkvClnt *DKVClient) RemoveNode(nodeURL string) error {

// ListNodes retrieves the current members of the Nexus cluster
// along with identifying the leader.
func (dkvClnt *DKVClient) ListNodes() (uint64, map[uint64]string, error) {
func (dkvClnt *DKVClient) ListNodes() (uint64, map[uint64]*models.NodeInfo, error) {
ctx, cancel := context.WithTimeout(context.Background(), Timeout)
defer cancel()
res, err := dkvClnt.dkvClusCli.ListNodes(ctx, &empty.Empty{})
Expand Down
546 changes: 277 additions & 269 deletions pkg/serverpb/api.pb.go

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions pkg/serverpb/api.proto
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
syntax = "proto3";
import "google/protobuf/empty.proto";
import "models/internal.proto";

package dkv.serverpb;
option go_package = "serverpb";
option go_package = "github.com/flipkart-incubator/dkv/pkg/serverpb";

service DKV {
// Put puts the given key into the key value store.
Expand Down Expand Up @@ -246,7 +248,7 @@ message ListNodesResponse {
uint64 leader = 2;
// Nodes represents the members of the cluster identified by
// their respective identifier and the Nexus URL.
map<uint64, string> nodes = 3;
map<uint64, models.NodeInfo> nodes = 3;
}

message AddNodeRequest {
Expand Down

0 comments on commit ef8792d

Please sign in to comment.