Clean up freelist reindex.

pull/34/head
Ben Johnson 2014-07-10 14:16:26 -06:00
parent cc8004c980
commit 333c586ed0
1 changed files with 13 additions and 11 deletions

View File

@ -153,7 +153,7 @@ func (f *freelist) read(p *page) {
f.ids = make([]pgid, len(ids)) f.ids = make([]pgid, len(ids))
copy(f.ids, ids) copy(f.ids, ids)
sort.Sort(pgids(f.ids)) sort.Sort(pgids(f.ids))
f.buildcache() f.reindex()
} }
// write writes the page ids onto a freelist page. All free and pending ids are // write writes the page ids onto a freelist page. All free and pending ids are
@ -180,17 +180,19 @@ func (f *freelist) write(p *page) error {
func (f *freelist) reload(p *page) { func (f *freelist) reload(p *page) {
f.read(p) f.read(p)
// We need to filter out the pending pages from the available freelist // Build a cache of only pending pages.
// so we rebuild the cache without the newly read freelist. pcache := make(map[pgid]bool)
ids := f.ids for _, pendingIDs := range f.pending {
f.ids = nil for _, pendingID := range pendingIDs {
f.buildcache() pcache[pendingID] = true
}
}
// Check each page in the freelist and build a new available freelist // Check each page in the freelist and build a new available freelist
// with any pages not in the pending lists. // with any pages not in the pending lists.
var a []pgid var a []pgid
for _, id := range ids { for _, id := range f.ids {
if !f.freed(id) { if !pcache[id] {
a = append(a, id) a = append(a, id)
} }
} }
@ -198,11 +200,11 @@ func (f *freelist) reload(p *page) {
// Once the available list is rebuilt then rebuild the free cache so that // Once the available list is rebuilt then rebuild the free cache so that
// it includes the available and pending free pages. // it includes the available and pending free pages.
f.buildcache() f.reindex()
} }
// buildcache rebuilds the free cache based on available and pending free lists. // reindex rebuilds the free cache based on available and pending free lists.
func (f *freelist) buildcache() { func (f *freelist) reindex() {
f.cache = make(map[pgid]bool) f.cache = make(map[pgid]bool)
for _, id := range f.ids { for _, id := range f.ids {
f.cache[id] = true f.cache[id] = true