mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
lib/storage: eliminate data race when updating lastSyncTime in dateMetricIDCache.Has
This commit is contained in:
parent
7247a7862d
commit
6bdde0d6d4
1 changed files with 3 additions and 3 deletions
|
@ -1020,7 +1020,7 @@ type dateMetricIDCache struct {
|
|||
// Contains mutable map protected by mu
|
||||
byDateMutable *byDateMetricIDMap
|
||||
lastSyncTime time.Time
|
||||
mu sync.RWMutex
|
||||
mu sync.Mutex
|
||||
}
|
||||
|
||||
func newDateMetricIDCache() *dateMetricIDCache {
|
||||
|
@ -1057,7 +1057,7 @@ func (dmc *dateMetricIDCache) Has(date, metricID uint64) bool {
|
|||
// Slow path. Check mutable map.
|
||||
currentTime := time.Now()
|
||||
|
||||
dmc.mu.RLock()
|
||||
dmc.mu.Lock()
|
||||
v = dmc.byDateMutable.get(date)
|
||||
ok := v.Has(metricID)
|
||||
mustSync := false
|
||||
|
@ -1065,7 +1065,7 @@ func (dmc *dateMetricIDCache) Has(date, metricID uint64) bool {
|
|||
mustSync = true
|
||||
dmc.lastSyncTime = currentTime
|
||||
}
|
||||
dmc.mu.RUnlock()
|
||||
dmc.mu.Unlock()
|
||||
|
||||
if mustSync {
|
||||
dmc.sync()
|
||||
|
|
Loading…
Reference in a new issue