Skip to content

Commit

Permalink
Merge pull request #65 from zrss/fix-page-cnt
Browse files Browse the repository at this point in the history
tx: fix the number of pages is incorrectly counted
  • Loading branch information
xiang90 authored Dec 7, 2017
2 parents b436469 + 22635d7 commit 48ea1b3
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
30 changes: 30 additions & 0 deletions allocate_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package bolt

import (
"testing"
)

func TestTx_allocatePageStats(t *testing.T) {
f := newFreelist()
f.ids = []pgid{2, 3}

tx := &Tx{
db: &DB{
freelist: f,
pageSize: defaultPageSize,
},
meta: &meta{},
pages: make(map[pgid]*page),
}

prePageCnt := tx.Stats().PageCount
allocateCnt := f.free_count()

if _, err := tx.allocate(allocateCnt); err != nil {
t.Fatal(err)
}

if tx.Stats().PageCount != prePageCnt+allocateCnt {
t.Errorf("Allocated %d but got %d page in stats", allocateCnt, tx.Stats().PageCount)
}
}
2 changes: 1 addition & 1 deletion tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ func (tx *Tx) allocate(count int) (*page, error) {
tx.pages[p.id] = p

// Update statistics.
tx.stats.PageCount++
tx.stats.PageCount += count
tx.stats.PageAlloc += count * tx.db.pageSize

return p, nil
Expand Down

0 comments on commit 48ea1b3

Please sign in to comment.