Revert "Revert "remove duplicated metadata subscription in filer""

This reverts commit 34b743c481.
This commit is contained in:
chrislu 2022-03-26 13:00:16 -07:00
parent 34b743c481
commit cae998eda1

View file

@ -25,7 +25,7 @@ type MetaAggregator struct {
isLeader bool isLeader bool
grpcDialOption grpc.DialOption grpcDialOption grpc.DialOption
MetaLogBuffer *log_buffer.LogBuffer MetaLogBuffer *log_buffer.LogBuffer
peerStatues map[pb.ServerAddress]struct{} peerStatues map[pb.ServerAddress]int
peerStatuesLock sync.Mutex peerStatuesLock sync.Mutex
// notifying clients // notifying clients
ListenersLock sync.Mutex ListenersLock sync.Mutex
@ -39,7 +39,7 @@ func NewMetaAggregator(filer *Filer, self pb.ServerAddress, grpcDialOption grpc.
filer: filer, filer: filer,
self: self, self: self,
grpcDialOption: grpcDialOption, grpcDialOption: grpcDialOption,
peerStatues: make(map[pb.ServerAddress]struct{}), peerStatues: make(map[pb.ServerAddress]int),
} }
t.ListenersCond = sync.NewCond(&t.ListenersLock) t.ListenersCond = sync.NewCond(&t.ListenersLock)
t.MetaLogBuffer = log_buffer.NewLogBuffer("aggr", LogFlushInterval, nil, func() { t.MetaLogBuffer = log_buffer.NewLogBuffer("aggr", LogFlushInterval, nil, func() {
@ -56,27 +56,40 @@ func (ma *MetaAggregator) OnPeerUpdate(update *master_pb.ClusterNodeUpdate) {
address := pb.ServerAddress(update.Address) address := pb.ServerAddress(update.Address)
if update.IsAdd { if update.IsAdd {
// every filer should subscribe to a new filer // every filer should subscribe to a new filer
ma.setActive(address, true) if ma.setActive(address, true) {
go ma.subscribeToOneFiler(ma.filer, ma.self, address) go ma.subscribeToOneFiler(ma.filer, ma.self, address)
}
} else { } else {
ma.setActive(address, false) ma.setActive(address, false)
} }
} }
func (ma *MetaAggregator) setActive(address pb.ServerAddress, isActive bool) { func (ma *MetaAggregator) setActive(address pb.ServerAddress, isActive bool) (notDuplicated bool) {
ma.peerStatuesLock.Lock() ma.peerStatuesLock.Lock()
defer ma.peerStatuesLock.Unlock() defer ma.peerStatuesLock.Unlock()
if isActive { if isActive {
ma.peerStatues[address] = struct{}{} if _, found := ma.peerStatues[address]; found {
ma.peerStatues[address] += 1
} else { } else {
ma.peerStatues[address] = 1
notDuplicated = true
}
} else {
if _, found := ma.peerStatues[address]; found {
ma.peerStatues[address] -= 1
}
if ma.peerStatues[address] <= 0 {
delete(ma.peerStatues, address) delete(ma.peerStatues, address)
} }
}
return
} }
func (ma *MetaAggregator) isActive(address pb.ServerAddress) (isActive bool) { func (ma *MetaAggregator) isActive(address pb.ServerAddress) (isActive bool) {
ma.peerStatuesLock.Lock() ma.peerStatuesLock.Lock()
defer ma.peerStatuesLock.Unlock() defer ma.peerStatuesLock.Unlock()
_, isActive = ma.peerStatues[address] var count int
return count, isActive = ma.peerStatues[address]
return count > 0 && isActive
} }
func (ma *MetaAggregator) subscribeToOneFiler(f *Filer, self pb.ServerAddress, peer pb.ServerAddress) { func (ma *MetaAggregator) subscribeToOneFiler(f *Filer, self pb.ServerAddress, peer pb.ServerAddress) {