|
@ -19,14 +19,13 @@ import ( |
|
|
|
|
|
|
|
|
func (ms *MasterServer) SendHeartbeat(stream master_pb.Seaweed_SendHeartbeatServer) error { |
|
|
func (ms *MasterServer) SendHeartbeat(stream master_pb.Seaweed_SendHeartbeatServer) error { |
|
|
var dn *topology.DataNode |
|
|
var dn *topology.DataNode |
|
|
t := ms.Topo |
|
|
|
|
|
|
|
|
|
|
|
defer func() { |
|
|
defer func() { |
|
|
if dn != nil { |
|
|
if dn != nil { |
|
|
|
|
|
|
|
|
// if the volume server disconnects and reconnects quickly
|
|
|
// if the volume server disconnects and reconnects quickly
|
|
|
// the unregister and register can race with each other
|
|
|
// the unregister and register can race with each other
|
|
|
t.UnRegisterDataNode(dn) |
|
|
|
|
|
|
|
|
ms.Topo.UnRegisterDataNode(dn) |
|
|
glog.V(0).Infof("unregister disconnected volume server %s:%d", dn.Ip, dn.Port) |
|
|
glog.V(0).Infof("unregister disconnected volume server %s:%d", dn.Ip, dn.Port) |
|
|
|
|
|
|
|
|
message := &master_pb.VolumeLocation{ |
|
|
message := &master_pb.VolumeLocation{ |
|
@ -62,11 +61,11 @@ func (ms *MasterServer) SendHeartbeat(stream master_pb.Seaweed_SendHeartbeatServ |
|
|
return err |
|
|
return err |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
t.Sequence.SetMax(heartbeat.MaxFileKey) |
|
|
|
|
|
|
|
|
ms.Topo.Sequence.SetMax(heartbeat.MaxFileKey) |
|
|
|
|
|
|
|
|
if dn == nil { |
|
|
if dn == nil { |
|
|
dcName, rackName := t.Configuration.Locate(heartbeat.Ip, heartbeat.DataCenter, heartbeat.Rack) |
|
|
|
|
|
dc := t.GetOrCreateDataCenter(dcName) |
|
|
|
|
|
|
|
|
dcName, rackName := ms.Topo.Configuration.Locate(heartbeat.Ip, heartbeat.DataCenter, heartbeat.Rack) |
|
|
|
|
|
dc := ms.Topo.GetOrCreateDataCenter(dcName) |
|
|
rack := dc.GetOrCreateRack(rackName) |
|
|
rack := dc.GetOrCreateRack(rackName) |
|
|
dn = rack.GetOrCreateDataNode(heartbeat.Ip, |
|
|
dn = rack.GetOrCreateDataNode(heartbeat.Ip, |
|
|
int(heartbeat.Port), heartbeat.PublicUrl, |
|
|
int(heartbeat.Port), heartbeat.PublicUrl, |
|
@ -102,12 +101,12 @@ func (ms *MasterServer) SendHeartbeat(stream master_pb.Seaweed_SendHeartbeatServ |
|
|
message.DeletedVids = append(message.DeletedVids, volInfo.Id) |
|
|
message.DeletedVids = append(message.DeletedVids, volInfo.Id) |
|
|
} |
|
|
} |
|
|
// update master internal volume layouts
|
|
|
// update master internal volume layouts
|
|
|
t.IncrementalSyncDataNodeRegistration(heartbeat.NewVolumes, heartbeat.DeletedVolumes, dn) |
|
|
|
|
|
|
|
|
ms.Topo.IncrementalSyncDataNodeRegistration(heartbeat.NewVolumes, heartbeat.DeletedVolumes, dn) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if len(heartbeat.Volumes) > 0 || heartbeat.HasNoVolumes { |
|
|
if len(heartbeat.Volumes) > 0 || heartbeat.HasNoVolumes { |
|
|
// process heartbeat.Volumes
|
|
|
// process heartbeat.Volumes
|
|
|
newVolumes, deletedVolumes := t.SyncDataNodeRegistration(heartbeat.Volumes, dn) |
|
|
|
|
|
|
|
|
newVolumes, deletedVolumes := ms.Topo.SyncDataNodeRegistration(heartbeat.Volumes, dn) |
|
|
|
|
|
|
|
|
for _, v := range newVolumes { |
|
|
for _, v := range newVolumes { |
|
|
glog.V(0).Infof("master see new volume %d from %s", uint32(v.Id), dn.Url()) |
|
|
glog.V(0).Infof("master see new volume %d from %s", uint32(v.Id), dn.Url()) |
|
@ -122,7 +121,7 @@ func (ms *MasterServer) SendHeartbeat(stream master_pb.Seaweed_SendHeartbeatServ |
|
|
if len(heartbeat.NewEcShards) > 0 || len(heartbeat.DeletedEcShards) > 0 { |
|
|
if len(heartbeat.NewEcShards) > 0 || len(heartbeat.DeletedEcShards) > 0 { |
|
|
|
|
|
|
|
|
// update master internal volume layouts
|
|
|
// update master internal volume layouts
|
|
|
t.IncrementalSyncDataNodeEcShards(heartbeat.NewEcShards, heartbeat.DeletedEcShards, dn) |
|
|
|
|
|
|
|
|
ms.Topo.IncrementalSyncDataNodeEcShards(heartbeat.NewEcShards, heartbeat.DeletedEcShards, dn) |
|
|
|
|
|
|
|
|
for _, s := range heartbeat.NewEcShards { |
|
|
for _, s := range heartbeat.NewEcShards { |
|
|
message.NewVids = append(message.NewVids, s.Id) |
|
|
message.NewVids = append(message.NewVids, s.Id) |
|
@ -138,7 +137,7 @@ func (ms *MasterServer) SendHeartbeat(stream master_pb.Seaweed_SendHeartbeatServ |
|
|
|
|
|
|
|
|
if len(heartbeat.EcShards) > 0 || heartbeat.HasNoEcShards { |
|
|
if len(heartbeat.EcShards) > 0 || heartbeat.HasNoEcShards { |
|
|
glog.V(1).Infof("master recieved ec shards from %s: %+v", dn.Url(), heartbeat.EcShards) |
|
|
glog.V(1).Infof("master recieved ec shards from %s: %+v", dn.Url(), heartbeat.EcShards) |
|
|
newShards, deletedShards := t.SyncDataNodeEcShards(heartbeat.EcShards, dn) |
|
|
|
|
|
|
|
|
newShards, deletedShards := ms.Topo.SyncDataNodeEcShards(heartbeat.EcShards, dn) |
|
|
|
|
|
|
|
|
// broadcast the ec vid changes to master clients
|
|
|
// broadcast the ec vid changes to master clients
|
|
|
for _, s := range newShards { |
|
|
for _, s := range newShards { |
|
@ -163,7 +162,7 @@ func (ms *MasterServer) SendHeartbeat(stream master_pb.Seaweed_SendHeartbeatServ |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// tell the volume servers about the leader
|
|
|
// tell the volume servers about the leader
|
|
|
newLeader, err := t.Leader() |
|
|
|
|
|
|
|
|
newLeader, err := ms.Topo.Leader() |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
glog.Warningf("SendHeartbeat find leader: %v", err) |
|
|
glog.Warningf("SendHeartbeat find leader: %v", err) |
|
|
return err |
|
|
return err |
|
|