From e8d4be579de16f334a13edd70afcbe95c60f6703 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Sat, 28 Jul 2018 01:17:35 -0700 Subject: [PATCH] send initial list of volume location --- weed/server/master_grpc_server.go | 6 ++++++ weed/topology/topology_map.go | 23 +++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/weed/server/master_grpc_server.go b/weed/server/master_grpc_server.go index c12938374..815bcfba3 100644 --- a/weed/server/master_grpc_server.go +++ b/weed/server/master_grpc_server.go @@ -143,6 +143,12 @@ func (ms *MasterServer) KeepConnected(stream master_pb.Seaweed_KeepConnectedServ ms.clientChansLock.Unlock() }() + for _, message := range ms.Topo.ToVolumeLocations() { + if err := stream.Send(message); err != nil { + return err + } + } + go func() { for { _, err := stream.Recv() diff --git a/weed/topology/topology_map.go b/weed/topology/topology_map.go index ce8e9e663..769ba0e2a 100644 --- a/weed/topology/topology_map.go +++ b/weed/topology/topology_map.go @@ -1,5 +1,7 @@ package topology +import "github.com/chrislusf/seaweedfs/weed/pb/master_pb" + func (t *Topology) ToMap() interface{} { m := make(map[string]interface{}) m["Max"] = t.GetMaxVolumeCount() @@ -51,3 +53,24 @@ func (t *Topology) ToVolumeMap() interface{} { m["DataCenters"] = dcs return m } + +func (t *Topology) ToVolumeLocations() (volumeLocations []*master_pb.VolumeLocation) { + for _, c := range t.Children() { + dc := c.(*DataCenter) + for _, r := range dc.Children() { + rack := r.(*Rack) + for _, d := range rack.Children() { + dn := d.(*DataNode) + volumeLocation := &master_pb.VolumeLocation{ + Url: dn.Url(), + PublicUrl: dn.PublicUrl, + } + for _, v := range dn.GetVolumes() { + volumeLocation.NewVids = append(volumeLocation.NewVids, uint32(v.Id)) + } + volumeLocations = append(volumeLocations, volumeLocation) + } + } + } + return +}