mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
avoid race conditions for OnPeerUpdate (#3525)
https://github.com/seaweedfs/seaweedfs/issues/3524
This commit is contained in:
parent
4f7a1f67cd
commit
e90ab4ac60
|
@ -96,7 +96,7 @@ func (f *Filer) MaybeBootstrapFromPeers(self pb.ServerAddress, existingNodes []*
|
||||||
func (f *Filer) AggregateFromPeers(self pb.ServerAddress, existingNodes []*master_pb.ClusterNodeUpdate, startFrom time.Time) {
|
func (f *Filer) AggregateFromPeers(self pb.ServerAddress, existingNodes []*master_pb.ClusterNodeUpdate, startFrom time.Time) {
|
||||||
|
|
||||||
f.MetaAggregator = NewMetaAggregator(f, self, f.GrpcDialOption)
|
f.MetaAggregator = NewMetaAggregator(f, self, f.GrpcDialOption)
|
||||||
f.MasterClient.OnPeerUpdate = f.MetaAggregator.OnPeerUpdate
|
f.MasterClient.SetOnPeerUpdateFn(f.MetaAggregator.OnPeerUpdate)
|
||||||
|
|
||||||
for _, peerUpdate := range existingNodes {
|
for _, peerUpdate := range existingNodes {
|
||||||
f.MetaAggregator.OnPeerUpdate(peerUpdate, startFrom)
|
f.MetaAggregator.OnPeerUpdate(peerUpdate, startFrom)
|
||||||
|
|
|
@ -42,7 +42,7 @@ func NewMessageBroker(option *MessageQueueBrokerOption, grpcDialOption grpc.Dial
|
||||||
MasterClient: wdclient.NewMasterClient(grpcDialOption, option.FilerGroup, cluster.BrokerType, pb.NewServerAddress(option.Ip, option.Port, 0), option.DataCenter, option.Rack, option.Masters),
|
MasterClient: wdclient.NewMasterClient(grpcDialOption, option.FilerGroup, cluster.BrokerType, pb.NewServerAddress(option.Ip, option.Port, 0), option.DataCenter, option.Rack, option.Masters),
|
||||||
filers: make(map[pb.ServerAddress]struct{}),
|
filers: make(map[pb.ServerAddress]struct{}),
|
||||||
}
|
}
|
||||||
mqBroker.MasterClient.OnPeerUpdate = mqBroker.OnBrokerUpdate
|
mqBroker.MasterClient.SetOnPeerUpdateFn(mqBroker.OnBrokerUpdate)
|
||||||
|
|
||||||
go mqBroker.MasterClient.KeepConnectedToMaster()
|
go mqBroker.MasterClient.KeepConnectedToMaster()
|
||||||
|
|
||||||
|
|
|
@ -116,7 +116,7 @@ func NewMasterServer(r *mux.Router, option *MasterOption, peers map[string]pb.Se
|
||||||
}
|
}
|
||||||
ms.boundedLeaderChan = make(chan int, 16)
|
ms.boundedLeaderChan = make(chan int, 16)
|
||||||
|
|
||||||
ms.MasterClient.OnPeerUpdate = ms.OnPeerUpdate
|
ms.MasterClient.SetOnPeerUpdateFn(ms.OnPeerUpdate)
|
||||||
|
|
||||||
seq := ms.createSequencer(option)
|
seq := ms.createSequencer(option)
|
||||||
if nil == seq {
|
if nil == seq {
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/seaweedfs/seaweedfs/weed/stats"
|
"github.com/seaweedfs/seaweedfs/weed/stats"
|
||||||
|
@ -29,6 +30,7 @@ type MasterClient struct {
|
||||||
vidMapCacheSize int
|
vidMapCacheSize int
|
||||||
|
|
||||||
OnPeerUpdate func(update *master_pb.ClusterNodeUpdate, startFrom time.Time)
|
OnPeerUpdate func(update *master_pb.ClusterNodeUpdate, startFrom time.Time)
|
||||||
|
OnPeerUpdateAccessLock sync.RWMutex
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewMasterClient(grpcDialOption grpc.DialOption, filerGroup string, clientType string, clientHost pb.ServerAddress, clientDataCenter string, rack string, masters map[string]pb.ServerAddress) *MasterClient {
|
func NewMasterClient(grpcDialOption grpc.DialOption, filerGroup string, clientType string, clientHost pb.ServerAddress, clientDataCenter string, rack string, masters map[string]pb.ServerAddress) *MasterClient {
|
||||||
|
@ -44,6 +46,12 @@ func NewMasterClient(grpcDialOption grpc.DialOption, filerGroup string, clientTy
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (mc *MasterClient) SetOnPeerUpdateFn(onPeerUpdate func(update *master_pb.ClusterNodeUpdate, startFrom time.Time)) {
|
||||||
|
mc.OnPeerUpdateAccessLock.Lock()
|
||||||
|
mc.OnPeerUpdate = onPeerUpdate
|
||||||
|
mc.OnPeerUpdateAccessLock.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
func (mc *MasterClient) GetLookupFileIdFunction() LookupFileIdFunctionType {
|
func (mc *MasterClient) GetLookupFileIdFunction() LookupFileIdFunctionType {
|
||||||
return mc.LookupFileIdWithFallback
|
return mc.LookupFileIdWithFallback
|
||||||
}
|
}
|
||||||
|
@ -219,6 +227,7 @@ func (mc *MasterClient) tryConnectToMaster(master pb.ServerAddress) (nextHintedL
|
||||||
|
|
||||||
if resp.ClusterNodeUpdate != nil {
|
if resp.ClusterNodeUpdate != nil {
|
||||||
update := resp.ClusterNodeUpdate
|
update := resp.ClusterNodeUpdate
|
||||||
|
mc.OnPeerUpdateAccessLock.RLock()
|
||||||
if mc.OnPeerUpdate != nil {
|
if mc.OnPeerUpdate != nil {
|
||||||
if update.FilerGroup == mc.FilerGroup {
|
if update.FilerGroup == mc.FilerGroup {
|
||||||
if update.IsAdd {
|
if update.IsAdd {
|
||||||
|
@ -230,6 +239,7 @@ func (mc *MasterClient) tryConnectToMaster(master pb.ServerAddress) (nextHintedL
|
||||||
mc.OnPeerUpdate(update, time.Now())
|
mc.OnPeerUpdate(update, time.Now())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
mc.OnPeerUpdateAccessLock.RUnlock()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue