Skip to content

Commit c346baf

Browse files
committed
fix:移除 serviceCount 的计数
1 parent 1a2334b commit c346baf

File tree

1 file changed

+7
-15
lines changed

1 file changed

+7
-15
lines changed

cache/service/service.go

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,7 @@ type serviceCache struct {
6363
// namespace -> model.NamespaceServiceCount
6464
namespaceServiceCnt *utils.SyncMap[string, *model.NamespaceServiceCount]
6565

66-
lastMtimeLogged int64
67-
68-
serviceCount int64
66+
lastMtimeLogged int64
6967
lastCheckAllTime int64
7068

7169
revisionWorker *ServiceRevisionWorker
@@ -166,12 +164,12 @@ func (sc *serviceCache) checkAll() {
166164
log.Errorf("[Cache][Service] get service count from storage err: %s", err.Error())
167165
return
168166
}
169-
if sc.serviceCount == int64(count) {
167+
if int64(sc.ids.Len()) == int64(count) {
170168
return
171169
}
172170
log.Infof(
173171
"[Cache][Service] service count not match, expect %d, actual %d, fallback to load all",
174-
count, sc.serviceCount)
172+
count, sc.ids.Len())
175173
sc.ResetLastMtime(sc.Name())
176174
}
177175

@@ -441,7 +439,7 @@ func (sc *serviceCache) setServices(services map[string]*model.Service) (map[str
441439

442440
// 这里要记录 ns 的变动情况,避免由于 svc delete 之后,命名空间的服务计数无法更新
443441
changeNs := make(map[string]struct{})
444-
svcCount := sc.serviceCount
442+
svcCount := sc.ids.Len()
445443

446444
aliases := make([]*model.Service, 0, 32)
447445

@@ -459,7 +457,7 @@ func (sc *serviceCache) setServices(services map[string]*model.Service) (map[str
459457
if service.IsAlias() {
460458
aliases = append(aliases, service)
461459
}
462-
oldVal, exist := sc.ids.Load(service.ID)
460+
oldVal, _ := sc.ids.Load(service.ID)
463461
if oldVal != nil {
464462
service.OldExportTo = oldVal.ExportTo
465463
}
@@ -471,14 +469,10 @@ func (sc *serviceCache) setServices(services map[string]*model.Service) (map[str
471469
sc.removeServices(service)
472470
sc.notifyRevisionWorker(service.ID, false)
473471
del++
474-
svcCount--
475472
continue
476473
}
477474

478475
update++
479-
if !exist {
480-
svcCount++
481-
}
482476

483477
sc.ids.Store(service.ID, service)
484478
sc.serviceList.addService(service)
@@ -496,10 +490,8 @@ func (sc *serviceCache) setServices(services map[string]*model.Service) (map[str
496490
/******兼容cl5******/
497491
}
498492

499-
if sc.serviceCount != svcCount {
500-
log.Infof("[Cache][Service] service count update from %d to %d",
501-
sc.serviceCount, svcCount)
502-
sc.serviceCount = svcCount
493+
if sc.ids.Len() != svcCount {
494+
log.Infof("[Cache][Service] service count update from %d to %d", svcCount, sc.ids.Len())
503495
}
504496

505497
sc.postProcessServiceAlias(aliases)

0 commit comments

Comments
 (0)