mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
broadcast messages of new and deleted volumes
This commit is contained in:
parent
f82ac793b4
commit
a12c7b86b0
|
@ -3,11 +3,10 @@ package filer2
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/chrislusf/seaweedfs/weed/glog"
|
||||
"github.com/chrislusf/seaweedfs/weed/pb/master_pb"
|
||||
"github.com/chrislusf/seaweedfs/weed/util"
|
||||
"time"
|
||||
)
|
||||
|
||||
func (fs *Filer) GetMaster() string {
|
||||
|
@ -16,6 +15,13 @@ func (fs *Filer) GetMaster() string {
|
|||
|
||||
func (fs *Filer) KeepConnectedToMaster() {
|
||||
glog.V(0).Infof("Filer bootstraps with masters %v", fs.masters)
|
||||
for {
|
||||
fs.tryAllMasters()
|
||||
time.Sleep(time.Second)
|
||||
}
|
||||
}
|
||||
|
||||
func (fs *Filer) tryAllMasters() {
|
||||
for _, master := range fs.masters {
|
||||
glog.V(0).Infof("Connecting to %v", master)
|
||||
withMasterClient(master, func(client master_pb.SeaweedClient) error {
|
||||
|
@ -28,17 +34,17 @@ func (fs *Filer) KeepConnectedToMaster() {
|
|||
glog.V(0).Infof("Connected to %v", master)
|
||||
fs.currentMaster = master
|
||||
|
||||
for {
|
||||
time.Sleep(time.Duration(float32(10*1e3)*0.25) * time.Millisecond)
|
||||
|
||||
if err = stream.Send(&master_pb.Empty{}); err != nil {
|
||||
if err = stream.Send(&master_pb.ClientListenRequest{Name: "filer"}); err != nil {
|
||||
glog.V(0).Infof("failed to send to %s: %v", master, err)
|
||||
return err
|
||||
}
|
||||
|
||||
if _, err = stream.Recv(); err != nil {
|
||||
for {
|
||||
if volumeLocation, err := stream.Recv(); err != nil {
|
||||
glog.V(0).Infof("failed to receive from %s: %v", master, err)
|
||||
return err
|
||||
} else {
|
||||
glog.V(0).Infof("volume location: %+v", volumeLocation)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
|
@ -14,6 +14,8 @@ It has these top-level messages:
|
|||
VolumeInformationMessage
|
||||
Empty
|
||||
SuperBlockExtra
|
||||
ClientListenRequest
|
||||
VolumeLocation
|
||||
*/
|
||||
package master_pb
|
||||
|
||||
|
@ -295,6 +297,62 @@ func (m *SuperBlockExtra_ErasureCoding) GetVolumeIds() []uint32 {
|
|||
return nil
|
||||
}
|
||||
|
||||
type ClientListenRequest struct {
|
||||
Name string `protobuf:"bytes,1,opt,name=name" json:"name,omitempty"`
|
||||
}
|
||||
|
||||
func (m *ClientListenRequest) Reset() { *m = ClientListenRequest{} }
|
||||
func (m *ClientListenRequest) String() string { return proto.CompactTextString(m) }
|
||||
func (*ClientListenRequest) ProtoMessage() {}
|
||||
func (*ClientListenRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{5} }
|
||||
|
||||
func (m *ClientListenRequest) GetName() string {
|
||||
if m != nil {
|
||||
return m.Name
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
type VolumeLocation struct {
|
||||
Url string `protobuf:"bytes,1,opt,name=url" json:"url,omitempty"`
|
||||
PublicUrl string `protobuf:"bytes,2,opt,name=public_url,json=publicUrl" json:"public_url,omitempty"`
|
||||
NewVids []uint32 `protobuf:"varint,3,rep,packed,name=new_vids,json=newVids" json:"new_vids,omitempty"`
|
||||
DeletedVids []uint32 `protobuf:"varint,4,rep,packed,name=deleted_vids,json=deletedVids" json:"deleted_vids,omitempty"`
|
||||
}
|
||||
|
||||
func (m *VolumeLocation) Reset() { *m = VolumeLocation{} }
|
||||
func (m *VolumeLocation) String() string { return proto.CompactTextString(m) }
|
||||
func (*VolumeLocation) ProtoMessage() {}
|
||||
func (*VolumeLocation) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{6} }
|
||||
|
||||
func (m *VolumeLocation) GetUrl() string {
|
||||
if m != nil {
|
||||
return m.Url
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (m *VolumeLocation) GetPublicUrl() string {
|
||||
if m != nil {
|
||||
return m.PublicUrl
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (m *VolumeLocation) GetNewVids() []uint32 {
|
||||
if m != nil {
|
||||
return m.NewVids
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *VolumeLocation) GetDeletedVids() []uint32 {
|
||||
if m != nil {
|
||||
return m.DeletedVids
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func init() {
|
||||
proto.RegisterType((*Heartbeat)(nil), "master_pb.Heartbeat")
|
||||
proto.RegisterType((*HeartbeatResponse)(nil), "master_pb.HeartbeatResponse")
|
||||
|
@ -302,6 +360,8 @@ func init() {
|
|||
proto.RegisterType((*Empty)(nil), "master_pb.Empty")
|
||||
proto.RegisterType((*SuperBlockExtra)(nil), "master_pb.SuperBlockExtra")
|
||||
proto.RegisterType((*SuperBlockExtra_ErasureCoding)(nil), "master_pb.SuperBlockExtra.ErasureCoding")
|
||||
proto.RegisterType((*ClientListenRequest)(nil), "master_pb.ClientListenRequest")
|
||||
proto.RegisterType((*VolumeLocation)(nil), "master_pb.VolumeLocation")
|
||||
}
|
||||
|
||||
// Reference imports to suppress errors if they are not otherwise used.
|
||||
|
@ -368,8 +428,8 @@ func (c *seaweedClient) KeepConnected(ctx context.Context, opts ...grpc.CallOpti
|
|||
}
|
||||
|
||||
type Seaweed_KeepConnectedClient interface {
|
||||
Send(*Empty) error
|
||||
Recv() (*Empty, error)
|
||||
Send(*ClientListenRequest) error
|
||||
Recv() (*VolumeLocation, error)
|
||||
grpc.ClientStream
|
||||
}
|
||||
|
||||
|
@ -377,12 +437,12 @@ type seaweedKeepConnectedClient struct {
|
|||
grpc.ClientStream
|
||||
}
|
||||
|
||||
func (x *seaweedKeepConnectedClient) Send(m *Empty) error {
|
||||
func (x *seaweedKeepConnectedClient) Send(m *ClientListenRequest) error {
|
||||
return x.ClientStream.SendMsg(m)
|
||||
}
|
||||
|
||||
func (x *seaweedKeepConnectedClient) Recv() (*Empty, error) {
|
||||
m := new(Empty)
|
||||
func (x *seaweedKeepConnectedClient) Recv() (*VolumeLocation, error) {
|
||||
m := new(VolumeLocation)
|
||||
if err := x.ClientStream.RecvMsg(m); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -431,8 +491,8 @@ func _Seaweed_KeepConnected_Handler(srv interface{}, stream grpc.ServerStream) e
|
|||
}
|
||||
|
||||
type Seaweed_KeepConnectedServer interface {
|
||||
Send(*Empty) error
|
||||
Recv() (*Empty, error)
|
||||
Send(*VolumeLocation) error
|
||||
Recv() (*ClientListenRequest, error)
|
||||
grpc.ServerStream
|
||||
}
|
||||
|
||||
|
@ -440,12 +500,12 @@ type seaweedKeepConnectedServer struct {
|
|||
grpc.ServerStream
|
||||
}
|
||||
|
||||
func (x *seaweedKeepConnectedServer) Send(m *Empty) error {
|
||||
func (x *seaweedKeepConnectedServer) Send(m *VolumeLocation) error {
|
||||
return x.ServerStream.SendMsg(m)
|
||||
}
|
||||
|
||||
func (x *seaweedKeepConnectedServer) Recv() (*Empty, error) {
|
||||
m := new(Empty)
|
||||
func (x *seaweedKeepConnectedServer) Recv() (*ClientListenRequest, error) {
|
||||
m := new(ClientListenRequest)
|
||||
if err := x.ServerStream.RecvMsg(m); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -476,45 +536,50 @@ var _Seaweed_serviceDesc = grpc.ServiceDesc{
|
|||
func init() { proto.RegisterFile("seaweed.proto", fileDescriptor0) }
|
||||
|
||||
var fileDescriptor0 = []byte{
|
||||
// 627 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0x74, 0x94, 0xcf, 0x6e, 0xd3, 0x40,
|
||||
0x10, 0xc6, 0x71, 0x92, 0x26, 0xf5, 0xa4, 0x6e, 0xd3, 0x15, 0x42, 0x56, 0x29, 0x10, 0xc2, 0xc5,
|
||||
0x12, 0x28, 0x42, 0xe5, 0xc4, 0x81, 0x4b, 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,
|
||||
0xa4, 0xd9, 0x29, 0x04, 0x73, 0xcc, 0xc5, 0xdd, 0x23, 0x7e, 0xb8, 0xb1, 0xf1, 0x9a, 0x1e, 0x1c,
|
||||
0xfe, 0x8b, 0xb6, 0x37, 0x78, 0xf2, 0x20, 0xf2, 0x5e, 0x7b, 0xec, 0x2d, 0x04, 0x67, 0x88, 0xe5,
|
||||
0xac, 0xc8, 0x73, 0x4c, 0x2d, 0x0a, 0x36, 0xda, 0x18, 0x22, 0xe9, 0x0e, 0xfe, 0x22, 0xf5, 0xe8,
|
||||
0xa2, 0x4f, 0xff, 0x2c, 0x6f, 0x7e, 0x07, 0x00, 0x00, 0xff, 0xff, 0x73, 0x2b, 0x68, 0x15, 0x6a,
|
||||
0x04, 0x00, 0x00,
|
||||
// 708 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0x74, 0x54, 0x41, 0x6f, 0xf3, 0x44,
|
||||
0x10, 0xc5, 0x49, 0xbe, 0x24, 0x9e, 0x7c, 0xc9, 0x97, 0x2e, 0x08, 0xb9, 0xa5, 0x94, 0x60, 0x2e,
|
||||
0x46, 0xa0, 0x08, 0x95, 0x33, 0x97, 0x46, 0x45, 0x54, 0x2d, 0x6a, 0xe5, 0x88, 0x1e, 0xb8, 0x58,
|
||||
0x1b, 0xef, 0xb4, 0x5a, 0x75, 0xbd, 0x36, 0xbb, 0x9b, 0x36, 0xee, 0x85, 0x7f, 0xc3, 0x8d, 0xbf,
|
||||
0xc0, 0x89, 0x1f, 0x86, 0x76, 0xd7, 0x4e, 0x42, 0x28, 0xb7, 0xd9, 0x37, 0x6f, 0xbc, 0xe3, 0xf7,
|
||||
0x66, 0x16, 0xc6, 0x1a, 0xe9, 0x0b, 0x22, 0x9b, 0x57, 0xaa, 0x34, 0x25, 0x09, 0x0b, 0xaa, 0x0d,
|
||||
0xaa, 0xac, 0x5a, 0xc5, 0x7f, 0x76,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, 0x35, 0xb1, 0x86, 0xa3, 0xad, 0x5c, 0x29, 0xea, 0xaa, 0x94, 0x1a,
|
||||
0x49, 0x02, 0x1f, 0x7c, 0x7e, 0xc9, 0x5f, 0xf1, 0x86, 0x17, 0xdc, 0x38, 0x0d, 0x7b, 0xe9, 0x21,
|
||||
0x4c, 0x4e, 0x21, 0xd4, 0x98, 0x2b, 0x34, 0xd7, 0x58, 0x3b, 0x55, 0xc3, 0x74, 0x07, 0x90, 0x4f,
|
||||
0xa1, 0x2f, 0x90, 0x32, 0x54, 0x8d, 0xac, 0xcd, 0x29, 0xfe, 0xbb, 0x03, 0xd1, 0xff, 0xb5, 0xe6,
|
||||
0x3c, 0x63, 0xee, 0xbe, 0x71, 0xda, 0xe1, 0xcc, 0x6a, 0xa2, 0xf9, 0x2b, 0xba, 0xaf, 0xf7, 0x52,
|
||||
0x17, 0x93, 0x33, 0x80, 0xbc, 0x14, 0x02, 0x73, 0x5b, 0xd8, 0x7c, 0x7c, 0x0f, 0xb1, 0x9a, 0x39,
|
||||
0x1b, 0x76, 0x76, 0xf5, 0xd2, 0xd0, 0x22, 0xde, 0xa9, 0x2f, 0xe1, 0x3d, 0x43, 0x81, 0xa6, 0x25,
|
||||
0x78, 0xa7, 0x46, 0x1e, 0xf3, 0x94, 0x6f, 0x81, 0xf8, 0x23, 0xcb, 0x56, 0xf5, 0x96, 0xd8, 0x77,
|
||||
0xc4, 0x69, 0x93, 0xb9, 0xa8, 0x5b, 0xf6, 0x67, 0x10, 0x2a, 0xa4, 0x2c, 0x2b, 0xa5, 0xa8, 0x9d,
|
||||
0x79, 0xc3, 0x74, 0x68, 0x81, 0x5b, 0x29, 0x6a, 0xf2, 0x0d, 0x1c, 0x29, 0xac, 0x04, 0xcf, 0x69,
|
||||
0x56, 0x09, 0x9a, 0x63, 0x81, 0xb2, 0xf5, 0x71, 0xda, 0x24, 0xee, 0x5a, 0x9c, 0x44, 0x30, 0x78,
|
||||
0x46, 0xa5, 0xed, 0x6f,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0x93, 0xc1, 0x2c, 0xe5, 0xfc, 0x8f, 0x00, 0x06, 0x4b, 0xff, 0xfc, 0x90, 0x2b, 0x18,
|
||||
0x2f, 0x51, 0xb2, 0xdd, 0x83, 0xf3, 0xc9, 0x9e, 0xba, 0x5b, 0xf4, 0xe4, 0xf4, 0x2d, 0xb4, 0xdd,
|
||||
0xb6, 0xf8, 0xa3, 0x24, 0xf8, 0x2e, 0x20, 0x77, 0x30, 0xbe, 0x46, 0xac, 0x16, 0xa5, 0x94, 0x98,
|
||||
0x1b, 0x64, 0xe4, 0x6c, 0xaf, 0xe8, 0x0d, 0x71, 0x4e, 0x8e, 0xff, 0xb3, 0xe7, 0xad, 0x22, 0xfe,
|
||||
0x8b, 0xab, 0xbe, 0x7b, 0x1c, 0xbf, 0xff, 0x27, 0x00, 0x00, 0xff, 0xff, 0xfd, 0x83, 0xd9, 0x6b,
|
||||
0x2d, 0x05, 0x00, 0x00,
|
||||
}
|
||||
|
|
|
@ -7,9 +7,7 @@ package master_pb;
|
|||
service Seaweed {
|
||||
rpc SendHeartbeat (stream Heartbeat) returns (stream HeartbeatResponse) {
|
||||
}
|
||||
rpc KeepConnected (stream Empty) returns (stream Empty) {
|
||||
}
|
||||
rpc ListenForTopoChange (stream Empty) returns (stream VolumeLocation) {
|
||||
rpc KeepConnected (stream ClientListenRequest) returns (stream VolumeLocation) {
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -58,8 +56,13 @@ message SuperBlockExtra {
|
|||
ErasureCoding erasure_coding = 1;
|
||||
}
|
||||
|
||||
message ClientListenRequest {
|
||||
string name = 1;
|
||||
}
|
||||
|
||||
message VolumeLocation {
|
||||
string url = 1;
|
||||
string public_url = 2;
|
||||
repeated uint32 vid = 3;
|
||||
repeated uint32 new_vids = 3;
|
||||
repeated uint32 deleted_vids = 4;
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import (
|
|||
"github.com/chrislusf/seaweedfs/weed/pb/master_pb"
|
||||
"github.com/chrislusf/seaweedfs/weed/topology"
|
||||
"google.golang.org/grpc/peer"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func (ms *MasterServer) SendHeartbeat(stream master_pb.Seaweed_SendHeartbeatServer) error {
|
||||
|
@ -16,8 +17,26 @@ func (ms *MasterServer) SendHeartbeat(stream master_pb.Seaweed_SendHeartbeatServ
|
|||
|
||||
defer func() {
|
||||
if dn != nil {
|
||||
|
||||
glog.V(0).Infof("unregister disconnected volume server %s:%d", dn.Ip, dn.Port)
|
||||
t.UnRegisterDataNode(dn)
|
||||
|
||||
message := &master_pb.VolumeLocation{
|
||||
Url: dn.Url(),
|
||||
PublicUrl: dn.PublicUrl,
|
||||
}
|
||||
for _, v := range dn.GetVolumes() {
|
||||
message.DeletedVids = append(message.DeletedVids, uint32(v.Id))
|
||||
}
|
||||
|
||||
if len(message.DeletedVids) > 0 {
|
||||
ms.clientChansLock.RLock()
|
||||
for _, ch := range ms.clientChans {
|
||||
ch <- message
|
||||
}
|
||||
ms.clientChansLock.RUnlock()
|
||||
}
|
||||
|
||||
}
|
||||
}()
|
||||
|
||||
|
@ -49,7 +68,26 @@ func (ms *MasterServer) SendHeartbeat(stream master_pb.Seaweed_SendHeartbeatServ
|
|||
}
|
||||
}
|
||||
|
||||
t.SyncDataNodeRegistration(heartbeat.Volumes, dn)
|
||||
newVolumes, deletedVolumes := t.SyncDataNodeRegistration(heartbeat.Volumes, dn)
|
||||
|
||||
message := &master_pb.VolumeLocation{
|
||||
Url: dn.Url(),
|
||||
PublicUrl: dn.PublicUrl,
|
||||
}
|
||||
for _, v := range newVolumes {
|
||||
message.NewVids = append(message.NewVids, uint32(v.Id))
|
||||
}
|
||||
for _, v := range deletedVolumes {
|
||||
message.DeletedVids = append(message.DeletedVids, uint32(v.Id))
|
||||
}
|
||||
|
||||
if len(message.NewVids) > 0 || len(message.DeletedVids) > 0 {
|
||||
ms.clientChansLock.RLock()
|
||||
for _, ch := range ms.clientChans {
|
||||
ch <- message
|
||||
}
|
||||
ms.clientChansLock.RUnlock()
|
||||
}
|
||||
|
||||
} else {
|
||||
return err
|
||||
|
@ -69,13 +107,63 @@ func (ms *MasterServer) SendHeartbeat(stream master_pb.Seaweed_SendHeartbeatServ
|
|||
|
||||
// KeepConnected keep a stream gRPC call to the master. Used by filer to know the master is up.
|
||||
func (ms *MasterServer) KeepConnected(stream master_pb.Seaweed_KeepConnectedServer) error {
|
||||
for {
|
||||
_, err := stream.Recv()
|
||||
|
||||
req, err := stream.Recv()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := stream.Send(&master_pb.Empty{}); err != nil {
|
||||
|
||||
// remember client address
|
||||
ctx := stream.Context()
|
||||
// fmt.Printf("FromContext %+v\n", ctx)
|
||||
pr, ok := peer.FromContext(ctx)
|
||||
if !ok {
|
||||
glog.Error("failed to get peer from ctx")
|
||||
return fmt.Errorf("failed to get peer from ctx")
|
||||
}
|
||||
if pr.Addr == net.Addr(nil) {
|
||||
glog.Error("failed to get peer address")
|
||||
return fmt.Errorf("failed to get peer address")
|
||||
}
|
||||
|
||||
clientName := req.Name + pr.Addr.String()
|
||||
glog.V(0).Infof("+ client %v", clientName)
|
||||
|
||||
messageChan := make(chan *master_pb.VolumeLocation)
|
||||
stopChan := make(chan bool)
|
||||
|
||||
ms.clientChansLock.Lock()
|
||||
ms.clientChans[clientName] = messageChan
|
||||
ms.clientChansLock.Unlock()
|
||||
|
||||
defer func() {
|
||||
glog.V(0).Infof("- client %v", clientName)
|
||||
ms.clientChansLock.Lock()
|
||||
delete(ms.clientChans, clientName)
|
||||
ms.clientChansLock.Unlock()
|
||||
}()
|
||||
|
||||
go func() {
|
||||
for {
|
||||
_, err := stream.Recv()
|
||||
if err != nil {
|
||||
glog.V(2).Infof("- client %v: %v", clientName, err)
|
||||
stopChan <- true
|
||||
break
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
for {
|
||||
select {
|
||||
case message := <-messageChan:
|
||||
if err := stream.Send(message); err != nil {
|
||||
return err
|
||||
}
|
||||
case <-stopChan:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ import (
|
|||
"github.com/chrislusf/seaweedfs/weed/topology"
|
||||
"github.com/chrislusf/seaweedfs/weed/util"
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/chrislusf/seaweedfs/weed/pb/master_pb"
|
||||
)
|
||||
|
||||
type MasterServer struct {
|
||||
|
@ -31,6 +32,10 @@ type MasterServer struct {
|
|||
vgLock sync.Mutex
|
||||
|
||||
bounedLeaderChan chan int
|
||||
|
||||
// notifying clients
|
||||
clientChansLock sync.RWMutex
|
||||
clientChans map[string]chan *master_pb.VolumeLocation
|
||||
}
|
||||
|
||||
func NewMasterServer(r *mux.Router, port int, metaFolder string,
|
||||
|
@ -54,6 +59,7 @@ func NewMasterServer(r *mux.Router, port int, metaFolder string,
|
|||
pulseSeconds: pulseSeconds,
|
||||
defaultReplicaPlacement: defaultReplicaPlacement,
|
||||
garbageThreshold: garbageThreshold,
|
||||
clientChans: make(map[string]chan *master_pb.VolumeLocation),
|
||||
}
|
||||
ms.bounedLeaderChan = make(chan int, 16)
|
||||
seq := sequence.NewMemorySequencer()
|
||||
|
|
|
@ -32,7 +32,7 @@ func (dn *DataNode) String() string {
|
|||
return fmt.Sprintf("Node:%s, volumes:%v, Ip:%s, Port:%d, PublicUrl:%s", dn.NodeImpl.String(), dn.volumes, dn.Ip, dn.Port, dn.PublicUrl)
|
||||
}
|
||||
|
||||
func (dn *DataNode) AddOrUpdateVolume(v storage.VolumeInfo) {
|
||||
func (dn *DataNode) AddOrUpdateVolume(v storage.VolumeInfo) (isNew bool) {
|
||||
dn.Lock()
|
||||
defer dn.Unlock()
|
||||
if _, ok := dn.volumes[v.Id]; !ok {
|
||||
|
@ -42,12 +42,14 @@ func (dn *DataNode) AddOrUpdateVolume(v storage.VolumeInfo) {
|
|||
dn.UpAdjustActiveVolumeCountDelta(1)
|
||||
}
|
||||
dn.UpAdjustMaxVolumeId(v.Id)
|
||||
isNew = true
|
||||
} else {
|
||||
dn.volumes[v.Id] = v
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (dn *DataNode) UpdateVolumes(actualVolumes []storage.VolumeInfo) (deletedVolumes []storage.VolumeInfo) {
|
||||
func (dn *DataNode) UpdateVolumes(actualVolumes []storage.VolumeInfo) (newVolumes, deletedVolumes []storage.VolumeInfo) {
|
||||
actualVolumeMap := make(map[storage.VolumeId]storage.VolumeInfo)
|
||||
for _, v := range actualVolumes {
|
||||
actualVolumeMap[v.Id] = v
|
||||
|
@ -64,7 +66,10 @@ func (dn *DataNode) UpdateVolumes(actualVolumes []storage.VolumeInfo) (deletedVo
|
|||
}
|
||||
dn.Unlock()
|
||||
for _, v := range actualVolumes {
|
||||
dn.AddOrUpdateVolume(v)
|
||||
isNew := dn.AddOrUpdateVolume(v)
|
||||
if isNew {
|
||||
newVolumes = append(newVolumes, v)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
|
@ -151,7 +151,7 @@ func (t *Topology) GetOrCreateDataCenter(dcName string) *DataCenter {
|
|||
return dc
|
||||
}
|
||||
|
||||
func (t *Topology) SyncDataNodeRegistration(volumes []*master_pb.VolumeInformationMessage, dn *DataNode) {
|
||||
func (t *Topology) SyncDataNodeRegistration(volumes []*master_pb.VolumeInformationMessage, dn *DataNode) (newVolumes, deletedVolumes []storage.VolumeInfo) {
|
||||
var volumeInfos []storage.VolumeInfo
|
||||
for _, v := range volumes {
|
||||
if vi, err := storage.NewVolumeInfo(v); err == nil {
|
||||
|
@ -160,11 +160,12 @@ func (t *Topology) SyncDataNodeRegistration(volumes []*master_pb.VolumeInformati
|
|||
glog.V(0).Infof("Fail to convert joined volume information: %v", err)
|
||||
}
|
||||
}
|
||||
deletedVolumes := dn.UpdateVolumes(volumeInfos)
|
||||
newVolumes, deletedVolumes = dn.UpdateVolumes(volumeInfos)
|
||||
for _, v := range volumeInfos {
|
||||
t.RegisterVolumeLayout(v, dn)
|
||||
}
|
||||
for _, v := range deletedVolumes {
|
||||
t.UnRegisterVolumeLayout(v, dn)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue