Browse Source

remove shallow clone

pull/7412/head
chrislu 1 month ago
parent
commit
91094f8933
  1. 5
      weed/wdclient/masterclient.go
  2. 15
      weed/wdclient/vid_map.go

5
weed/wdclient/masterclient.go

@ -580,8 +580,9 @@ func (mc *MasterClient) resetVidMap() {
mc.vidMapLock.Lock() mc.vidMapLock.Lock()
defer mc.vidMapLock.Unlock() defer mc.vidMapLock.Unlock()
// Create a shallow clone to preserve in the cache chain
tail := mc.vidMap.shallowClone()
// Preserve the existing vidMap in the cache chain
// No need to clone - the existing vidMap has its own mutex for thread safety
tail := mc.vidMap
nvm := newVidMap(tail.DataCenter) nvm := newVidMap(tail.DataCenter)
nvm.cache.Store(tail) nvm.cache.Store(tail)

15
weed/wdclient/vid_map.go

@ -54,21 +54,6 @@ 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 {
newMap := &vidMap{
vid2Locations: vc.vid2Locations,
ecVid2Locations: vc.ecVid2Locations,
DataCenter: vc.DataCenter,
}
// Atomically copy the cache pointer
if cachedMap := vc.cache.Load(); cachedMap != nil {
newMap.cache.Store(cachedMap)
}
return newMap
}
func (vc *vidMap) getLocationIndex(length int) (int, error) { func (vc *vidMap) getLocationIndex(length int) (int, error) {
if length <= 0 { if length <= 0 {
return 0, fmt.Errorf("invalid length: %d", length) return 0, fmt.Errorf("invalid length: %d", length)

Loading…
Cancel
Save