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: Jakub Sztandera <kubuxu@protonmail.ch>
Jakub Sztandera committed
Aug 31, 2016 at 12:56 UTC
c4323c0bcf8e7a3222c1603e82c5a5746caab276
2 files changed
+18
-15
blocks/blockstore/arc_cache.go
+5
-2
@@ -3,6 +3,7 @@ package blockstore
3
import (
4
"github.com/ipfs/go-ipfs/blocks"
5
key "github.com/ipfs/go-ipfs/blocks/key"
6
+
7
ds "gx/ipfs/QmNgqJarToRiq2GBaPJhkmW4B5BxS5B74E1rkGvv2JoaTp/go-datastore"
8
lru "gx/ipfs/QmVYxfoJQiZijTgPNHCHgHELvQpbsJNTg6Crmc3dQkj3yy/golang-lru"
9
context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context"
@@ -95,15 +96,17 @@ func (b *arccache) Put(bl blocks.Block) error {
96
func (b *arccache) PutMany(bs []blocks.Block) error {
97
var good []blocks.Block
98
for _, block := range bs {
99
+ // call put on block if result is inconclusive or we are sure that
100
+ // the block isn't in storage
101
if has, ok := b.hasCached(block.Key()); !ok || (ok && !has) {
102
good = append(good, block)
103
}
104
}
102
- err := b.blockstore.PutMany(bs)
105
+ err := b.blockstore.PutMany(good)
106
if err != nil {
107
return err
108
}
106
- for _, block := range bs {
109
+ for _, block := range good {
110
b.arc.Add(block.Key(), true)
111
}
112
return nil
blocks/blockstore/bloom_cache.go
+13
-13
@@ -1,12 +1,13 @@
1
package blockstore
2
3
import (
4
+ "sync/atomic"
5
+
6
"github.com/ipfs/go-ipfs/blocks"
7
key "github.com/ipfs/go-ipfs/blocks/key"
8
+
9
bloom "gx/ipfs/QmWQ2SJisXwcCLsUXLwYCKSfyExXjFRW2WbBH5sqCUnwX5/bbloom"
10
context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context"
8
-
9
- "sync/atomic"
11
)
12
13
// bloomCached returns Blockstore that caches Has requests using Bloom filter
@@ -126,19 +127,18 @@ func (b *bloomcache) Put(bl blocks.Block) error {
127
}
128
129
func (b *bloomcache) PutMany(bs []blocks.Block) error {
129
- var good []blocks.Block
130
- for _, block := range bs {
131
- if has, ok := b.hasCached(block.Key()); !ok || (ok && !has) {
132
- good = append(good, block)
133
- }
134
- }
130
+ // bloom cache gives only conclusive resulty if key is not contained
131
+ // to reduce number of puts we need conclusive infomration if block is contained
132
+ // this means that PutMany can't be improved with bloom cache so we just
133
+ // just do a passthrough.
134
err := b.blockstore.PutMany(bs)
136
- if err == nil {
137
- for _, block := range bs {
138
- b.bloom.AddTS([]byte(block.Key()))
139
- }
135
+ if err != nil {
136
+ return err
137
}
141
- return err
138
+ for _, bl := range bs {
139
+ b.bloom.AddTS([]byte(bl.Key()))
140
+ }
141
+ return nil
142
}
143
144
func (b *bloomcache) AllKeysChan(ctx context.Context) (<-chan key.Key, error) {