fixed improper handling of cache miss

This commit is contained in:
Todd Gruben 2014-12-01 17:09:58 +00:00
parent 0225f6e798
commit bbc23c6543
2 changed files with 23 additions and 10 deletions

View file

@ -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})
}
}
}
}

View file

@ -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 {