aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Johnson <benbjohnson@yahoo.com>2014-06-20 09:03:24 -0600
committerBen Johnson <benbjohnson@yahoo.com>2014-06-20 09:03:24 -0600
commit0a59a754725b284a8ba75161a801a3dd535b4e27 (patch)
treefdde635f974c64649488abea2faa7fee781355a4
parentMerge pull request #202 from benbjohnson/refactor-split (diff)
parentsplit the freelist page count stats to free and pending (diff)
downloaddedo-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.go3
-rw-r--r--db_test.go3
-rw-r--r--freelist.go12
-rw-r--r--tx.go8
4 files changed, 20 insertions, 6 deletions
diff --git a/db.go b/db.go
index 9a125ee..d7037f9 100644
--- a/db.go
+++ b/db.go
@@ -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
diff --git a/db_test.go b/db_test.go
index b5c943e..0fc286b 100644
--- a/db_test.go
+++ b/db_test.go
@@ -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)
}
diff --git a/tx.go b/tx.go
index ac034ec..09077de 100644
--- a/tx.go
+++ b/tx.go
@@ -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()