mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
lib/logstorage: eliminate data race when clearing s.ptwHot after deleting the corresponding partition
The previous code could result in the following data race:
1. The s.ptwHot partition is marked to be deleted
2. ptw.decRef() is called on it
3. ptw.pt is set to nil
4. s.ptwHot.pt is accessed from concurrent goroutine, which leads to panic.
The change clears s.ptwHot under s.partitionsLock in order to prevent from the data race.
This is a follow-up for 8d50032dd6
Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/4895
This commit is contained in:
parent
e8db78eaa4
commit
317a273c6d
1 changed files with 3 additions and 3 deletions
|
@ -317,6 +317,9 @@ func (s *Storage) watchRetention() {
|
|||
break
|
||||
}
|
||||
ptwsToDelete = append(ptwsToDelete, ptw)
|
||||
if ptw == s.ptwHot {
|
||||
s.ptwHot = nil
|
||||
}
|
||||
}
|
||||
for i := range ptwsToDelete {
|
||||
s.partitions[i] = nil
|
||||
|
@ -329,9 +332,6 @@ func (s *Storage) watchRetention() {
|
|||
logger.Infof("the partition %s is scheduled to be deleted because it is outside the -retentionPeriod=%dd", ptw.pt.path, durationToDays(s.retention))
|
||||
atomic.StoreUint32(&ptw.mustBeDeleted, 1)
|
||||
ptw.decRef()
|
||||
if s.ptwHot != nil && s.ptwHot.pt == ptw.pt {
|
||||
s.ptwHot = nil
|
||||
}
|
||||
}
|
||||
|
||||
select {
|
||||
|
|
Loading…
Reference in a new issue