@@ -75,14 +75,14 @@ type Database struct {
75
75
76
76
log log.Logger // Contextual logger tracking the database path
77
77
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
86
86
}
87
87
88
88
func (d * Database ) onCompactionBegin (info pebble.CompactionInfo ) {
@@ -91,16 +91,16 @@ func (d *Database) onCompactionBegin(info pebble.CompactionInfo) {
91
91
}
92
92
l0 := info .Input [0 ]
93
93
if l0 .Level == 0 {
94
- atomic . AddUint32 ( & d .level0Comp , 1 )
94
+ d .level0Comp . Add ( 1 )
95
95
} else {
96
- atomic . AddUint32 ( & d .nonLevel0Comp , 1 )
96
+ d .nonLevel0Comp . Add ( 1 )
97
97
}
98
98
d .activeComp ++
99
99
}
100
100
101
101
func (d * Database ) onCompactionEnd (info pebble.CompactionInfo ) {
102
102
if d .activeComp == 1 {
103
- atomic . AddInt64 ( & d .compTime , int64 (time .Since (d .compStartTime )))
103
+ d .compTime . Add ( int64 (time .Since (d .compStartTime )))
104
104
} else if d .activeComp == 0 {
105
105
panic ("should not happen" )
106
106
}
@@ -112,7 +112,7 @@ func (d *Database) onWriteStallBegin(b pebble.WriteStallBeginInfo) {
112
112
}
113
113
114
114
func (d * Database ) onWriteStallEnd () {
115
- atomic . AddInt64 ( & d .writeDelayTime , int64 (time .Since (d .writeDelayStartTime )))
115
+ d .writeDelayTime . Add ( int64 (time .Since (d .writeDelayStartTime )))
116
116
}
117
117
118
118
// 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) {
407
407
nWrite int64
408
408
409
409
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 ( ))
415
415
)
416
416
writeDelayTimes [i % 2 ] = writeDelayTime
417
417
writeDelayCounts [i % 2 ] = writeDelayCount
0 commit comments