blockstore: fix PutMany with cache logic

Thanks @whyrusleeping for noticing it.

Removed PutMany logic in bloom cache as it can't help with anything.
Fixed ARC cache to use filtered results instad of all blocks.

License: MIT
Signed-off-by: default avatarJakub Sztandera <kubuxu@protonmail.ch>
parent 3303fea6
......@@ -3,6 +3,7 @@ package blockstore
import (
"github.com/ipfs/go-ipfs/blocks"
key "github.com/ipfs/go-ipfs/blocks/key"
ds "gx/ipfs/QmNgqJarToRiq2GBaPJhkmW4B5BxS5B74E1rkGvv2JoaTp/go-datastore"
lru "gx/ipfs/QmVYxfoJQiZijTgPNHCHgHELvQpbsJNTg6Crmc3dQkj3yy/golang-lru"
context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context"
......@@ -95,15 +96,17 @@ func (b *arccache) Put(bl blocks.Block) error {
func (b *arccache) PutMany(bs []blocks.Block) error {
var good []blocks.Block
for _, block := range bs {
// call put on block if result is inconclusive or we are sure that
// the block isn't in storage
if has, ok := b.hasCached(block.Key()); !ok || (ok && !has) {
good = append(good, block)
}
}
err := b.blockstore.PutMany(bs)
err := b.blockstore.PutMany(good)
if err != nil {
return err
}
for _, block := range bs {
for _, block := range good {
b.arc.Add(block.Key(), true)
}
return nil
......
package blockstore
import (
"sync/atomic"
"github.com/ipfs/go-ipfs/blocks"
key "github.com/ipfs/go-ipfs/blocks/key"
bloom "gx/ipfs/QmWQ2SJisXwcCLsUXLwYCKSfyExXjFRW2WbBH5sqCUnwX5/bbloom"
context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context"
"sync/atomic"
)
// bloomCached returns Blockstore that caches Has requests using Bloom filter
......@@ -126,19 +127,18 @@ func (b *bloomcache) Put(bl blocks.Block) error {
}
func (b *bloomcache) PutMany(bs []blocks.Block) error {
var good []blocks.Block
for _, block := range bs {
if has, ok := b.hasCached(block.Key()); !ok || (ok && !has) {
good = append(good, block)
}
}
// bloom cache gives only conclusive resulty if key is not contained
// to reduce number of puts we need conclusive infomration if block is contained
// this means that PutMany can't be improved with bloom cache so we just
// just do a passthrough.
err := b.blockstore.PutMany(bs)
if err == nil {
for _, block := range bs {
b.bloom.AddTS([]byte(block.Key()))
}
if err != nil {
return err
}
return err
for _, bl := range bs {
b.bloom.AddTS([]byte(bl.Key()))
}
return nil
}
func (b *bloomcache) AllKeysChan(ctx context.Context) (<-chan key.Key, error) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment