mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-23 20:37:12 +01:00
lib/logstorage: consistently use atomic.* type for refCount and mustDrop fields in datadb and storage structs in the same way as it is used in lib/storage
Seeea9e2b19a5
anda204fd69f1
This commit is contained in:
parent
5c89150fc9
commit
275335c181
@ -92,10 +92,10 @@ type partWrapper struct {
|
||||
// refCount is the number of references to p.
|
||||
//
|
||||
// When the number of references reaches zero, then p is closed.
|
||||
refCount int32
|
||||
refCount atomic.Int32
|
||||
|
||||
// The flag, which is set when the part must be deleted after refCount reaches zero.
|
||||
mustBeDeleted uint32
|
||||
mustDrop atomic.Bool
|
||||
|
||||
// p is an opened part
|
||||
p *part
|
||||
@ -111,18 +111,18 @@ type partWrapper struct {
|
||||
}
|
||||
|
||||
func (pw *partWrapper) incRef() {
|
||||
atomic.AddInt32(&pw.refCount, 1)
|
||||
pw.refCount.Add(1)
|
||||
}
|
||||
|
||||
func (pw *partWrapper) decRef() {
|
||||
n := atomic.AddInt32(&pw.refCount, -1)
|
||||
n := pw.refCount.Add(-1)
|
||||
if n > 0 {
|
||||
return
|
||||
}
|
||||
|
||||
deletePath := ""
|
||||
if pw.mp == nil {
|
||||
if atomic.LoadUint32(&pw.mustBeDeleted) != 0 {
|
||||
if pw.mustDrop.Load() {
|
||||
deletePath = pw.p.path
|
||||
}
|
||||
} else {
|
||||
@ -767,7 +767,7 @@ func (ddb *datadb) swapSrcWithDstParts(pws []*partWrapper, pwNew *partWrapper, d
|
||||
// Mark old parts as must be deleted and decrement reference count,
|
||||
// so they are eventually closed and deleted.
|
||||
for _, pw := range pws {
|
||||
atomic.StoreUint32(&pw.mustBeDeleted, 1)
|
||||
pw.mustDrop.Store(true)
|
||||
pw.decRef()
|
||||
}
|
||||
}
|
||||
@ -917,8 +917,8 @@ func mustCloseDatadb(ddb *datadb) {
|
||||
// close file parts
|
||||
for _, pw := range ddb.fileParts {
|
||||
pw.decRef()
|
||||
if pw.refCount != 0 {
|
||||
logger.Panicf("BUG: ther are %d references to filePart", pw.refCount)
|
||||
if n := pw.refCount.Load(); n != 0 {
|
||||
logger.Panicf("BUG: ther are %d references to filePart", n)
|
||||
}
|
||||
}
|
||||
ddb.fileParts = nil
|
||||
|
@ -142,10 +142,10 @@ type Storage struct {
|
||||
type partitionWrapper struct {
|
||||
// refCount is the number of active references to p.
|
||||
// When it reaches zero, then the p is closed.
|
||||
refCount int32
|
||||
refCount atomic.Int32
|
||||
|
||||
// The flag, which is set when the partition must be deleted after refCount reaches zero.
|
||||
mustBeDeleted uint32
|
||||
mustDrop atomic.Bool
|
||||
|
||||
// day is the day for the partition in the unix timestamp divided by the number of seconds in the day.
|
||||
day int64
|
||||
@ -164,17 +164,17 @@ func newPartitionWrapper(pt *partition, day int64) *partitionWrapper {
|
||||
}
|
||||
|
||||
func (ptw *partitionWrapper) incRef() {
|
||||
atomic.AddInt32(&ptw.refCount, 1)
|
||||
ptw.refCount.Add(1)
|
||||
}
|
||||
|
||||
func (ptw *partitionWrapper) decRef() {
|
||||
n := atomic.AddInt32(&ptw.refCount, -1)
|
||||
n := ptw.refCount.Add(-1)
|
||||
if n > 0 {
|
||||
return
|
||||
}
|
||||
|
||||
deletePath := ""
|
||||
if atomic.LoadUint32(&ptw.mustBeDeleted) != 0 {
|
||||
if ptw.mustDrop.Load() {
|
||||
deletePath = ptw.pt.path
|
||||
}
|
||||
|
||||
@ -293,7 +293,7 @@ func MustOpenStorage(path string, cfg *StorageConfig) *Storage {
|
||||
break
|
||||
}
|
||||
logger.Infof("the partition %s is scheduled to be deleted because it is outside the -futureRetention=%dd", ptw.pt.path, durationToDays(s.futureRetention))
|
||||
atomic.StoreUint32(&ptw.mustBeDeleted, 1)
|
||||
ptw.mustDrop.Store(true)
|
||||
ptw.decRef()
|
||||
j--
|
||||
}
|
||||
@ -348,7 +348,7 @@ func (s *Storage) watchRetention() {
|
||||
|
||||
for _, ptw := range ptwsToDelete {
|
||||
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.mustDrop.Store(true)
|
||||
ptw.decRef()
|
||||
}
|
||||
|
||||
@ -379,8 +379,8 @@ func (s *Storage) MustClose() {
|
||||
// Close partitions
|
||||
for _, pw := range s.partitions {
|
||||
pw.decRef()
|
||||
if pw.refCount != 0 {
|
||||
logger.Panicf("BUG: there are %d users of partition", pw.refCount)
|
||||
if n := pw.refCount.Load(); n != 0 {
|
||||
logger.Panicf("BUG: there are %d users of partition", n)
|
||||
}
|
||||
}
|
||||
s.partitions = nil
|
||||
|
Loading…
Reference in New Issue
Block a user