diff --git a/weed/server/master_grpc_server.go b/weed/server/master_grpc_server.go index afd479b21..be92d972d 100644 --- a/weed/server/master_grpc_server.go +++ b/weed/server/master_grpc_server.go @@ -22,7 +22,11 @@ func (ms *MasterServer) SendHeartbeat(stream master_pb.Seaweed_SendHeartbeatServ defer func() { if dn != nil { - + dn.Counter-- + if dn.Counter > 0 { + glog.V(0).Infof("disconnect phantom volume server %s:%d remaining %d", dn.Counter, dn.Ip, dn.Port) + return + } // if the volume server disconnects and reconnects quickly // the unregister and register can race with each other ms.Topo.UnRegisterDataNode(dn) @@ -68,6 +72,7 @@ func (ms *MasterServer) SendHeartbeat(stream master_pb.Seaweed_SendHeartbeatServ dc := ms.Topo.GetOrCreateDataCenter(dcName) rack := dc.GetOrCreateRack(rackName) dn = rack.GetOrCreateDataNode(heartbeat.Ip, int(heartbeat.Port), heartbeat.PublicUrl, heartbeat.MaxVolumeCounts) + dn.Counter++ glog.V(0).Infof("added volume server %v:%d", heartbeat.GetIp(), heartbeat.GetPort()) if err := stream.Send(&master_pb.HeartbeatResponse{ VolumeSizeLimit: uint64(ms.option.VolumeSizeLimitMB) * 1024 * 1024, diff --git a/weed/topology/data_node.go b/weed/topology/data_node.go index 2813f7b45..3f0234ca8 100644 --- a/weed/topology/data_node.go +++ b/weed/topology/data_node.go @@ -18,6 +18,7 @@ type DataNode struct { Port int PublicUrl string LastSeen int64 // unix time in seconds + Counter int // in race condition, the previous dataNode was not dead } func NewDataNode(id string) *DataNode {