mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2025-03-21 15:45:01 +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
|
// Contains mutable map protected by mu
|
||||||
byDateMutable *byDateMetricIDMap
|
byDateMutable *byDateMetricIDMap
|
||||||
lastSyncTime time.Time
|
lastSyncTime time.Time
|
||||||
mu sync.RWMutex
|
mu sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
func newDateMetricIDCache() *dateMetricIDCache {
|
func newDateMetricIDCache() *dateMetricIDCache {
|
||||||
|
@ -1057,7 +1057,7 @@ func (dmc *dateMetricIDCache) Has(date, metricID uint64) bool {
|
||||||
// Slow path. Check mutable map.
|
// Slow path. Check mutable map.
|
||||||
currentTime := time.Now()
|
currentTime := time.Now()
|
||||||
|
|
||||||
dmc.mu.RLock()
|
dmc.mu.Lock()
|
||||||
v = dmc.byDateMutable.get(date)
|
v = dmc.byDateMutable.get(date)
|
||||||
ok := v.Has(metricID)
|
ok := v.Has(metricID)
|
||||||
mustSync := false
|
mustSync := false
|
||||||
|
@ -1065,7 +1065,7 @@ func (dmc *dateMetricIDCache) Has(date, metricID uint64) bool {
|
||||||
mustSync = true
|
mustSync = true
|
||||||
dmc.lastSyncTime = currentTime
|
dmc.lastSyncTime = currentTime
|
||||||
}
|
}
|
||||||
dmc.mu.RUnlock()
|
dmc.mu.Unlock()
|
||||||
|
|
||||||
if mustSync {
|
if mustSync {
|
||||||
dmc.sync()
|
dmc.sync()
|
||||||
|
|
Loading…
Reference in a new issue