mirror of https://github.com/etcd-io/bbolt.git
drop mergeStats and move freelist stats update to Tx
parent
c105316292
commit
4918ce8301
16
db.go
16
db.go
|
@ -427,12 +427,16 @@ func (db *DB) removeTx(tx *Tx) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
n := len(db.txs)
|
||||||
|
|
||||||
// Unlock the meta pages.
|
// Unlock the meta pages.
|
||||||
db.metalock.Unlock()
|
db.metalock.Unlock()
|
||||||
|
|
||||||
// Merge statistics.
|
// Merge statistics.
|
||||||
db.mergeStats(&tx.stats)
|
db.statlock.Lock()
|
||||||
|
db.stats.OpenTxN = n
|
||||||
|
db.stats.TxStats.add(&tx.stats)
|
||||||
|
db.statlock.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update executes a function within the context of a read-write managed transaction.
|
// Update executes a function within the context of a read-write managed transaction.
|
||||||
|
@ -550,16 +554,6 @@ func (db *DB) allocate(count int) (*page, error) {
|
||||||
return p, nil
|
return p, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// mergeStats updates db stats in thread-safe manner.
|
|
||||||
func (db *DB) mergeStats(txStats *TxStats) {
|
|
||||||
db.statlock.Lock()
|
|
||||||
db.stats.FreelistN = db.freelist.count()
|
|
||||||
db.stats.FreelistAlloc = db.freelist.size()
|
|
||||||
db.stats.OpenTxN = len(db.txs)
|
|
||||||
db.stats.TxStats.add(txStats)
|
|
||||||
db.statlock.Unlock()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Stats represents statistics about the database.
|
// Stats represents statistics about the database.
|
||||||
type Stats struct {
|
type Stats struct {
|
||||||
// Freelist stats
|
// Freelist stats
|
||||||
|
|
10
tx.go
10
tx.go
|
@ -232,11 +232,19 @@ func (tx *Tx) rollback() {
|
||||||
|
|
||||||
func (tx *Tx) close() {
|
func (tx *Tx) close() {
|
||||||
if tx.writable {
|
if tx.writable {
|
||||||
|
// Grab freelist stats.
|
||||||
|
var freelistN = tx.db.freelist.count()
|
||||||
|
var freelistAlloc = tx.db.freelist.size()
|
||||||
|
|
||||||
// Remove writer lock.
|
// Remove writer lock.
|
||||||
tx.db.rwlock.Unlock()
|
tx.db.rwlock.Unlock()
|
||||||
|
|
||||||
// Merge statistics.
|
// Merge statistics.
|
||||||
tx.db.mergeStats(&tx.stats)
|
tx.db.statlock.Lock()
|
||||||
|
tx.db.stats.FreelistN = freelistN
|
||||||
|
tx.db.stats.FreelistAlloc = freelistAlloc
|
||||||
|
tx.db.stats.TxStats.add(&tx.stats)
|
||||||
|
tx.db.statlock.Unlock()
|
||||||
} else {
|
} else {
|
||||||
tx.db.removeTx(tx)
|
tx.db.removeTx(tx)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue