Skip to content
This repository has been archived by the owner on Mar 9, 2019. It is now read-only.

Commit

Permalink
Merge pull request #214 from Shopify/fix_stats_sub
Browse files Browse the repository at this point in the history
Copy the free pages stats from the receiver
  • Loading branch information
benbjohnson committed Jun 27, 2014
2 parents d1a77a9 + 8c386e7 commit e4ad031
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions db.go
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,10 @@ func (s *Stats) Sub(other *Stats) Stats {
return *s
}
var diff Stats
diff.FreePageN = s.FreePageN
diff.PendingPageN = s.PendingPageN
diff.FreeAlloc = s.FreeAlloc
diff.FreelistInuse = s.FreelistInuse
diff.TxN = other.TxN - s.TxN
diff.TxStats = s.TxStats.Sub(&other.TxStats)
return diff
Expand Down
4 changes: 4 additions & 0 deletions db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,9 +354,13 @@ func TestDB_String(t *testing.T) {
func TestDBStats_Sub(t *testing.T) {
var a, b Stats
a.TxStats.PageCount = 3
a.FreePageN = 4
b.TxStats.PageCount = 10
b.FreePageN = 14
diff := b.Sub(&a)
assert.Equal(t, 7, diff.TxStats.PageCount)
// free page stats are copied from the receiver and not subtracted
assert.Equal(t, 14, diff.FreePageN)
}

// Ensure that meta with bad magic is invalid.
Expand Down

0 comments on commit e4ad031

Please sign in to comment.