mirror of https://github.com/etcd-io/bbolt.git
update the freelist readIDs (#139)
parent
22d122a8b9
commit
c5638469ec
|
@ -2,3 +2,4 @@
|
|||
*.test
|
||||
*.swp
|
||||
/bin/
|
||||
cover.out
|
||||
|
|
|
@ -6,7 +6,8 @@ import (
|
|||
|
||||
func TestTx_allocatePageStats(t *testing.T) {
|
||||
f := newFreelist()
|
||||
f.ids = []pgid{2, 3}
|
||||
ids := []pgid{2, 3}
|
||||
f.readIDs(ids)
|
||||
|
||||
tx := &Tx{
|
||||
db: &DB{
|
||||
|
|
|
@ -260,7 +260,7 @@ func (f *freelist) read(p *page) {
|
|||
f.reindex()
|
||||
}
|
||||
|
||||
// read initializes the freelist from a given list of ids.
|
||||
// readIDs initializes the freelist from a given list of ids.
|
||||
func (f *freelist) readIDs(ids []pgid) {
|
||||
f.ids = ids
|
||||
f.reindex()
|
||||
|
@ -312,11 +312,8 @@ func (f *freelist) reload(p *page) {
|
|||
a = append(a, id)
|
||||
}
|
||||
}
|
||||
f.ids = a
|
||||
|
||||
// Once the available list is rebuilt then rebuild the free cache so that
|
||||
// it includes the available and pending free pages.
|
||||
f.reindex()
|
||||
f.readIDs(a)
|
||||
}
|
||||
|
||||
// reindex rebuilds the free cache based on available and pending free lists.
|
||||
|
|
|
@ -148,12 +148,13 @@ func TestFreelist_releaseRange(t *testing.T) {
|
|||
|
||||
for _, c := range releaseRangeTests {
|
||||
f := newFreelist()
|
||||
|
||||
var ids []pgid
|
||||
for _, p := range c.pagesIn {
|
||||
for i := uint64(0); i < uint64(p.n); i++ {
|
||||
f.ids = append(f.ids, pgid(uint64(p.id)+i))
|
||||
ids = append(ids, pgid(uint64(p.id)+i))
|
||||
}
|
||||
}
|
||||
f.readIDs(ids)
|
||||
for _, p := range c.pagesIn {
|
||||
f.allocate(p.allocTxn, p.n)
|
||||
}
|
||||
|
@ -175,7 +176,8 @@ func TestFreelist_releaseRange(t *testing.T) {
|
|||
// Ensure that a freelist can find contiguous blocks of pages.
|
||||
func TestFreelist_allocate(t *testing.T) {
|
||||
f := newFreelist()
|
||||
f.ids = []pgid{3, 4, 5, 6, 7, 9, 12, 13, 18}
|
||||
ids := []pgid{3, 4, 5, 6, 7, 9, 12, 13, 18}
|
||||
f.readIDs(ids)
|
||||
if id := int(f.allocate(1, 3)); id != 3 {
|
||||
t.Fatalf("exp=3; got=%v", id)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue