diff --git a/weed/wdclient/masterclient.go b/weed/wdclient/masterclient.go index a91cb3614..c883576f1 100644 --- a/weed/wdclient/masterclient.go +++ b/weed/wdclient/masterclient.go @@ -592,14 +592,10 @@ func (mc *MasterClient) resetVidMap() { mc.vidMapLock.Lock() defer mc.vidMapLock.Unlock() - tail := &vidMap{ - vid2Locations: mc.vidMap.vid2Locations, - ecVid2Locations: mc.vidMap.ecVid2Locations, - DataCenter: mc.vidMap.DataCenter, - cache: mc.vidMap.cache, - } + // Create a shallow clone to preserve in the cache chain + tail := mc.vidMap.shallowClone() - nvm := newVidMap(mc.vidMap.DataCenter) + nvm := newVidMap(tail.DataCenter) nvm.cache = tail mc.vidMap = nvm diff --git a/weed/wdclient/vid_map.go b/weed/wdclient/vid_map.go index 9d5e5d378..6d6ccd6e6 100644 --- a/weed/wdclient/vid_map.go +++ b/weed/wdclient/vid_map.go @@ -53,6 +53,17 @@ func newVidMap(dataCenter string) *vidMap { } } +// shallowClone creates a shallow copy of the vidMap for use in cache chaining. +// The caller is responsible for ensuring thread safety. +func (vc *vidMap) shallowClone() *vidMap { + return &vidMap{ + vid2Locations: vc.vid2Locations, + ecVid2Locations: vc.ecVid2Locations, + DataCenter: vc.DataCenter, + cache: vc.cache, + } +} + func (vc *vidMap) getLocationIndex(length int) (int, error) { if length <= 0 { return 0, fmt.Errorf("invalid length: %d", length)