Skip to content

Commit

Permalink
fix data race
Browse files Browse the repository at this point in the history
Signed-off-by: Wei Liu <[email protected]>
  • Loading branch information
weiliu1031 committed Jul 12, 2024
1 parent 184b3bc commit 243bc5b
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions internal/querycoordv2/balance/score_based_balancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type ScoreBasedBalancer struct {
broker meta.Broker

// collectionID -> cachedRecordSizeInfo
cachedMaxRecordSize map[int64]*cachedRecordSizeInfo
cachedMaxRecordSize *typeutil.ConcurrentMap[int64, *cachedRecordSizeInfo]
}

func NewScoreBasedBalancer(scheduler task.Scheduler,
Expand All @@ -60,7 +60,7 @@ func NewScoreBasedBalancer(scheduler task.Scheduler,
return &ScoreBasedBalancer{
RowCountBasedBalancer: NewRowCountBasedBalancer(scheduler, nodeManager, dist, meta, targetMgr),
broker: broker,
cachedMaxRecordSize: make(map[int64]*cachedRecordSizeInfo),
cachedMaxRecordSize: typeutil.NewConcurrentMap[int64, *cachedRecordSizeInfo](),
}
}

Expand Down Expand Up @@ -230,7 +230,7 @@ func (b *ScoreBasedBalancer) calculateScore(collectionID, nodeID int64) int {
}

func (b *ScoreBasedBalancer) estimateRecordSize(collectionID int64) int {
cacheInfo, ok := b.cachedMaxRecordSize[collectionID]
cacheInfo, ok := b.cachedMaxRecordSize.Get(collectionID)
if ok && time.Since(cacheInfo.ts) < 300*time.Second {
return cacheInfo.size
}
Expand All @@ -251,7 +251,7 @@ func (b *ScoreBasedBalancer) estimateRecordSize(collectionID int64) int {
// if get schema failed, set record size to 4096 by default
recordSize = 4096

Check warning on line 252 in internal/querycoordv2/balance/score_based_balancer.go

View check run for this annotation

Codecov / codecov/patch

internal/querycoordv2/balance/score_based_balancer.go#L252

Added line #L252 was not covered by tests
}
b.cachedMaxRecordSize[collectionID] = &cachedRecordSizeInfo{size: recordSize, ts: time.Now()}
b.cachedMaxRecordSize.Insert(collectionID, &cachedRecordSizeInfo{size: recordSize, ts: time.Now()})
return recordSize
}

Expand Down

0 comments on commit 243bc5b

Please sign in to comment.