forked from cerc-io/plugeth
ethdb/pebble: use atomic type (#27014)
This commit is contained in:
parent
2d1492821d
commit
50317bdace
@ -77,12 +77,12 @@ type Database struct {
|
|||||||
|
|
||||||
activeComp int // Current number of active compactions
|
activeComp int // Current number of active compactions
|
||||||
compStartTime time.Time // The start time of the earliest currently-active compaction
|
compStartTime time.Time // The start time of the earliest currently-active compaction
|
||||||
compTime int64 // Total time spent in compaction in ns
|
compTime atomic.Int64 // Total time spent in compaction in ns
|
||||||
level0Comp uint32 // Total number of level-zero compactions
|
level0Comp atomic.Uint32 // Total number of level-zero compactions
|
||||||
nonLevel0Comp uint32 // Total number of non level-zero compactions
|
nonLevel0Comp atomic.Uint32 // Total number of non level-zero compactions
|
||||||
writeDelayStartTime time.Time // The start time of the latest write stall
|
writeDelayStartTime time.Time // The start time of the latest write stall
|
||||||
writeDelayCount int64 // Total number of write stall counts
|
writeDelayCount atomic.Int64 // Total number of write stall counts
|
||||||
writeDelayTime int64 // Total time spent in write stalls
|
writeDelayTime atomic.Int64 // Total time spent in write stalls
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Database) onCompactionBegin(info pebble.CompactionInfo) {
|
func (d *Database) onCompactionBegin(info pebble.CompactionInfo) {
|
||||||
@ -91,16 +91,16 @@ func (d *Database) onCompactionBegin(info pebble.CompactionInfo) {
|
|||||||
}
|
}
|
||||||
l0 := info.Input[0]
|
l0 := info.Input[0]
|
||||||
if l0.Level == 0 {
|
if l0.Level == 0 {
|
||||||
atomic.AddUint32(&d.level0Comp, 1)
|
d.level0Comp.Add(1)
|
||||||
} else {
|
} else {
|
||||||
atomic.AddUint32(&d.nonLevel0Comp, 1)
|
d.nonLevel0Comp.Add(1)
|
||||||
}
|
}
|
||||||
d.activeComp++
|
d.activeComp++
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Database) onCompactionEnd(info pebble.CompactionInfo) {
|
func (d *Database) onCompactionEnd(info pebble.CompactionInfo) {
|
||||||
if d.activeComp == 1 {
|
if d.activeComp == 1 {
|
||||||
atomic.AddInt64(&d.compTime, int64(time.Since(d.compStartTime)))
|
d.compTime.Add(int64(time.Since(d.compStartTime)))
|
||||||
} else if d.activeComp == 0 {
|
} else if d.activeComp == 0 {
|
||||||
panic("should not happen")
|
panic("should not happen")
|
||||||
}
|
}
|
||||||
@ -112,7 +112,7 @@ func (d *Database) onWriteStallBegin(b pebble.WriteStallBeginInfo) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *Database) onWriteStallEnd() {
|
func (d *Database) onWriteStallEnd() {
|
||||||
atomic.AddInt64(&d.writeDelayTime, int64(time.Since(d.writeDelayStartTime)))
|
d.writeDelayTime.Add(int64(time.Since(d.writeDelayStartTime)))
|
||||||
}
|
}
|
||||||
|
|
||||||
// New returns a wrapped pebble DB object. The namespace is the prefix that the
|
// New returns a wrapped pebble DB object. The namespace is the prefix that the
|
||||||
@ -407,11 +407,11 @@ func (d *Database) meter(refresh time.Duration) {
|
|||||||
nWrite int64
|
nWrite int64
|
||||||
|
|
||||||
metrics = d.db.Metrics()
|
metrics = d.db.Metrics()
|
||||||
compTime = atomic.LoadInt64(&d.compTime)
|
compTime = d.compTime.Load()
|
||||||
writeDelayCount = atomic.LoadInt64(&d.writeDelayCount)
|
writeDelayCount = d.writeDelayCount.Load()
|
||||||
writeDelayTime = atomic.LoadInt64(&d.writeDelayTime)
|
writeDelayTime = d.writeDelayTime.Load()
|
||||||
nonLevel0CompCount = int64(atomic.LoadUint32(&d.nonLevel0Comp))
|
nonLevel0CompCount = int64(d.nonLevel0Comp.Load())
|
||||||
level0CompCount = int64(atomic.LoadUint32(&d.level0Comp))
|
level0CompCount = int64(d.level0Comp.Load())
|
||||||
)
|
)
|
||||||
writeDelayTimes[i%2] = writeDelayTime
|
writeDelayTimes[i%2] = writeDelayTime
|
||||||
writeDelayCounts[i%2] = writeDelayCount
|
writeDelayCounts[i%2] = writeDelayCount
|
||||||
|
Loading…
Reference in New Issue
Block a user