diff options
| author | LHHDZ <changlin.shi@ly.com> | 2022-07-22 17:22:38 +0800 |
|---|---|---|
| committer | LHHDZ <changlin.shi@ly.com> | 2022-07-22 17:22:38 +0800 |
| commit | 58c02d6429530d674d4e0e493e9e1a860208017e (patch) | |
| tree | 14bce48d059b56ba0dc8631f82c798c8d768e681 /weed/wdclient/masterclient.go | |
| parent | 56ec89625a5d4a66e3b1c810544afd93f449842e (diff) | |
| download | seaweedfs-58c02d6429530d674d4e0e493e9e1a860208017e.tar.xz seaweedfs-58c02d6429530d674d4e0e493e9e1a860208017e.zip | |
Solve the problem that `LookupFileId` lookup urls is empty due to leader switching
The vidMap structure is modified to a linked list structure (the length is limited to 5). When the vidMap is reset, the current vidMap is added to the new vidMap as a cache node. When the query locations is empty, the cache node is searched to avoid problems when the master switches leaders.
Diffstat (limited to 'weed/wdclient/masterclient.go')
| -rw-r--r-- | weed/wdclient/masterclient.go | 34 |
1 files changed, 26 insertions, 8 deletions
diff --git a/weed/wdclient/masterclient.go b/weed/wdclient/masterclient.go index 3e76dc0c5..1ff735788 100644 --- a/weed/wdclient/masterclient.go +++ b/weed/wdclient/masterclient.go @@ -23,18 +23,20 @@ type MasterClient struct { grpcDialOption grpc.DialOption vidMap + vidMapCacheSize int OnPeerUpdate func(update *master_pb.ClusterNodeUpdate, startFrom time.Time) } func NewMasterClient(grpcDialOption grpc.DialOption, filerGroup string, clientType string, clientHost pb.ServerAddress, clientDataCenter string, masters map[string]pb.ServerAddress) *MasterClient { return &MasterClient{ - FilerGroup: filerGroup, - clientType: clientType, - clientHost: clientHost, - masters: masters, - grpcDialOption: grpcDialOption, - vidMap: newVidMap(clientDataCenter), + FilerGroup: filerGroup, + clientType: clientType, + clientHost: clientHost, + masters: masters, + grpcDialOption: grpcDialOption, + vidMap: newVidMap(clientDataCenter), + vidMapCacheSize: 5, } } @@ -175,10 +177,12 @@ func (mc *MasterClient) tryConnectToMaster(master pb.ServerAddress) (nextHintedL stats.MasterClientConnectCounter.WithLabelValues(stats.RedirectedToleader).Inc() return nil } - mc.vidMap = newVidMap("") + //mc.vidMap = newVidMap("") + mc.resetVidMap() mc.updateVidMap(resp) } else { - mc.vidMap = newVidMap("") + mc.resetVidMap() + //mc.vidMap = newVidMap("") } mc.currentMaster = master @@ -263,3 +267,17 @@ func (mc *MasterClient) WithClient(streamingMode bool, fn func(client master_pb. }) }) } + +func (mc *MasterClient) resetVidMap() { + tail := &vidMap{vid2Locations: mc.vid2Locations, ecVid2Locations: mc.ecVid2Locations, cache: mc.cache} + mc.vidMap = newVidMap("") + mc.vidMap.cache = tail + + for i := 0; i < mc.vidMapCacheSize && tail.cache != nil; i++ { + if i == mc.vidMapCacheSize-1 { + tail.cache = nil + } else { + tail = tail.cache + } + } +} |
