|
@ -2,12 +2,16 @@ package weed_server |
|
|
|
|
|
|
|
|
import ( |
|
|
import ( |
|
|
"context" |
|
|
"context" |
|
|
|
|
|
"errors" |
|
|
|
|
|
"fmt" |
|
|
|
|
|
"net" |
|
|
|
|
|
"sort" |
|
|
|
|
|
"time" |
|
|
|
|
|
|
|
|
"github.com/chrislusf/seaweedfs/weed/pb" |
|
|
"github.com/chrislusf/seaweedfs/weed/pb" |
|
|
"github.com/chrislusf/seaweedfs/weed/stats" |
|
|
"github.com/chrislusf/seaweedfs/weed/stats" |
|
|
"github.com/chrislusf/seaweedfs/weed/storage/backend" |
|
|
"github.com/chrislusf/seaweedfs/weed/storage/backend" |
|
|
"github.com/chrislusf/seaweedfs/weed/util" |
|
|
"github.com/chrislusf/seaweedfs/weed/util" |
|
|
"net" |
|
|
|
|
|
"time" |
|
|
|
|
|
|
|
|
|
|
|
"github.com/chrislusf/raft" |
|
|
"github.com/chrislusf/raft" |
|
|
"google.golang.org/grpc/peer" |
|
|
"google.golang.org/grpc/peer" |
|
@ -18,6 +22,41 @@ import ( |
|
|
"github.com/chrislusf/seaweedfs/weed/topology" |
|
|
"github.com/chrislusf/seaweedfs/weed/topology" |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
func (ms *MasterServer) RegisterUuids(heartbeat *master_pb.Heartbeat) (duplicated_uuids []string, err error) { |
|
|
|
|
|
ms.Topo.UuidAccessLock.Lock() |
|
|
|
|
|
defer ms.Topo.UuidAccessLock.Unlock() |
|
|
|
|
|
key := fmt.Sprintf("%s:%d", heartbeat.Ip, heartbeat.Port) |
|
|
|
|
|
if ms.Topo.UuidMap == nil { |
|
|
|
|
|
ms.Topo.UuidMap = make(map[string][]string) |
|
|
|
|
|
} |
|
|
|
|
|
// find whether new uuid exists
|
|
|
|
|
|
for k, v := range ms.Topo.UuidMap { |
|
|
|
|
|
sort.Strings(v) |
|
|
|
|
|
for _, id := range heartbeat.LocationUuids { |
|
|
|
|
|
index := sort.SearchStrings(v, id) |
|
|
|
|
|
if index < len(v) && v[index] == id { |
|
|
|
|
|
duplicated_uuids = append(duplicated_uuids, id) |
|
|
|
|
|
glog.Errorf("directory of %s on %s has been loaded", id, k) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
if len(duplicated_uuids) > 0 { |
|
|
|
|
|
return duplicated_uuids, errors.New("volume: Duplicated volume directories were loaded") |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
ms.Topo.UuidMap[key] = heartbeat.LocationUuids |
|
|
|
|
|
glog.V(0).Infof("found new uuid:%v %v , %v", key, heartbeat.LocationUuids, ms.Topo.UuidMap) |
|
|
|
|
|
return nil, nil |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (ms *MasterServer) UnRegisterUuids(ip string, port int) { |
|
|
|
|
|
ms.Topo.UuidAccessLock.Lock() |
|
|
|
|
|
defer ms.Topo.UuidAccessLock.Unlock() |
|
|
|
|
|
key := fmt.Sprintf("%s:%d", ip, port) |
|
|
|
|
|
delete(ms.Topo.UuidMap, key) |
|
|
|
|
|
glog.V(0).Infof("remove volume server %v, online volume server: %v", key, ms.Topo.UuidMap) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
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 |
|
|
|
|
|
|
|
@ -32,6 +71,7 @@ func (ms *MasterServer) SendHeartbeat(stream master_pb.Seaweed_SendHeartbeatServ |
|
|
// the unregister and register can race with each other
|
|
|
// the unregister and register can race with each other
|
|
|
ms.Topo.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) |
|
|
|
|
|
ms.UnRegisterUuids(dn.Ip, dn.Port) |
|
|
|
|
|
|
|
|
message := &master_pb.VolumeLocation{ |
|
|
message := &master_pb.VolumeLocation{ |
|
|
Url: dn.Url(), |
|
|
Url: dn.Url(), |
|
@ -69,7 +109,18 @@ func (ms *MasterServer) SendHeartbeat(stream master_pb.Seaweed_SendHeartbeatServ |
|
|
dc := ms.Topo.GetOrCreateDataCenter(dcName) |
|
|
dc := ms.Topo.GetOrCreateDataCenter(dcName) |
|
|
rack := dc.GetOrCreateRack(rackName) |
|
|
rack := dc.GetOrCreateRack(rackName) |
|
|
dn = rack.GetOrCreateDataNode(heartbeat.Ip, int(heartbeat.Port), int(heartbeat.GrpcPort), heartbeat.PublicUrl, heartbeat.MaxVolumeCounts) |
|
|
dn = rack.GetOrCreateDataNode(heartbeat.Ip, int(heartbeat.Port), int(heartbeat.GrpcPort), heartbeat.PublicUrl, heartbeat.MaxVolumeCounts) |
|
|
glog.V(0).Infof("added volume server %d: %v:%d", dn.Counter, heartbeat.GetIp(), heartbeat.GetPort()) |
|
|
|
|
|
|
|
|
glog.V(0).Infof("added volume server %d: %v:%d %v", dn.Counter, heartbeat.GetIp(), heartbeat.GetPort(), heartbeat.LocationUuids) |
|
|
|
|
|
uuidlist, err := ms.RegisterUuids(heartbeat) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
if stream_err := stream.Send(&master_pb.HeartbeatResponse{ |
|
|
|
|
|
DuplicatedUuids: uuidlist, |
|
|
|
|
|
}); stream_err != nil { |
|
|
|
|
|
glog.Warningf("SendHeartbeat.Send DuplicatedDirectory response to %s:%d %v", dn.Ip, dn.Port, stream_err) |
|
|
|
|
|
return stream_err |
|
|
|
|
|
} |
|
|
|
|
|
return err |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
if err := stream.Send(&master_pb.HeartbeatResponse{ |
|
|
if err := stream.Send(&master_pb.HeartbeatResponse{ |
|
|
VolumeSizeLimit: uint64(ms.option.VolumeSizeLimitMB) * 1024 * 1024, |
|
|
VolumeSizeLimit: uint64(ms.option.VolumeSizeLimitMB) * 1024 * 1024, |
|
|
}); err != nil { |
|
|
}); err != nil { |
|
|