Skip to content

Commit

Permalink
gossip: allow cluster info to be queried
Browse files Browse the repository at this point in the history
  • Loading branch information
lni committed May 30, 2022
1 parent e0e7708 commit c5cb120
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
18 changes: 18 additions & 0 deletions internal/registry/nodehost.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,21 @@ func (r *NodeHostRegistry) GetMeta(nhID string) ([]byte, bool) {
}
return m.Data, true
}

// GetClusterInfo returns the cluster info for the specified cluster if it is
// available in the gossip view.
func (r *NodeHostRegistry) GetClusterInfo(clusterID uint64) (ClusterInfo, bool) {
r.view.mu.Lock()
defer r.view.mu.Unlock()

ci, ok := r.view.mu.nodehosts[clusterID]
if !ok {
return ClusterInfo{}, false
}
result := ci
result.Nodes = make(map[uint64]string)
for clusterID, target := range ci.Nodes {
result.Nodes[clusterID] = target
}
return result, true
}
2 changes: 1 addition & 1 deletion internal/registry/view_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,6 @@ func TestGetGossipData(t *testing.T) {
v := newView(123)
cil := getTestClusterInfo()
v.update(cil)
data := v.getGossipData(320)
data := v.getGossipData(330)
assert.True(t, len(data) > 0)
}
1 change: 1 addition & 0 deletions registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ package dragonboat
type INodeHostRegistry interface {
NumOfClusters() int
GetMeta(nhID string) ([]byte, bool)
GetClusterInfo(clusterID uint64) (ClusterInfo, bool)
}

0 comments on commit c5cb120

Please sign in to comment.