Skip to content

Commit fbcfd11

Browse files
s7v7nislandsshekhirin
authored andcommitted
ethdb/pebble: use atomic type (ethereum#27014)
1 parent db53196 commit fbcfd11

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

ethdb/pebble/pebble.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,14 @@ type Database struct {
7575

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

78-
activeComp int // Current number of active compactions
79-
compStartTime time.Time // The start time of the earliest currently-active compaction
80-
compTime int64 // Total time spent in compaction in ns
81-
level0Comp uint32 // Total number of level-zero compactions
82-
nonLevel0Comp uint32 // Total number of non level-zero compactions
83-
writeDelayStartTime time.Time // The start time of the latest write stall
84-
writeDelayCount int64 // Total number of write stall counts
85-
writeDelayTime int64 // Total time spent in write stalls
78+
activeComp int // Current number of active compactions
79+
compStartTime time.Time // The start time of the earliest currently-active compaction
80+
compTime atomic.Int64 // Total time spent in compaction in ns
81+
level0Comp atomic.Uint32 // Total number of level-zero compactions
82+
nonLevel0Comp atomic.Uint32 // Total number of non level-zero compactions
83+
writeDelayStartTime time.Time // The start time of the latest write stall
84+
writeDelayCount atomic.Int64 // Total number of write stall counts
85+
writeDelayTime atomic.Int64 // Total time spent in write stalls
8686
}
8787

8888
func (d *Database) onCompactionBegin(info pebble.CompactionInfo) {
@@ -91,16 +91,16 @@ func (d *Database) onCompactionBegin(info pebble.CompactionInfo) {
9191
}
9292
l0 := info.Input[0]
9393
if l0.Level == 0 {
94-
atomic.AddUint32(&d.level0Comp, 1)
94+
d.level0Comp.Add(1)
9595
} else {
96-
atomic.AddUint32(&d.nonLevel0Comp, 1)
96+
d.nonLevel0Comp.Add(1)
9797
}
9898
d.activeComp++
9999
}
100100

101101
func (d *Database) onCompactionEnd(info pebble.CompactionInfo) {
102102
if d.activeComp == 1 {
103-
atomic.AddInt64(&d.compTime, int64(time.Since(d.compStartTime)))
103+
d.compTime.Add(int64(time.Since(d.compStartTime)))
104104
} else if d.activeComp == 0 {
105105
panic("should not happen")
106106
}
@@ -112,7 +112,7 @@ func (d *Database) onWriteStallBegin(b pebble.WriteStallBeginInfo) {
112112
}
113113

114114
func (d *Database) onWriteStallEnd() {
115-
atomic.AddInt64(&d.writeDelayTime, int64(time.Since(d.writeDelayStartTime)))
115+
d.writeDelayTime.Add(int64(time.Since(d.writeDelayStartTime)))
116116
}
117117

118118
// 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) {
407407
nWrite int64
408408

409409
metrics = d.db.Metrics()
410-
compTime = atomic.LoadInt64(&d.compTime)
411-
writeDelayCount = atomic.LoadInt64(&d.writeDelayCount)
412-
writeDelayTime = atomic.LoadInt64(&d.writeDelayTime)
413-
nonLevel0CompCount = int64(atomic.LoadUint32(&d.nonLevel0Comp))
414-
level0CompCount = int64(atomic.LoadUint32(&d.level0Comp))
410+
compTime = d.compTime.Load()
411+
writeDelayCount = d.writeDelayCount.Load()
412+
writeDelayTime = d.writeDelayTime.Load()
413+
nonLevel0CompCount = int64(d.nonLevel0Comp.Load())
414+
level0CompCount = int64(d.level0Comp.Load())
415415
)
416416
writeDelayTimes[i%2] = writeDelayTime
417417
writeDelayCounts[i%2] = writeDelayCount

0 commit comments

Comments
 (0)