diff options
author | Ben Johnson <benbjohnson@yahoo.com> | 2014-07-10 14:16:26 -0600 |
---|---|---|
committer | Ben Johnson <benbjohnson@yahoo.com> | 2014-07-10 14:16:26 -0600 |
commit | 333c586ed07bea4e66cc89a8c1189232cad50d8e (patch) | |
tree | dd834956e2bc67ecd64aeb528348eed5ff3ca4a4 | |
parent | Merge branch 'master' of https://github.com/boltdb/bolt into free-cache (diff) | |
download | dedo-333c586ed07bea4e66cc89a8c1189232cad50d8e.tar.gz dedo-333c586ed07bea4e66cc89a8c1189232cad50d8e.tar.xz |
Clean up freelist reindex.
-rw-r--r-- | freelist.go | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/freelist.go b/freelist.go index 27aea6a..a297354 100644 --- a/freelist.go +++ b/freelist.go @@ -153,7 +153,7 @@ func (f *freelist) read(p *page) { f.ids = make([]pgid, len(ids)) copy(f.ids, 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 @@ -180,17 +180,19 @@ func (f *freelist) write(p *page) error { func (f *freelist) reload(p *page) { f.read(p) - // We need to filter out the pending pages from the available freelist - // so we rebuild the cache without the newly read freelist. - ids := f.ids - f.ids = nil - f.buildcache() + // Build a cache of only pending pages. + pcache := make(map[pgid]bool) + for _, pendingIDs := range f.pending { + for _, pendingID := range pendingIDs { + pcache[pendingID] = true + } + } // Check each page in the freelist and build a new available freelist // with any pages not in the pending lists. var a []pgid - for _, id := range ids { - if !f.freed(id) { + for _, id := range f.ids { + if !pcache[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 // it includes the available and pending free pages. - f.buildcache() + f.reindex() } -// buildcache rebuilds the free cache based on available and pending free lists. -func (f *freelist) buildcache() { +// reindex rebuilds the free cache based on available and pending free lists. +func (f *freelist) reindex() { f.cache = make(map[pgid]bool) for _, id := range f.ids { f.cache[id] = true |