diff --git a/index/brand.go b/index/brand.go index 58a5ad2b7..dd78e5ee0 100644 --- a/index/brand.go +++ b/index/brand.go @@ -31,7 +31,6 @@ type Brand struct { func NewBrand(db string, slice int, s Storage, threshold_len int, threshold int, skipp int) *Brand { f := new(Brand) - f.bitmap_cache = make(map[uint64]*Rank) f.storage = s f.slice = slice f.db = db @@ -40,10 +39,14 @@ func NewBrand(db string, slice int, s Storage, threshold_len int, threshold int, f.threshold_length = threshold_len f.threshold_idx = threshold f.skip = skipp + f.Clear() //alloc the cache return f } - +func (self *Brand) Clear() bool { + self.bitmap_cache = make(map[uint64]*Rank) + return true +} func (self *Brand) Get(bitmap_id uint64) IBitmap { bm, ok := self.bitmap_cache[bitmap_id] if ok { diff --git a/index/commands.go b/index/commands.go index 074f0ea57..86312a37f 100644 --- a/index/commands.go +++ b/index/commands.go @@ -191,3 +191,14 @@ func NewTopN(b BitmapHandle, n int) *CmdTopN { func (self *CmdTopN) Execute(f *Fragment) Calculation { return f.TopN(self.bitmap, self.n) } + +type CmdClear struct { + *Responder +} + +func NewClear() *CmdClear { + return &CmdClear{NewResponder("Clear")} +} +func (self *CmdClear) Execute(f *Fragment) Calculation { + return f.impl.Clear() +} diff --git a/index/fragment_container.go b/index/fragment_container.go index 052a6091c..3f4fee0d4 100644 --- a/index/fragment_container.go +++ b/index/fragment_container.go @@ -123,6 +123,15 @@ func (self *FragmentContainer) SetBit(frag_id SUUID, bitmap_id uint64, pos uint6 return false, errors.New("Invalid Bitmap Handle") } +func (self *FragmentContainer) Clear(frag_id SUUID) (bool, error) { + if fragment, found := self.GetFragment(frag_id); found { + request := NewClear() + fragment.requestChan <- request + return request.Response().answer.(bool), nil + } + return false, errors.New("Invalid Fragment ID") +} + func (self *FragmentContainer) AddFragment(db string, frame string, slice int, id SUUID) { log.Println("ADD FRAGMENT", frame) f := NewFragment(id, db, slice, frame) @@ -134,6 +143,7 @@ type Pilosa interface { Get(id uint64) IBitmap SetBit(id uint64, bit_pos uint64) bool TopN(b IBitmap, n int) []Pair + Clear() bool } type Fragment struct { diff --git a/index/fragment_container_test.go b/index/fragment_container_test.go index 3129b7875..16fb3c5a0 100644 --- a/index/fragment_container_test.go +++ b/index/fragment_container_test.go @@ -132,5 +132,9 @@ func TestFragment(t *testing.T) { So(1, ShouldEqual, 1) }) */ + Convey("Clear ", t, func() { + res, _ := dummy.Clear(general) + So(res, ShouldEqual, true) + }) } diff --git a/index/general.go b/index/general.go index 7bc642df7..88156a97a 100644 --- a/index/general.go +++ b/index/general.go @@ -11,13 +11,18 @@ type General struct { func NewGeneral(db string, slice int, s Storage) *General { f := new(General) - f.bitmap_cache = lru.New(10000) f.storage = s f.slice = slice f.db = db + f.Clear() + //f.bitmap_cache = lru.New(10000) return f } +func (self *General) Clear() bool { + self.bitmap_cache = lru.New(10000) + return true +} func (self *General) Get(bitmap_id uint64) IBitmap { bm, ok := self.bitmap_cache.Get(bitmap_id)