Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ethdb/pebble: use atomic type #27014

Merged
merged 1 commit into from
Mar 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions ethdb/pebble/pebble.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,14 @@ type Database struct {

log log.Logger // Contextual logger tracking the database path

activeComp int // Current number of active compactions
compStartTime time.Time // The start time of the earliest currently-active compaction
compTime int64 // Total time spent in compaction in ns
level0Comp uint32 // Total number of level-zero compactions
nonLevel0Comp uint32 // Total number of non level-zero compactions
writeDelayStartTime time.Time // The start time of the latest write stall
writeDelayCount int64 // Total number of write stall counts
writeDelayTime int64 // Total time spent in write stalls
activeComp int // Current number of active compactions
compStartTime time.Time // The start time of the earliest currently-active compaction
compTime atomic.Int64 // Total time spent in compaction in ns
level0Comp atomic.Uint32 // Total number of level-zero compactions
nonLevel0Comp atomic.Uint32 // Total number of non level-zero compactions
writeDelayStartTime time.Time // The start time of the latest write stall
writeDelayCount atomic.Int64 // Total number of write stall counts
writeDelayTime atomic.Int64 // Total time spent in write stalls
}

func (d *Database) onCompactionBegin(info pebble.CompactionInfo) {
Expand All @@ -91,16 +91,16 @@ func (d *Database) onCompactionBegin(info pebble.CompactionInfo) {
}
l0 := info.Input[0]
if l0.Level == 0 {
atomic.AddUint32(&d.level0Comp, 1)
d.level0Comp.Add(1)
} else {
atomic.AddUint32(&d.nonLevel0Comp, 1)
d.nonLevel0Comp.Add(1)
}
d.activeComp++
}

func (d *Database) onCompactionEnd(info pebble.CompactionInfo) {
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 {
panic("should not happen")
}
Expand All @@ -112,7 +112,7 @@ func (d *Database) onWriteStallBegin(b pebble.WriteStallBeginInfo) {
}

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
Expand Down Expand Up @@ -407,11 +407,11 @@ func (d *Database) meter(refresh time.Duration) {
nWrite int64

metrics = d.db.Metrics()
compTime = atomic.LoadInt64(&d.compTime)
writeDelayCount = atomic.LoadInt64(&d.writeDelayCount)
writeDelayTime = atomic.LoadInt64(&d.writeDelayTime)
nonLevel0CompCount = int64(atomic.LoadUint32(&d.nonLevel0Comp))
level0CompCount = int64(atomic.LoadUint32(&d.level0Comp))
compTime = d.compTime.Load()
writeDelayCount = d.writeDelayCount.Load()
writeDelayTime = d.writeDelayTime.Load()
nonLevel0CompCount = int64(d.nonLevel0Comp.Load())
level0CompCount = int64(d.level0Comp.Load())
)
writeDelayTimes[i%2] = writeDelayTime
writeDelayCounts[i%2] = writeDelayCount
Expand Down