mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
reformat
This commit is contained in:
parent
ac793a3c5a
commit
5ccf8e8078
|
@ -43,55 +43,54 @@ func (ms *MasterServer) SendHeartbeat(stream master_pb.Seaweed_SendHeartbeatServ
|
||||||
|
|
||||||
for {
|
for {
|
||||||
heartbeat, err := stream.Recv()
|
heartbeat, err := stream.Recv()
|
||||||
if err == nil {
|
if err != nil {
|
||||||
if dn == nil {
|
return err
|
||||||
t.Sequence.SetMax(heartbeat.MaxFileKey)
|
}
|
||||||
if heartbeat.Ip == "" {
|
|
||||||
if pr, ok := peer.FromContext(stream.Context()); ok {
|
if dn == nil {
|
||||||
if pr.Addr != net.Addr(nil) {
|
t.Sequence.SetMax(heartbeat.MaxFileKey)
|
||||||
heartbeat.Ip = pr.Addr.String()[0:strings.LastIndex(pr.Addr.String(), ":")]
|
if heartbeat.Ip == "" {
|
||||||
glog.V(0).Infof("remote IP address is detected as %v", heartbeat.Ip)
|
if pr, ok := peer.FromContext(stream.Context()); ok {
|
||||||
}
|
if pr.Addr != net.Addr(nil) {
|
||||||
|
heartbeat.Ip = pr.Addr.String()[0:strings.LastIndex(pr.Addr.String(), ":")]
|
||||||
|
glog.V(0).Infof("remote IP address is detected as %v", heartbeat.Ip)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dcName, rackName := t.Configuration.Locate(heartbeat.Ip, heartbeat.DataCenter, heartbeat.Rack)
|
|
||||||
dc := t.GetOrCreateDataCenter(dcName)
|
|
||||||
rack := dc.GetOrCreateRack(rackName)
|
|
||||||
dn = rack.GetOrCreateDataNode(heartbeat.Ip,
|
|
||||||
int(heartbeat.Port), heartbeat.PublicUrl,
|
|
||||||
int(heartbeat.MaxVolumeCount))
|
|
||||||
glog.V(0).Infof("added volume server %v:%d", heartbeat.GetIp(), heartbeat.GetPort())
|
|
||||||
if err := stream.Send(&master_pb.HeartbeatResponse{
|
|
||||||
VolumeSizeLimit: uint64(ms.volumeSizeLimitMB) * 1024 * 1024,
|
|
||||||
SecretKey: string(ms.guard.SecretKey),
|
|
||||||
}); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
dcName, rackName := t.Configuration.Locate(heartbeat.Ip, heartbeat.DataCenter, heartbeat.Rack)
|
||||||
|
dc := t.GetOrCreateDataCenter(dcName)
|
||||||
|
rack := dc.GetOrCreateRack(rackName)
|
||||||
|
dn = rack.GetOrCreateDataNode(heartbeat.Ip,
|
||||||
|
int(heartbeat.Port), heartbeat.PublicUrl,
|
||||||
|
int(heartbeat.MaxVolumeCount))
|
||||||
|
glog.V(0).Infof("added volume server %v:%d", heartbeat.GetIp(), heartbeat.GetPort())
|
||||||
|
if err := stream.Send(&master_pb.HeartbeatResponse{
|
||||||
|
VolumeSizeLimit: uint64(ms.volumeSizeLimitMB) * 1024 * 1024,
|
||||||
|
SecretKey: string(ms.guard.SecretKey),
|
||||||
|
}); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
newVolumes, deletedVolumes := t.SyncDataNodeRegistration(heartbeat.Volumes, dn)
|
newVolumes, deletedVolumes := t.SyncDataNodeRegistration(heartbeat.Volumes, dn)
|
||||||
|
|
||||||
message := &master_pb.VolumeLocation{
|
message := &master_pb.VolumeLocation{
|
||||||
Url: dn.Url(),
|
Url: dn.Url(),
|
||||||
PublicUrl: dn.PublicUrl,
|
PublicUrl: dn.PublicUrl,
|
||||||
}
|
}
|
||||||
for _, v := range newVolumes {
|
for _, v := range newVolumes {
|
||||||
message.NewVids = append(message.NewVids, uint32(v.Id))
|
message.NewVids = append(message.NewVids, uint32(v.Id))
|
||||||
}
|
}
|
||||||
for _, v := range deletedVolumes {
|
for _, v := range deletedVolumes {
|
||||||
message.DeletedVids = append(message.DeletedVids, uint32(v.Id))
|
message.DeletedVids = append(message.DeletedVids, uint32(v.Id))
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(message.NewVids) > 0 || len(message.DeletedVids) > 0 {
|
if len(message.NewVids) > 0 || len(message.DeletedVids) > 0 {
|
||||||
ms.clientChansLock.RLock()
|
ms.clientChansLock.RLock()
|
||||||
for _, ch := range ms.clientChans {
|
for _, ch := range ms.clientChans {
|
||||||
ch <- message
|
ch <- message
|
||||||
}
|
|
||||||
ms.clientChansLock.RUnlock()
|
|
||||||
}
|
}
|
||||||
|
ms.clientChansLock.RUnlock()
|
||||||
} else {
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// tell the volume servers about the leader
|
// tell the volume servers about the leader
|
||||||
|
|
Loading…
Reference in a new issue