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:
Aliaksandr Valialkin 2023-08-29 11:04:11 +02:00
parent c4b10109d7
commit 1e1aa94ffb
No known key found for this signature in database
GPG key ID: A72BEC6CD3D0DED1

View file

@ -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