diff options
| author | Chris Lu <chrislusf@users.noreply.github.com> | 2022-07-22 02:57:50 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-07-22 02:57:50 -0700 |
| commit | 0716092b396941e07ab2e41e782641ae658b3793 (patch) | |
| tree | e13bb6cae85e8ba2454658d27698b6577800abab /weed/wdclient/masterclient.go | |
| parent | 8d97add89cddb316466776d875e9dc1419932ae6 (diff) | |
| parent | 994a2dec78bcc0beaf9d643a96b98c9d17bd22b5 (diff) | |
| download | seaweedfs-0716092b396941e07ab2e41e782641ae658b3793.tar.xz seaweedfs-0716092b396941e07ab2e41e782641ae658b3793.zip | |
Merge pull request #3350 from shichanglin5/optimize_masterclient_vidmap
Solve the problem that `LookupFileId` lookup urls is empty due to lea…
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 d6a06bb57..2d0b00b76 100644 --- a/weed/wdclient/masterclient.go +++ b/weed/wdclient/masterclient.go @@ -24,18 +24,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 + } + } +} |
