Merge pull request #12 from heyitsanthony/skip-freelist-overflow

freelist: read all free pages on count overflow
pull/17/head v1.3.1-coreos.0
Anthony Romano 2017-08-10 14:28:08 -07:00 committed by GitHub
commit 12923fe56c
2 changed files with 17 additions and 1 deletions

View File

@ -423,6 +423,22 @@ func TestBucket_Delete_FreelistOverflow(t *testing.T) {
}); err != nil {
t.Fatal(err)
}
// Check more than an overflow's worth of pages are freed.
stats := db.Stats()
freePages := stats.FreePageN + stats.PendingPageN
if freePages <= 0xFFFF {
t.Fatalf("expected more than 0xFFFF free pages, got %v", freePages)
}
// Free page count should be preserved on reopen.
if err := db.DB.Close(); err != nil {
t.Fatal(err)
}
db.MustReopen()
if reopenFreePages := db.Stats().FreePageN; freePages != reopenFreePages {
t.Fatalf("expected %d free pages, got %+v", freePages, db.Stats())
}
}
// Ensure that accessing and updating nested buckets is ok across transactions.

View File

@ -245,7 +245,7 @@ func (f *freelist) read(p *page) {
if count == 0 {
f.ids = nil
} else {
ids := ((*[maxAllocSize]pgid)(unsafe.Pointer(&p.ptr)))[idx:count]
ids := ((*[maxAllocSize]pgid)(unsafe.Pointer(&p.ptr)))[idx:idx+count]
f.ids = make([]pgid, len(ids))
copy(f.ids, ids)