mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
mvcc: use GaugeFunc metric to load db size when requested
Relying on mvcc to set the db size metric can cause it to miss size changes when a txn commits after the last write completes before a quiescent period. Instead, load the db size on demand. Fixes #8146
This commit is contained in:
parent
4e6c77185b
commit
522e75cb4f
@ -251,6 +251,11 @@ func (s *store) Restore(b backend.Backend) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *store) restore() error {
|
func (s *store) restore() error {
|
||||||
|
reportDbTotalSizeInBytesMu.Lock()
|
||||||
|
b := s.b
|
||||||
|
reportDbTotalSizeInBytes = func() float64 { return float64(b.Size()) }
|
||||||
|
reportDbTotalSizeInBytesMu.Unlock()
|
||||||
|
|
||||||
min, max := newRevBytes(), newRevBytes()
|
min, max := newRevBytes(), newRevBytes()
|
||||||
revToBytes(revision{main: 1}, min)
|
revToBytes(revision{main: 1}, min)
|
||||||
revToBytes(revision{main: math.MaxInt64, sub: math.MaxInt64}, max)
|
revToBytes(revision{main: math.MaxInt64, sub: math.MaxInt64}, max)
|
||||||
@ -261,8 +266,6 @@ func (s *store) restore() error {
|
|||||||
tx := s.b.BatchTx()
|
tx := s.b.BatchTx()
|
||||||
tx.Lock()
|
tx.Lock()
|
||||||
|
|
||||||
dbTotalSize.Set(float64(s.b.Size()))
|
|
||||||
|
|
||||||
_, finishedCompactBytes := tx.UnsafeRange(metaBucketName, finishedCompactKeyName, nil, 0)
|
_, finishedCompactBytes := tx.UnsafeRange(metaBucketName, finishedCompactKeyName, nil, 0)
|
||||||
if len(finishedCompactBytes) != 0 {
|
if len(finishedCompactBytes) != 0 {
|
||||||
s.compactMainRev = bytesToRev(finishedCompactBytes[0]).main
|
s.compactMainRev = bytesToRev(finishedCompactBytes[0]).main
|
||||||
|
@ -105,7 +105,6 @@ func (tw *storeTxnWrite) End() {
|
|||||||
if len(tw.changes) != 0 {
|
if len(tw.changes) != 0 {
|
||||||
tw.s.revMu.Unlock()
|
tw.s.revMu.Unlock()
|
||||||
}
|
}
|
||||||
dbTotalSize.Set(float64(tw.s.b.Size()))
|
|
||||||
tw.s.mu.RUnlock()
|
tw.s.mu.RUnlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,6 +15,8 @@
|
|||||||
package mvcc
|
package mvcc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"sync"
|
||||||
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -129,12 +131,21 @@ var (
|
|||||||
Buckets: prometheus.ExponentialBuckets(100, 2, 14),
|
Buckets: prometheus.ExponentialBuckets(100, 2, 14),
|
||||||
})
|
})
|
||||||
|
|
||||||
dbTotalSize = prometheus.NewGauge(prometheus.GaugeOpts{
|
dbTotalSize = prometheus.NewGaugeFunc(prometheus.GaugeOpts{
|
||||||
Namespace: "etcd_debugging",
|
Namespace: "etcd_debugging",
|
||||||
Subsystem: "mvcc",
|
Subsystem: "mvcc",
|
||||||
Name: "db_total_size_in_bytes",
|
Name: "db_total_size_in_bytes",
|
||||||
Help: "Total size of the underlying database in bytes.",
|
Help: "Total size of the underlying database in bytes.",
|
||||||
})
|
},
|
||||||
|
func() float64 {
|
||||||
|
reportDbTotalSizeInBytesMu.RLock()
|
||||||
|
defer reportDbTotalSizeInBytesMu.RUnlock()
|
||||||
|
return reportDbTotalSizeInBytes()
|
||||||
|
},
|
||||||
|
)
|
||||||
|
// overridden by mvcc initialization
|
||||||
|
reportDbTotalSizeInBytesMu sync.RWMutex
|
||||||
|
reportDbTotalSizeInBytes func() float64 = func() float64 { return 0 }
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user