fix bug due to data racing on VidMap (#3606)

This commit is contained in:
LHHDZ
2022-09-06 11:00:16 +08:00
committed by GitHub
parent 7c277f36ec
commit bc629665de
3 changed files with 48 additions and 6 deletions

View File

@@ -27,7 +27,7 @@ type MasterClient struct {
masters map[string]pb.ServerAddress
grpcDialOption grpc.DialOption
vidMap
*vidMap
vidMapCacheSize int
OnPeerUpdate func(update *master_pb.ClusterNodeUpdate, startFrom time.Time)
OnPeerUpdateLock sync.RWMutex
@@ -303,9 +303,12 @@ func (mc *MasterClient) resetVidMap() {
DataCenter: mc.DataCenter,
cache: mc.cache,
}
mc.vidMap = newVidMap(mc.DataCenter)
mc.vidMap.cache = tail
nvm := newVidMap(mc.DataCenter)
nvm.cache = tail
mc.vidMap = nvm
//trim
for i := 0; i < mc.vidMapCacheSize && tail.cache != nil; i++ {
if i == mc.vidMapCacheSize-1 {
tail.cache = nil