mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
mvcc/backend: avoid unnecessary metrics update
https://github.com/coreos/etcd/pull/9300 Signed-off-by: Gyuho Lee <gyuhox@gmail.com>
This commit is contained in:
parent
84d11a51c1
commit
78a13e67a0
@ -225,15 +225,7 @@ func (b *backend) Commits() int64 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (b *backend) Defrag() error {
|
func (b *backend) Defrag() error {
|
||||||
err := b.defrag()
|
return b.defrag()
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// commit to update metadata like db.size
|
|
||||||
b.batchTx.Commit()
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *backend) defrag() error {
|
func (b *backend) defrag() error {
|
||||||
|
@ -160,25 +160,6 @@ func (t *batchTx) commit(stop bool) {
|
|||||||
// commit the last tx
|
// commit the last tx
|
||||||
if t.tx != nil {
|
if t.tx != nil {
|
||||||
if t.pending == 0 && !stop {
|
if t.pending == 0 && !stop {
|
||||||
t.backend.mu.RLock()
|
|
||||||
defer t.backend.mu.RUnlock()
|
|
||||||
|
|
||||||
// batchTx.commit(true) calls *bolt.Tx.Commit, which
|
|
||||||
// initializes *bolt.Tx.db and *bolt.Tx.meta as nil,
|
|
||||||
// and subsequent *bolt.Tx.Size() call panics.
|
|
||||||
//
|
|
||||||
// This nil pointer reference panic happens when:
|
|
||||||
// 1. batchTx.commit(false) from newBatchTx
|
|
||||||
// 2. batchTx.commit(true) from stopping backend
|
|
||||||
// 3. batchTx.commit(false) from inflight mvcc Hash call
|
|
||||||
//
|
|
||||||
// Check if db is nil to prevent this panic
|
|
||||||
if t.tx.DB() != nil {
|
|
||||||
size := t.tx.Size()
|
|
||||||
db := t.tx.DB()
|
|
||||||
atomic.StoreInt64(&t.backend.size, size)
|
|
||||||
atomic.StoreInt64(&t.backend.sizeInUse, size-(int64(db.Stats().FreePageN)*int64(db.Info().PageSize)))
|
|
||||||
}
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user