Skip to content

Commit

Permalink
Merge pull request etcd-io#12 from heyitsanthony/skip-freelist-overflow
Browse files Browse the repository at this point in the history
freelist: read all free pages on count overflow
  • Loading branch information
Anthony Romano committed Aug 10, 2017
2 parents b219ffc + 03f5e16 commit 12923fe
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
16 changes: 16 additions & 0 deletions bucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion freelist.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 12923fe

Please sign in to comment.