1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-06-29 01:12:24 +08:00

blocks/blockstore: style cleanup of bloomcache

License: MIT
Signed-off-by: Jakub Sztandera <kubuxu@protonmail.ch>
This commit is contained in:
Jakub Sztandera
2016-07-04 20:34:46 +02:00
parent e92e6662a7
commit f13506c11a

View File

@ -76,32 +76,36 @@ func (b *bloomcache) DeleteBlock(k key.Key) error {
b.arc.Remove(k) // Invalidate cache before deleting. b.arc.Remove(k) // Invalidate cache before deleting.
err := b.blockstore.DeleteBlock(k) err := b.blockstore.DeleteBlock(k)
if err == nil { switch err {
case nil:
b.arc.Add(k, false) b.arc.Add(k, false)
} else if err == ds.ErrNotFound || err == ErrNotFound { case ds.ErrNotFound, ErrNotFound:
b.arc.Add(k, false) b.arc.Add(k, false)
return ErrNotFound default:
}
return err return err
}
return nil
} }
// if ok == false has is inconclusive // if ok == false has is inconclusive
// if ok == true then has respons to question: is it contained // if ok == true then has respons to question: is it contained
func (b *bloomcache) hasCached(k key.Key) (has bool, ok bool) { func (b *bloomcache) hasCached(k key.Key) (has bool, ok bool) {
if k == "" { if k == "" {
return true, true // Return cache invalid so call to blockstore
// in case of invalid key is forwarded deeper
return false, false
} }
if b.BloomActive() { if b.BloomActive() {
blr := b.bloom.HasTS([]byte(k)) blr := b.bloom.HasTS([]byte(k))
if blr == false { // not contained in bloom is only conclusive answer bloom gives if blr == false { // not contained in bloom is only conclusive answer bloom gives
return blr, true return false, true
} }
} }
h, ok := b.arc.Get(k) h, ok := b.arc.Get(k)
if ok { if ok {
return h.(bool), ok return h.(bool), ok
} else { } else {
return false, ok return false, false
} }
} }