From bbc23c6543e78a5b7e6f2345f59670fc95e69f6c Mon Sep 17 00:00:00 2001 From: Todd Gruben Date: Mon, 1 Dec 2014 17:09:58 +0000 Subject: [PATCH] fixed improper handling of cache miss --- index/commands.go | 26 ++++++++++++++++++-------- index/fragment_container.go | 7 +++++-- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/index/commands.go b/index/commands.go index d8cad61ee..eae3c791e 100644 --- a/index/commands.go +++ b/index/commands.go @@ -4,6 +4,7 @@ import ( "bytes" "compress/gzip" "io/ioutil" + "log" "time" ) @@ -62,7 +63,10 @@ func NewCount(bitmap_handle BitmapHandle) *CmdCount { } func (self *CmdCount) Execute(f *Fragment) Calculation { - bm, _ := f.getBitmap(self.bitmap) + bm, ok := f.getBitmap(self.bitmap) + if ok == false { + return 0 + } return BitCount(bm) } @@ -133,8 +137,12 @@ func NewGetBytes(bh BitmapHandle) *CmdGetBytes { } func (self *CmdGetBytes) Execute(f *Fragment) Calculation { - bm, _ := f.getBitmap(self.bitmap) + bm, ok := f.getBitmap(self.bitmap) //*Compress it + if !ok { + bm = NewBitmap() + log.Println("cache miss") + } var b bytes.Buffer w := gzip.NewWriter(&b) w.Write(bm.ToBytes()) @@ -308,16 +316,18 @@ func (self *CmdTopFill) Execute(f *Fragment) Calculation { a := f.NewHandle(v) if self.args.Handle == 0 { // return just the count - bm, _ := f.getBitmap(a) - if bm.Count() > 0 { + bm, ok := f.getBitmap(a) + if ok && bm.Count() > 0 { result = append(result, Pair{v, bm.Count()}) } } else { res := f.intersect([]BitmapHandle{self.args.Handle, a}) - bm, _ := f.getBitmap(res) - bc := BitCount(bm) - if bc > 0 { - result = append(result, Pair{v, bc}) + bm, ok := f.getBitmap(res) + if ok { + bc := BitCount(bm) + if bc > 0 { + result = append(result, Pair{v, bc}) + } } } } diff --git a/index/fragment_container.go b/index/fragment_container.go index 6449be3fc..1a7e6fef8 100644 --- a/index/fragment_container.go +++ b/index/fragment_container.go @@ -345,7 +345,7 @@ func NewFragment(frag_id util.SUUID, db string, slice int, frame string) *Fragme f := new(Fragment) f.requestChan = make(chan Command, 64) f.fragment_id = frag_id - f.cache = lru.New(10000) + f.cache = lru.New(20000) f.impl = impl //NewGeneral(db, slice, NewMemoryStorage()) f.slice = slice f.exit = make(chan *sync.WaitGroup) @@ -355,7 +355,10 @@ func NewFragment(frag_id util.SUUID, db string, slice int, frame string) *Fragme func (self *Fragment) getBitmap(bitmap BitmapHandle) (IBitmap, bool) { bm, ok := self.cache.Get(bitmap) - return bm.(IBitmap), ok + if ok && bm != nil { + return bm.(IBitmap), ok + } + return NewBitmap(), false //cache fail but return ting em } func (self *Fragment) exists(bitmap_id uint64) bool {