diff options
author | Ben Johnson <benbjohnson@yahoo.com> | 2014-06-20 09:03:24 -0600 |
---|---|---|
committer | Ben Johnson <benbjohnson@yahoo.com> | 2014-06-20 09:03:24 -0600 |
commit | 0a59a754725b284a8ba75161a801a3dd535b4e27 (patch) | |
tree | fdde635f974c64649488abea2faa7fee781355a4 | |
parent | Merge pull request #202 from benbjohnson/refactor-split (diff) | |
parent | split the freelist page count stats to free and pending (diff) | |
download | dedo-0a59a754725b284a8ba75161a801a3dd535b4e27.tar.gz dedo-0a59a754725b284a8ba75161a801a3dd535b4e27.tar.xz |
Merge pull request #206 from Shopify/pending_page_stats
Split the freelist page count stats to free and pending
-rw-r--r-- | db.go | 3 | ||||
-rw-r--r-- | db_test.go | 3 | ||||
-rw-r--r-- | freelist.go | 12 | ||||
-rw-r--r-- | tx.go | 8 |
4 files changed, 20 insertions, 6 deletions
@@ -559,7 +559,8 @@ func (db *DB) allocate(count int) (*page, error) { // Stats represents statistics about the database. type Stats struct { // Freelist stats - FreePageN int // total number of free pages + FreePageN int // total number of free pages on the freelist + PendingPageN int // total number of pending pages on the freelist FreeAlloc int // total bytes allocated in free pages FreelistInuse int // total bytes used by the freelist @@ -254,7 +254,8 @@ func TestDB_Stats(t *testing.T) { }) stats := db.Stats() assert.Equal(t, 2, stats.TxStats.PageCount, "PageCount") - assert.Equal(t, 2, stats.FreePageN, "FreelistN") + assert.Equal(t, 0, stats.FreePageN, "FreePageN") + assert.Equal(t, 2, stats.PendingPageN, "PendingPageN") }) } diff --git a/freelist.go b/freelist.go index 3551113..6f05ac5 100644 --- a/freelist.go +++ b/freelist.go @@ -27,7 +27,17 @@ func (f *freelist) size() int { // count returns count of pages on the freelist func (f *freelist) count() int { - var count = len(f.ids) + return f.free_count() + f.pending_count() +} + +// free_count returns count of free pages +func (f *freelist) free_count() int { + return len(f.ids) +} + +// pending_count returns count of pending pages +func (f *freelist) pending_count() int { + var count int for _, list := range f.pending { count += len(list) } @@ -233,7 +233,8 @@ func (tx *Tx) rollback() { func (tx *Tx) close() { if tx.writable { // Grab freelist stats. - var freelistN = tx.db.freelist.count() + var freelistFreeN = tx.db.freelist.free_count() + var freelistPendingN = tx.db.freelist.pending_count() var freelistAlloc = tx.db.freelist.size() // Remove writer lock. @@ -241,8 +242,9 @@ func (tx *Tx) close() { // Merge statistics. tx.db.statlock.Lock() - tx.db.stats.FreePageN = freelistN - tx.db.stats.FreeAlloc = freelistN * tx.db.pageSize + tx.db.stats.FreePageN = freelistFreeN + tx.db.stats.PendingPageN = freelistPendingN + tx.db.stats.FreeAlloc = (freelistFreeN + freelistPendingN) * tx.db.pageSize tx.db.stats.FreelistInuse = freelistAlloc tx.db.stats.TxStats.add(&tx.stats) tx.db.statlock.Unlock() |