@cryptotaxi247 / kubo / commits / 758e00bc4

Extract blocks/blockstore package to go-ipfs-blockstore

This extracts the blocks/blockstore package and renames the blocks/blockstore/util package to /blocks/blockstoreutil (because util depends on Pin and I don't plan to extract Pin and its depedencies). The history of blocks/blockstore has been preserved. It has been gx'ed and imported. Imports have been rewritten accordingly and re-ordered. License: MIT Signed-off-by: Hector Sanjuan <hector@protocol.ai>

Hector Sanjuan committed Feb 15, 2018 at 18:03 UTC 758e00bc4ccd5b99beed9ffc93f5c9a3a9207e7c
42 files changed +61 -1409
blocks/blockstore/arc_cache.go deleted
-156
@@ -1,156 +0,0 @@
1 -package blockstore
2 -
3 -import (
4 - "context"
5 -
6 - "gx/ipfs/Qmej7nf81hi2x2tvjRBF3mcp74sQyuDH4VMYDGd1YtXjb2/go-block-format"
7 -
8 - ds "gx/ipfs/QmPpegoMqhAEqjncrzArm7KVWAkCm78rqL2DPuNjhPrshg/go-datastore"
9 - "gx/ipfs/QmRg1gKTHzc3CZXSKzem8aR4E3TubFhbgXwfVuWnSK5CC5/go-metrics-interface"
10 - lru "gx/ipfs/QmVYxfoJQiZijTgPNHCHgHELvQpbsJNTg6Crmc3dQkj3yy/golang-lru"
11 - cid "gx/ipfs/QmcZfnkapfECQGcLZaf9B79NRg7cRa9EnZh4LSbkCzwNvY/go-cid"
12 -)
13 -
14 -// arccache wraps a BlockStore with an Adaptive Replacement Cache (ARC) for
15 -// block Cids. This provides block access-time improvements, allowing
16 -// to short-cut many searches without query-ing the underlying datastore.
17 -type arccache struct {
18 - arc *lru.ARCCache
19 - blockstore Blockstore
20 -
21 - hits metrics.Counter
22 - total metrics.Counter
23 -}
24 -
25 -func newARCCachedBS(ctx context.Context, bs Blockstore, lruSize int) (*arccache, error) {
26 - arc, err := lru.NewARC(lruSize)
27 - if err != nil {
28 - return nil, err
29 - }
30 - c := &arccache{arc: arc, blockstore: bs}
31 - c.hits = metrics.NewCtx(ctx, "arc.hits_total", "Number of ARC cache hits").Counter()
32 - c.total = metrics.NewCtx(ctx, "arc_total", "Total number of ARC cache requests").Counter()
33 -
34 - return c, nil
35 -}
36 -
37 -func (b *arccache) DeleteBlock(k *cid.Cid) error {
38 - if has, ok := b.hasCached(k); ok && !has {
39 - return ErrNotFound
40 - }
41 -
42 - b.arc.Remove(k) // Invalidate cache before deleting.
43 - err := b.blockstore.DeleteBlock(k)
44 - switch err {
45 - case nil, ds.ErrNotFound, ErrNotFound:
46 - b.addCache(k, false)
47 - return err
48 - default:
49 - return err
50 - }
51 -}
52 -
53 -// if ok == false has is inconclusive
54 -// if ok == true then has respons to question: is it contained
55 -func (b *arccache) hasCached(k *cid.Cid) (has bool, ok bool) {
56 - b.total.Inc()
57 - if k == nil {
58 - log.Error("nil cid in arccache")
59 - // Return cache invalid so the call to blockstore happens
60 - // in case of invalid key and correct error is created.
61 - return false, false
62 - }
63 -
64 - h, ok := b.arc.Get(k.KeyString())
65 - if ok {
66 - b.hits.Inc()
67 - return h.(bool), true
68 - }
69 - return false, false
70 -}
71 -
72 -func (b *arccache) Has(k *cid.Cid) (bool, error) {
73 - if has, ok := b.hasCached(k); ok {
74 - return has, nil
75 - }
76 -
77 - res, err := b.blockstore.Has(k)
78 - if err == nil {
79 - b.addCache(k, res)
80 - }
81 - return res, err
82 -}
83 -
84 -func (b *arccache) Get(k *cid.Cid) (blocks.Block, error) {
85 - if k == nil {
86 - log.Error("nil cid in arc cache")
87 - return nil, ErrNotFound
88 - }
89 -
90 - if has, ok := b.hasCached(k); ok && !has {
91 - return nil, ErrNotFound
92 - }
93 -
94 - bl, err := b.blockstore.Get(k)
95 - if bl == nil && err == ErrNotFound {
96 - b.addCache(k, false)
97 - } else if bl != nil {
98 - b.addCache(k, true)
99 - }
100 - return bl, err
101 -}
102 -
103 -func (b *arccache) Put(bl blocks.Block) error {
104 - if has, ok := b.hasCached(bl.Cid()); ok && has {
105 - return nil
106 - }
107 -
108 - err := b.blockstore.Put(bl)
109 - if err == nil {
110 - b.addCache(bl.Cid(), true)
111 - }
112 - return err
113 -}
114 -
115 -func (b *arccache) PutMany(bs []blocks.Block) error {
116 - var good []blocks.Block
117 - for _, block := range bs {
118 - // call put on block if result is inconclusive or we are sure that
119 - // the block isn't in storage
120 - if has, ok := b.hasCached(block.Cid()); !ok || (ok && !has) {
121 - good = append(good, block)
122 - }
123 - }
124 - err := b.blockstore.PutMany(good)
125 - if err != nil {
126 - return err
127 - }
128 - for _, block := range good {
129 - b.addCache(block.Cid(), true)
130 - }
131 - return nil
132 -}
133 -
134 -func (b *arccache) HashOnRead(enabled bool) {
135 - b.blockstore.HashOnRead(enabled)
136 -}
137 -
138 -func (b *arccache) addCache(c *cid.Cid, has bool) {
139 - b.arc.Add(c.KeyString(), has)
140 -}
141 -
142 -func (b *arccache) AllKeysChan(ctx context.Context) (<-chan *cid.Cid, error) {
143 - return b.blockstore.AllKeysChan(ctx)
144 -}
145 -
146 -func (b *arccache) GCLock() Unlocker {
147 - return b.blockstore.(GCBlockstore).GCLock()
148 -}
149 -
150 -func (b *arccache) PinLock() Unlocker {
151 - return b.blockstore.(GCBlockstore).PinLock()
152 -}
153 -
154 -func (b *arccache) GCRequested() bool {
155 - return b.blockstore.(GCBlockstore).GCRequested()
156 -}
blocks/blockstore/arc_cache_test.go deleted
-201
@@ -1,201 +0,0 @@
1 -package blockstore
2 -
3 -import (
4 - "context"
5 - "testing"
6 -
7 - "gx/ipfs/Qmej7nf81hi2x2tvjRBF3mcp74sQyuDH4VMYDGd1YtXjb2/go-block-format"
8 -
9 - ds "gx/ipfs/QmPpegoMqhAEqjncrzArm7KVWAkCm78rqL2DPuNjhPrshg/go-datastore"
10 - syncds "gx/ipfs/QmPpegoMqhAEqjncrzArm7KVWAkCm78rqL2DPuNjhPrshg/go-datastore/sync"
11 - cid "gx/ipfs/QmcZfnkapfECQGcLZaf9B79NRg7cRa9EnZh4LSbkCzwNvY/go-cid"
12 -)
13 -
14 -var exampleBlock = blocks.NewBlock([]byte("foo"))
15 -
16 -func testArcCached(ctx context.Context, bs Blockstore) (*arccache, error) {
17 - if ctx == nil {
18 - ctx = context.TODO()
19 - }
20 - opts := DefaultCacheOpts()
21 - opts.HasBloomFilterSize = 0
22 - opts.HasBloomFilterHashes = 0
23 - bbs, err := CachedBlockstore(ctx, bs, opts)
24 - if err == nil {
25 - return bbs.(*arccache), nil
26 - }
27 - return nil, err
28 -}
29 -
30 -func createStores(t *testing.T) (*arccache, Blockstore, *callbackDatastore) {
31 - cd := &callbackDatastore{f: func() {}, ds: ds.NewMapDatastore()}
32 - bs := NewBlockstore(syncds.MutexWrap(cd))
33 - arc, err := testArcCached(context.TODO(), bs)
34 - if err != nil {
35 - t.Fatal(err)
36 - }
37 - return arc, bs, cd
38 -}
39 -
40 -func trap(message string, cd *callbackDatastore, t *testing.T) {
41 - cd.SetFunc(func() {
42 - t.Fatal(message)
43 - })
44 -}
45 -func untrap(cd *callbackDatastore) {
46 - cd.SetFunc(func() {})
47 -}
48 -
49 -func TestRemoveCacheEntryOnDelete(t *testing.T) {
50 - arc, _, cd := createStores(t)
51 -
52 - arc.Put(exampleBlock)
53 -
54 - cd.Lock()
55 - writeHitTheDatastore := false
56 - cd.Unlock()
57 -
58 - cd.SetFunc(func() {
59 - writeHitTheDatastore = true
60 - })
61 -
62 - arc.DeleteBlock(exampleBlock.Cid())
63 - arc.Put(exampleBlock)
64 - if !writeHitTheDatastore {
65 - t.Fail()
66 - }
67 -}
68 -
69 -func TestElideDuplicateWrite(t *testing.T) {
70 - arc, _, cd := createStores(t)
71 -
72 - arc.Put(exampleBlock)
73 - trap("write hit datastore", cd, t)
74 - arc.Put(exampleBlock)
75 -}
76 -
77 -func TestHasRequestTriggersCache(t *testing.T) {
78 - arc, _, cd := createStores(t)
79 -
80 - arc.Has(exampleBlock.Cid())
81 - trap("has hit datastore", cd, t)
82 - if has, err := arc.Has(exampleBlock.Cid()); has || err != nil {
83 - t.Fatal("has was true but there is no such block")
84 - }
85 -
86 - untrap(cd)
87 - err := arc.Put(exampleBlock)
88 - if err != nil {
89 - t.Fatal(err)
90 - }
91 -
92 - trap("has hit datastore", cd, t)
93 -
94 - if has, err := arc.Has(exampleBlock.Cid()); !has || err != nil {
95 - t.Fatal("has returned invalid result")
96 - }
97 -}
98 -
99 -func TestGetFillsCache(t *testing.T) {
100 - arc, _, cd := createStores(t)
101 -
102 - if bl, err := arc.Get(exampleBlock.Cid()); bl != nil || err == nil {
103 - t.Fatal("block was found or there was no error")
104 - }
105 -
106 - trap("has hit datastore", cd, t)
107 -
108 - if has, err := arc.Has(exampleBlock.Cid()); has || err != nil {
109 - t.Fatal("has was true but there is no such block")
110 - }
111 -
112 - untrap(cd)
113 -
114 - if err := arc.Put(exampleBlock); err != nil {
115 - t.Fatal(err)
116 - }
117 -
118 - trap("has hit datastore", cd, t)
119 -
120 - if has, err := arc.Has(exampleBlock.Cid()); !has || err != nil {
121 - t.Fatal("has returned invalid result")
122 - }
123 -}
124 -
125 -func TestGetAndDeleteFalseShortCircuit(t *testing.T) {
126 - arc, _, cd := createStores(t)
127 -
128 - arc.Has(exampleBlock.Cid())
129 -
130 - trap("get hit datastore", cd, t)
131 -
132 - if bl, err := arc.Get(exampleBlock.Cid()); bl != nil || err != ErrNotFound {
133 - t.Fatal("get returned invalid result")
134 - }
135 -
136 - if arc.DeleteBlock(exampleBlock.Cid()) != ErrNotFound {
137 - t.Fatal("expected ErrNotFound error")
138 - }
139 -}
140 -
141 -func TestArcCreationFailure(t *testing.T) {
142 - if arc, err := newARCCachedBS(context.TODO(), nil, -1); arc != nil || err == nil {
143 - t.Fatal("expected error and no cache")
144 - }
145 -}
146 -
147 -func TestInvalidKey(t *testing.T) {
148 - arc, _, _ := createStores(t)
149 -
150 - bl, err := arc.Get(nil)
151 -
152 - if bl != nil {
153 - t.Fatal("blocks should be nil")
154 - }
155 - if err == nil {
156 - t.Fatal("expected error")
157 - }
158 -}
159 -
160 -func TestHasAfterSucessfulGetIsCached(t *testing.T) {
161 - arc, bs, cd := createStores(t)
162 -
163 - bs.Put(exampleBlock)
164 -
165 - arc.Get(exampleBlock.Cid())
166 -
167 - trap("has hit datastore", cd, t)
168 - arc.Has(exampleBlock.Cid())
169 -}
170 -
171 -func TestDifferentKeyObjectsWork(t *testing.T) {
172 - arc, bs, cd := createStores(t)
173 -
174 - bs.Put(exampleBlock)
175 -
176 - arc.Get(exampleBlock.Cid())
177 -
178 - trap("has hit datastore", cd, t)
179 - cidstr := exampleBlock.Cid().String()
180 -
181 - ncid, err := cid.Decode(cidstr)
182 - if err != nil {
183 - t.Fatal(err)
184 - }
185 -
186 - arc.Has(ncid)
187 -}
188 -
189 -func TestPutManyCaches(t *testing.T) {
190 - arc, _, cd := createStores(t)
191 - arc.PutMany([]blocks.Block{exampleBlock})
192 -
193 - trap("has hit datastore", cd, t)
194 - arc.Has(exampleBlock.Cid())
195 - untrap(cd)
196 - arc.DeleteBlock(exampleBlock.Cid())
197 -
198 - arc.Put(exampleBlock)
199 - trap("PunMany has hit datastore", cd, t)
200 - arc.PutMany([]blocks.Block{exampleBlock})
201 -}
blocks/blockstore/blockstore.go deleted
-282
@@ -1,282 +0,0 @@
1 -// Package blockstore implements a thin wrapper over a datastore, giving a
2 -// clean interface for Getting and Putting block objects.
3 -package blockstore
4 -
5 -import (
6 - "context"
7 - "errors"
8 - "sync"
9 - "sync/atomic"
10 -
11 - ds "gx/ipfs/QmPpegoMqhAEqjncrzArm7KVWAkCm78rqL2DPuNjhPrshg/go-datastore"
12 - dsns "gx/ipfs/QmPpegoMqhAEqjncrzArm7KVWAkCm78rqL2DPuNjhPrshg/go-datastore/namespace"
13 - dsq "gx/ipfs/QmPpegoMqhAEqjncrzArm7KVWAkCm78rqL2DPuNjhPrshg/go-datastore/query"
14 - logging "gx/ipfs/QmRb5jh8z2E8hMGN2tkvs1yHynUanqnZ3UeKwgN1i9P1F8/go-log"
15 - cid "gx/ipfs/QmcZfnkapfECQGcLZaf9B79NRg7cRa9EnZh4LSbkCzwNvY/go-cid"
16 - dshelp "gx/ipfs/QmdQTPWduSeyveSxeCAte33M592isSW5Z979g81aJphrgn/go-ipfs-ds-help"
17 - blocks "gx/ipfs/Qmej7nf81hi2x2tvjRBF3mcp74sQyuDH4VMYDGd1YtXjb2/go-block-format"
18 -)
19 -
20 -var log = logging.Logger("blockstore")
21 -
22 -// BlockPrefix namespaces blockstore datastores
23 -var BlockPrefix = ds.NewKey("blocks")
24 -
25 -// ErrValueTypeMismatch is an error returned when the item retrieved from
26 -// the datatstore is not a block.
27 -var ErrValueTypeMismatch = errors.New("the retrieved value is not a Block")
28 -
29 -// ErrHashMismatch is an error returned when the hash of a block
30 -// is different than expected.
31 -var ErrHashMismatch = errors.New("block in storage has different hash than requested")
32 -
33 -// ErrNotFound is an error returned when a block is not found.
34 -var ErrNotFound = errors.New("blockstore: block not found")
35 -
36 -// Blockstore wraps a Datastore block-centered methods and provides a layer
37 -// of abstraction which allows to add different caching strategies.
38 -type Blockstore interface {
39 - DeleteBlock(*cid.Cid) error
40 - Has(*cid.Cid) (bool, error)
41 - Get(*cid.Cid) (blocks.Block, error)
42 -
43 - // Put puts a given block to the underlying datastore
44 - Put(blocks.Block) error
45 -
46 - // PutMany puts a slice of blocks at the same time using batching
47 - // capabilities of the underlying datastore whenever possible.
48 - PutMany([]blocks.Block) error
49 -
50 - // AllKeysChan returns a channel from which
51 - // the CIDs in the Blockstore can be read. It should respect
52 - // the given context, closing the channel if it becomes Done.
53 - AllKeysChan(ctx context.Context) (<-chan *cid.Cid, error)
54 -
55 - // HashOnRead specifies if every read block should be
56 - // rehashed to make sure it matches its CID.
57 - HashOnRead(enabled bool)
58 -}
59 -
60 -// GCLocker abstract functionality to lock a blockstore when performing
61 -// garbage-collection operations.
62 -type GCLocker interface {
63 - // GCLock locks the blockstore for garbage collection. No operations
64 - // that expect to finish with a pin should ocurr simultaneously.
65 - // Reading during GC is safe, and requires no lock.
66 - GCLock() Unlocker
67 -
68 - // PinLock locks the blockstore for sequences of puts expected to finish
69 - // with a pin (before GC). Multiple put->pin sequences can write through
70 - // at the same time, but no GC should not happen simulatenously.
71 - // Reading during Pinning is safe, and requires no lock.
72 - PinLock() Unlocker
73 -
74 - // GcRequested returns true if GCLock has been called and is waiting to
75 - // take the lock
76 - GCRequested() bool
77 -}
78 -
79 -// GCBlockstore is a blockstore that can safely run garbage-collection
80 -// operations.
81 -type GCBlockstore interface {
82 - Blockstore
83 - GCLocker
84 -}
85 -
86 -// NewGCBlockstore returns a default implementation of GCBlockstore
87 -// using the given Blockstore and GCLocker.
88 -func NewGCBlockstore(bs Blockstore, gcl GCLocker) GCBlockstore {
89 - return gcBlockstore{bs, gcl}
90 -}
91 -
92 -type gcBlockstore struct {
93 - Blockstore
94 - GCLocker
95 -}
96 -
97 -// NewBlockstore returns a default Blockstore implementation
98 -// using the provided datastore.Batching backend.
99 -func NewBlockstore(d ds.Batching) Blockstore {
100 - var dsb ds.Batching
101 - dd := dsns.Wrap(d, BlockPrefix)
102 - dsb = dd
103 - return &blockstore{
104 - datastore: dsb,
105 - }
106 -}
107 -
108 -type blockstore struct {
109 - datastore ds.Batching
110 -
111 - rehash bool
112 -}
113 -
114 -func (bs *blockstore) HashOnRead(enabled bool) {
115 - bs.rehash = enabled
116 -}
117 -
118 -func (bs *blockstore) Get(k *cid.Cid) (blocks.Block, error) {
119 - if k == nil {
120 - log.Error("nil cid in blockstore")
121 - return nil, ErrNotFound
122 - }
123 -
124 - maybeData, err := bs.datastore.Get(dshelp.CidToDsKey(k))
125 - if err == ds.ErrNotFound {
126 - return nil, ErrNotFound
127 - }
128 - if err != nil {
129 - return nil, err
130 - }
131 - bdata, ok := maybeData.([]byte)
132 - if !ok {
133 - return nil, ErrValueTypeMismatch
134 - }
135 -
136 - if bs.rehash {
137 - rbcid, err := k.Prefix().Sum(bdata)
138 - if err != nil {
139 - return nil, err
140 - }
141 -
142 - if !rbcid.Equals(k) {
143 - return nil, ErrHashMismatch
144 - }
145 -
146 - return blocks.NewBlockWithCid(bdata, rbcid)
147 - }
148 - return blocks.NewBlockWithCid(bdata, k)
149 -}
150 -
151 -func (bs *blockstore) Put(block blocks.Block) error {
152 - k := dshelp.CidToDsKey(block.Cid())
153 -
154 - // Has is cheaper than Put, so see if we already have it
155 - exists, err := bs.datastore.Has(k)
156 - if err == nil && exists {
157 - return nil // already stored.
158 - }
159 - return bs.datastore.Put(k, block.RawData())
160 -}
161 -
162 -func (bs *blockstore) PutMany(blocks []blocks.Block) error {
163 - t, err := bs.datastore.Batch()
164 - if err != nil {
165 - return err
166 - }
167 - for _, b := range blocks {
168 - k := dshelp.CidToDsKey(b.Cid())
169 - exists, err := bs.datastore.Has(k)
170 - if err == nil && exists {
171 - continue
172 - }
173 -
174 - err = t.Put(k, b.RawData())
175 - if err != nil {
176 - return err
177 - }
178 - }
179 - return t.Commit()
180 -}
181 -
182 -func (bs *blockstore) Has(k *cid.Cid) (bool, error) {
183 - return bs.datastore.Has(dshelp.CidToDsKey(k))
184 -}
185 -
186 -func (bs *blockstore) DeleteBlock(k *cid.Cid) error {
187 - err := bs.datastore.Delete(dshelp.CidToDsKey(k))
188 - if err == ds.ErrNotFound {
189 - return ErrNotFound
190 - }
191 - return err
192 -}
193 -
194 -// AllKeysChan runs a query for keys from the blockstore.
195 -// this is very simplistic, in the future, take dsq.Query as a param?
196 -//
197 -// AllKeysChan respects context.
198 -func (bs *blockstore) AllKeysChan(ctx context.Context) (<-chan *cid.Cid, error) {
199 -
200 - // KeysOnly, because that would be _a lot_ of data.
201 - q := dsq.Query{KeysOnly: true}
202 - res, err := bs.datastore.Query(q)
203 - if err != nil {
204 - return nil, err
205 - }
206 -
207 - output := make(chan *cid.Cid, dsq.KeysOnlyBufSize)
208 - go func() {
209 - defer func() {
210 - res.Close() // ensure exit (signals early exit, too)
211 - close(output)
212 - }()
213 -
214 - for {
215 - e, ok := res.NextSync()
216 - if !ok {
217 - return
218 - }
219 - if e.Error != nil {
220 - log.Errorf("blockstore.AllKeysChan got err: %s", e.Error)
221 - return
222 - }
223 -
224 - // need to convert to key.Key using key.KeyFromDsKey.
225 - k, err := dshelp.DsKeyToCid(ds.RawKey(e.Key))
226 - if err != nil {
227 - log.Warningf("error parsing key from DsKey: %s", err)
228 - continue
229 - }
230 -
231 - select {
232 - case <-ctx.Done():
233 - return
234 - case output <- k:
235 - }
236 - }
237 - }()
238 -
239 - return output, nil
240 -}
241 -
242 -// NewGCLocker returns a default implementation of
243 -// GCLocker using standard [RW] mutexes.
244 -func NewGCLocker() GCLocker {
245 - return &gclocker{}
246 -}
247 -
248 -type gclocker struct {
249 - lk sync.RWMutex
250 - gcreq int32
251 -}
252 -
253 -// Unlocker represents an object which can Unlock
254 -// something.
255 -type Unlocker interface {
256 - Unlock()
257 -}
258 -
259 -type unlocker struct {
260 - unlock func()
261 -}
262 -
263 -func (u *unlocker) Unlock() {
264 - u.unlock()
265 - u.unlock = nil // ensure its not called twice
266 -}
267 -
268 -func (bs *gclocker) GCLock() Unlocker {
269 - atomic.AddInt32(&bs.gcreq, 1)
270 - bs.lk.Lock()
271 - atomic.AddInt32(&bs.gcreq, -1)
272 - return &unlocker{bs.lk.Unlock}
273 -}
274 -
275 -func (bs *gclocker) PinLock() Unlocker {
276 - bs.lk.RLock()
277 - return &unlocker{bs.lk.RUnlock}
278 -}
279 -
280 -func (bs *gclocker) GCRequested() bool {
281 - return atomic.LoadInt32(&bs.gcreq) > 0
282 -}
blocks/blockstore/blockstore_test.go deleted
-253
@@ -1,253 +0,0 @@
1 -package blockstore
2 -
3 -import (
4 - "bytes"
5 - "context"
6 - "fmt"
7 - "testing"
8 -
9 - u "gx/ipfs/QmNiJuT8Ja3hMVpBHXv3Q6dwmperaQ6JjLtpMQgMCD7xvx/go-ipfs-util"
10 - ds "gx/ipfs/QmPpegoMqhAEqjncrzArm7KVWAkCm78rqL2DPuNjhPrshg/go-datastore"
11 - dsq "gx/ipfs/QmPpegoMqhAEqjncrzArm7KVWAkCm78rqL2DPuNjhPrshg/go-datastore/query"
12 - ds_sync "gx/ipfs/QmPpegoMqhAEqjncrzArm7KVWAkCm78rqL2DPuNjhPrshg/go-datastore/sync"
13 - cid "gx/ipfs/QmcZfnkapfECQGcLZaf9B79NRg7cRa9EnZh4LSbkCzwNvY/go-cid"
14 - dshelp "gx/ipfs/QmdQTPWduSeyveSxeCAte33M592isSW5Z979g81aJphrgn/go-ipfs-ds-help"
15 - blocks "gx/ipfs/Qmej7nf81hi2x2tvjRBF3mcp74sQyuDH4VMYDGd1YtXjb2/go-block-format"
16 -)
17 -
18 -func TestGetWhenKeyNotPresent(t *testing.T) {
19 - bs := NewBlockstore(ds_sync.MutexWrap(ds.NewMapDatastore()))
20 - c := cid.NewCidV0(u.Hash([]byte("stuff")))
21 - bl, err := bs.Get(c)
22 -
23 - if bl != nil {
24 - t.Error("nil block expected")
25 - }
26 - if err == nil {
27 - t.Error("error expected, got nil")
28 - }
29 -}
30 -
31 -func TestGetWhenKeyIsNil(t *testing.T) {
32 - bs := NewBlockstore(ds_sync.MutexWrap(ds.NewMapDatastore()))
33 - _, err := bs.Get(nil)
34 - if err != ErrNotFound {
35 - t.Fail()
36 - }
37 -}
38 -
39 -func TestPutThenGetBlock(t *testing.T) {
40 - bs := NewBlockstore(ds_sync.MutexWrap(ds.NewMapDatastore()))
41 - block := blocks.NewBlock([]byte("some data"))
42 -
43 - err := bs.Put(block)
44 - if err != nil {
45 - t.Fatal(err)
46 - }
47 -
48 - blockFromBlockstore, err := bs.Get(block.Cid())
49 - if err != nil {
50 - t.Fatal(err)
51 - }
52 - if !bytes.Equal(block.RawData(), blockFromBlockstore.RawData()) {
53 - t.Fail()
54 - }
55 -}
56 -
57 -func TestHashOnRead(t *testing.T) {
58 - orginalDebug := u.Debug
59 - defer (func() {
60 - u.Debug = orginalDebug
61 - })()
62 - u.Debug = false
63 -
64 - bs := NewBlockstore(ds_sync.MutexWrap(ds.NewMapDatastore()))
65 - bl := blocks.NewBlock([]byte("some data"))
66 - blBad, err := blocks.NewBlockWithCid([]byte("some other data"), bl.Cid())
67 - if err != nil {
68 - t.Fatal("debug is off, still got an error")
69 - }
70 - bl2 := blocks.NewBlock([]byte("some other data"))
71 - bs.Put(blBad)
72 - bs.Put(bl2)
73 - bs.HashOnRead(true)
74 -
75 - if _, err := bs.Get(bl.Cid()); err != ErrHashMismatch {
76 - t.Fatalf("expected '%v' got '%v'\n", ErrHashMismatch, err)
77 - }
78 -
79 - if b, err := bs.Get(bl2.Cid()); err != nil || b.String() != bl2.String() {
80 - t.Fatal("got wrong blocks")
81 - }
82 -}
83 -
84 -func newBlockStoreWithKeys(t *testing.T, d ds.Datastore, N int) (Blockstore, []*cid.Cid) {
85 - if d == nil {
86 - d = ds.NewMapDatastore()
87 - }
88 - bs := NewBlockstore(ds_sync.MutexWrap(d))
89 -
90 - keys := make([]*cid.Cid, N)
91 - for i := 0; i < N; i++ {
92 - block := blocks.NewBlock([]byte(fmt.Sprintf("some data %d", i)))
93 - err := bs.Put(block)
94 - if err != nil {
95 - t.Fatal(err)
96 - }
97 - keys[i] = block.Cid()
98 - }
99 - return bs, keys
100 -}
101 -
102 -func collect(ch <-chan *cid.Cid) []*cid.Cid {
103 - var keys []*cid.Cid
104 - for k := range ch {
105 - keys = append(keys, k)
106 - }
107 - return keys
108 -}
109 -
110 -func TestAllKeysSimple(t *testing.T) {
111 - bs, keys := newBlockStoreWithKeys(t, nil, 100)
112 -
113 - ctx := context.Background()
114 - ch, err := bs.AllKeysChan(ctx)
115 - if err != nil {
116 - t.Fatal(err)
117 - }
118 - keys2 := collect(ch)
119 -
120 - // for _, k2 := range keys2 {
121 - // t.Log("found ", k2.B58String())
122 - // }
123 -
124 - expectMatches(t, keys, keys2)
125 -}
126 -
127 -func TestAllKeysRespectsContext(t *testing.T) {
128 - N := 100
129 -
130 - d := &queryTestDS{ds: ds.NewMapDatastore()}
131 - bs, _ := newBlockStoreWithKeys(t, d, N)
132 -
133 - started := make(chan struct{}, 1)
134 - done := make(chan struct{}, 1)
135 - errors := make(chan error, 100)
136 -
137 - getKeys := func(ctx context.Context) {
138 - started <- struct{}{}
139 - ch, err := bs.AllKeysChan(ctx) // once without cancelling
140 - if err != nil {
141 - errors <- err
142 - }
143 - _ = collect(ch)
144 - done <- struct{}{}
145 - errors <- nil // a nil one to signal break
146 - }
147 -
148 - var results dsq.Results
149 - var resultsmu = make(chan struct{})
150 - resultChan := make(chan dsq.Result)
151 - d.SetFunc(func(q dsq.Query) (dsq.Results, error) {
152 - results = dsq.ResultsWithChan(q, resultChan)
153 - resultsmu <- struct{}{}
154 - return results, nil
155 - })
156 -
157 - go getKeys(context.Background())
158 -
159 - // make sure it's waiting.
160 - <-started
161 - <-resultsmu
162 - select {
163 - case <-done:
164 - t.Fatal("sync is wrong")
165 - case <-results.Process().Closing():
166 - t.Fatal("should not be closing")
167 - case <-results.Process().Closed():
168 - t.Fatal("should not be closed")
169 - default:
170 - }
171 -
172 - e := dsq.Entry{Key: BlockPrefix.ChildString("foo").String()}
173 - resultChan <- dsq.Result{Entry: e} // let it go.
174 - close(resultChan)
175 - <-done // should be done now.
176 - <-results.Process().Closed() // should be closed now
177 -
178 - // print any errors
179 - for err := range errors {
180 - if err == nil {
181 - break
182 - }
183 - t.Error(err)
184 - }
185 -
186 -}
187 -
188 -func TestErrValueTypeMismatch(t *testing.T) {
189 - block := blocks.NewBlock([]byte("some data"))
190 -
191 - datastore := ds.NewMapDatastore()
192 - k := BlockPrefix.Child(dshelp.CidToDsKey(block.Cid()))
193 - datastore.Put(k, "data that isn't a block!")
194 -
195 - blockstore := NewBlockstore(ds_sync.MutexWrap(datastore))
196 -
197 - _, err := blockstore.Get(block.Cid())
198 - if err != ErrValueTypeMismatch {
199 - t.Fatal(err)
200 - }
201 -}
202 -
203 -func expectMatches(t *testing.T, expect, actual []*cid.Cid) {
204 -
205 - if len(expect) != len(actual) {
206 - t.Errorf("expect and actual differ: %d != %d", len(expect), len(actual))
207 - }
208 - for _, ek := range expect {
209 - found := false
210 - for _, ak := range actual {
211 - if ek.Equals(ak) {
212 - found = true
213 - }
214 - }
215 - if !found {
216 - t.Error("expected key not found: ", ek)
217 - }
218 - }
219 -}
220 -
221 -type queryTestDS struct {
222 - cb func(q dsq.Query) (dsq.Results, error)
223 - ds ds.Datastore
224 -}
225 -
226 -func (c *queryTestDS) SetFunc(f func(dsq.Query) (dsq.Results, error)) { c.cb = f }
227 -
228 -func (c *queryTestDS) Put(key ds.Key, value interface{}) (err error) {
229 - return c.ds.Put(key, value)
230 -}
231 -
232 -func (c *queryTestDS) Get(key ds.Key) (value interface{}, err error) {
233 - return c.ds.Get(key)
234 -}
235 -
236 -func (c *queryTestDS) Has(key ds.Key) (exists bool, err error) {
237 - return c.ds.Has(key)
238 -}
239 -
240 -func (c *queryTestDS) Delete(key ds.Key) (err error) {
241 - return c.ds.Delete(key)
242 -}
243 -
244 -func (c *queryTestDS) Query(q dsq.Query) (dsq.Results, error) {
245 - if c.cb != nil {
246 - return c.cb(q)
247 - }
248 - return c.ds.Query(q)
249 -}
250 -
251 -func (c *queryTestDS) Batch() (ds.Batch, error) {
252 - return ds.NewBasicBatch(c), nil
253 -}
blocks/blockstore/bloom_cache.go deleted
-187
@@ -1,187 +0,0 @@
1 -package blockstore
2 -
3 -import (
4 - "context"
5 - "sync/atomic"
6 - "time"
7 -
8 - "gx/ipfs/Qmej7nf81hi2x2tvjRBF3mcp74sQyuDH4VMYDGd1YtXjb2/go-block-format"
9 -
10 - "gx/ipfs/QmRg1gKTHzc3CZXSKzem8aR4E3TubFhbgXwfVuWnSK5CC5/go-metrics-interface"
11 - bloom "gx/ipfs/QmXqKGu7QzfRzFC4yd5aL9sThYx22vY163VGwmxfp5qGHk/bbloom"
12 - cid "gx/ipfs/QmcZfnkapfECQGcLZaf9B79NRg7cRa9EnZh4LSbkCzwNvY/go-cid"
13 -)
14 -
15 -// bloomCached returns a Blockstore that caches Has requests using a Bloom
16 -// filter. bloomSize is size of bloom filter in bytes. hashCount specifies the
17 -// number of hashing functions in the bloom filter (usually known as k).
18 -func bloomCached(ctx context.Context, bs Blockstore, bloomSize, hashCount int) (*bloomcache, error) {
19 - bl, err := bloom.New(float64(bloomSize), float64(hashCount))
20 - if err != nil {
21 - return nil, err
22 - }
23 - bc := &bloomcache{blockstore: bs, bloom: bl}
24 - bc.hits = metrics.NewCtx(ctx, "bloom.hits_total",
25 - "Number of cache hits in bloom cache").Counter()
26 - bc.total = metrics.NewCtx(ctx, "bloom_total",
27 - "Total number of requests to bloom cache").Counter()
28 -
29 - bc.Invalidate()
30 - go bc.Rebuild(ctx)
31 - if metrics.Active() {
32 - go func() {
33 - fill := metrics.NewCtx(ctx, "bloom_fill_ratio",
34 - "Ratio of bloom filter fullnes, (updated once a minute)").Gauge()
35 -
36 - <-bc.rebuildChan
37 - t := time.NewTicker(1 * time.Minute)
38 - for {
39 - select {
40 - case <-ctx.Done():
41 - t.Stop()
42 - return
43 - case <-t.C:
44 - fill.Set(bc.bloom.FillRatio())
45 - }
46 - }
47 - }()
48 - }
49 - return bc, nil
50 -}
51 -
52 -type bloomcache struct {
53 - bloom *bloom.Bloom
54 - active int32
55 -
56 - // This chan is only used for testing to wait for bloom to enable
57 - rebuildChan chan struct{}
58 - blockstore Blockstore
59 -
60 - // Statistics
61 - hits metrics.Counter
62 - total metrics.Counter
63 -}
64 -
65 -func (b *bloomcache) Invalidate() {
66 - b.rebuildChan = make(chan struct{})
67 - atomic.StoreInt32(&b.active, 0)
68 -}
69 -
70 -func (b *bloomcache) BloomActive() bool {
71 - return atomic.LoadInt32(&b.active) != 0
72 -}
73 -
74 -func (b *bloomcache) Rebuild(ctx context.Context) {
75 - evt := log.EventBegin(ctx, "bloomcache.Rebuild")
76 - defer evt.Done()
77 -
78 - ch, err := b.blockstore.AllKeysChan(ctx)
79 - if err != nil {
80 - log.Errorf("AllKeysChan failed in bloomcache rebuild with: %v", err)
81 - return
82 - }
83 - finish := false
84 - for !finish {
85 - select {
86 - case key, ok := <-ch:
87 - if ok {
88 - b.bloom.AddTS(key.Bytes()) // Use binary key, the more compact the better
89 - } else {
90 - finish = true
91 - }
92 - case <-ctx.Done():
93 - log.Warning("Cache rebuild closed by context finishing.")
94 - return
95 - }
96 - }
97 - close(b.rebuildChan)
98 - atomic.StoreInt32(&b.active, 1)
99 -}
100 -
101 -func (b *bloomcache) DeleteBlock(k *cid.Cid) error {
102 - if has, ok := b.hasCached(k); ok && !has {
103 - return ErrNotFound
104 - }
105 -
106 - return b.blockstore.DeleteBlock(k)
107 -}
108 -
109 -// if ok == false has is inconclusive
110 -// if ok == true then has respons to question: is it contained
111 -func (b *bloomcache) hasCached(k *cid.Cid) (has bool, ok bool) {
112 - b.total.Inc()
113 - if k == nil {
114 - log.Error("nil cid in bloom cache")
115 - // Return cache invalid so call to blockstore
116 - // in case of invalid key is forwarded deeper
117 - return false, false
118 - }
119 - if b.BloomActive() {
120 - blr := b.bloom.HasTS(k.Bytes())
121 - if !blr { // not contained in bloom is only conclusive answer bloom gives
122 - b.hits.Inc()
123 - return false, true
124 - }
125 - }
126 - return false, false
127 -}
128 -
129 -func (b *bloomcache) Has(k *cid.Cid) (bool, error) {
130 - if has, ok := b.hasCached(k); ok {
131 - return has, nil
132 - }
133 -
134 - return b.blockstore.Has(k)
135 -}
136 -
137 -func (b *bloomcache) Get(k *cid.Cid) (blocks.Block, error) {
138 - if has, ok := b.hasCached(k); ok && !has {
139 - return nil, ErrNotFound
140 - }
141 -
142 - return b.blockstore.Get(k)
143 -}
144 -
145 -func (b *bloomcache) Put(bl blocks.Block) error {
146 - // See comment in PutMany
147 - err := b.blockstore.Put(bl)
148 - if err == nil {
149 - b.bloom.AddTS(bl.Cid().Bytes())
150 - }
151 - return err
152 -}
153 -
154 -func (b *bloomcache) PutMany(bs []blocks.Block) error {
155 - // bloom cache gives only conclusive resulty if key is not contained
156 - // to reduce number of puts we need conclusive information if block is contained
157 - // this means that PutMany can't be improved with bloom cache so we just
158 - // just do a passthrough.
159 - err := b.blockstore.PutMany(bs)
160 - if err != nil {
161 - return err
162 - }
163 - for _, bl := range bs {
164 - b.bloom.AddTS(bl.Cid().Bytes())
165 - }
166 - return nil
167 -}
168 -
169 -func (b *bloomcache) HashOnRead(enabled bool) {
170 - b.blockstore.HashOnRead(enabled)
171 -}
172 -
173 -func (b *bloomcache) AllKeysChan(ctx context.Context) (<-chan *cid.Cid, error) {
174 - return b.blockstore.AllKeysChan(ctx)
175 -}
176 -
177 -func (b *bloomcache) GCLock() Unlocker {
178 - return b.blockstore.(GCBlockstore).GCLock()
179 -}
180 -
181 -func (b *bloomcache) PinLock() Unlocker {
182 - return b.blockstore.(GCBlockstore).PinLock()
183 -}
184 -
185 -func (b *bloomcache) GCRequested() bool {
186 - return b.blockstore.(GCBlockstore).GCRequested()
187 -}
blocks/blockstore/bloom_cache_test.go deleted
-180
@@ -1,180 +0,0 @@
1 -package blockstore
2 -
3 -import (
4 - "fmt"
5 - "sync"
6 - "testing"
7 - "time"
8 -
9 - "gx/ipfs/Qmej7nf81hi2x2tvjRBF3mcp74sQyuDH4VMYDGd1YtXjb2/go-block-format"
10 -
11 - context "context"
12 - ds "gx/ipfs/QmPpegoMqhAEqjncrzArm7KVWAkCm78rqL2DPuNjhPrshg/go-datastore"
13 - dsq "gx/ipfs/QmPpegoMqhAEqjncrzArm7KVWAkCm78rqL2DPuNjhPrshg/go-datastore/query"
14 - syncds "gx/ipfs/QmPpegoMqhAEqjncrzArm7KVWAkCm78rqL2DPuNjhPrshg/go-datastore/sync"
15 -)
16 -
17 -func testBloomCached(ctx context.Context, bs Blockstore) (*bloomcache, error) {
18 - if ctx == nil {
19 - ctx = context.Background()
20 - }
21 - opts := DefaultCacheOpts()
22 - opts.HasARCCacheSize = 0
23 - bbs, err := CachedBlockstore(ctx, bs, opts)
24 - if err == nil {
25 - return bbs.(*bloomcache), nil
26 - }
27 - return nil, err
28 -}
29 -
30 -func TestPutManyAddsToBloom(t *testing.T) {
31 - bs := NewBlockstore(syncds.MutexWrap(ds.NewMapDatastore()))
32 -
33 - ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
34 - defer cancel()
35 -
36 - cachedbs, err := testBloomCached(ctx, bs)
37 - if err != nil {
38 - t.Fatal(err)
39 - }
40 -
41 - select {
42 - case <-cachedbs.rebuildChan:
43 - case <-ctx.Done():
44 - t.Fatalf("Timeout wating for rebuild: %d", cachedbs.bloom.ElementsAdded())
45 - }
46 -
47 - block1 := blocks.NewBlock([]byte("foo"))
48 - block2 := blocks.NewBlock([]byte("bar"))
49 -
50 - cachedbs.PutMany([]blocks.Block{block1})
51 - has, err := cachedbs.Has(block1.Cid())
52 - if err != nil {
53 - t.Fatal(err)
54 - }
55 - if !has {
56 - t.Fatal("added block is reported missing")
57 - }
58 -
59 - has, err = cachedbs.Has(block2.Cid())
60 - if err != nil {
61 - t.Fatal(err)
62 - }
63 - if has {
64 - t.Fatal("not added block is reported to be in blockstore")
65 - }
66 -}
67 -
68 -func TestReturnsErrorWhenSizeNegative(t *testing.T) {
69 - bs := NewBlockstore(syncds.MutexWrap(ds.NewMapDatastore()))
70 - _, err := bloomCached(context.Background(), bs, -1, 1)
71 - if err == nil {
72 - t.Fail()
73 - }
74 -}
75 -func TestHasIsBloomCached(t *testing.T) {
76 - cd := &callbackDatastore{f: func() {}, ds: ds.NewMapDatastore()}
77 - bs := NewBlockstore(syncds.MutexWrap(cd))
78 -
79 - for i := 0; i < 1000; i++ {
80 - bs.Put(blocks.NewBlock([]byte(fmt.Sprintf("data: %d", i))))
81 - }
82 - ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
83 - defer cancel()
84 -
85 - cachedbs, err := testBloomCached(ctx, bs)
86 - if err != nil {
87 - t.Fatal(err)
88 - }
89 -
90 - select {
91 - case <-cachedbs.rebuildChan:
92 - case <-ctx.Done():
93 - t.Fatalf("Timeout wating for rebuild: %d", cachedbs.bloom.ElementsAdded())
94 - }
95 -
96 - cacheFails := 0
97 - cd.SetFunc(func() {
98 - cacheFails++
99 - })
100 -
101 - for i := 0; i < 1000; i++ {
102 - cachedbs.Has(blocks.NewBlock([]byte(fmt.Sprintf("data: %d", i+2000))).Cid())
103 - }
104 -
105 - if float64(cacheFails)/float64(1000) > float64(0.05) {
106 - t.Fatal("Bloom filter has cache miss rate of more than 5%")
107 - }
108 -
109 - cacheFails = 0
110 - block := blocks.NewBlock([]byte("newBlock"))
111 -
112 - cachedbs.PutMany([]blocks.Block{block})
113 - if cacheFails != 2 {
114 - t.Fatalf("expected two datastore hits: %d", cacheFails)
115 - }
116 - cachedbs.Put(block)
117 - if cacheFails != 3 {
118 - t.Fatalf("expected datastore hit: %d", cacheFails)
119 - }
120 -
121 - if has, err := cachedbs.Has(block.Cid()); !has || err != nil {
122 - t.Fatal("has gave wrong response")
123 - }
124 -
125 - bl, err := cachedbs.Get(block.Cid())
126 - if bl.String() != block.String() {
127 - t.Fatal("block data doesn't match")
128 - }
129 -
130 - if err != nil {
131 - t.Fatal("there should't be an error")
132 - }
133 -}
134 -
135 -type callbackDatastore struct {
136 - sync.Mutex
137 - f func()
138 - ds ds.Datastore
139 -}
140 -
141 -func (c *callbackDatastore) SetFunc(f func()) {
142 - c.Lock()
143 - defer c.Unlock()
144 - c.f = f
145 -}
146 -
147 -func (c *callbackDatastore) CallF() {
148 - c.Lock()
149 - defer c.Unlock()
150 - c.f()
151 -}
152 -
153 -func (c *callbackDatastore) Put(key ds.Key, value interface{}) (err error) {
154 - c.CallF()
155 - return c.ds.Put(key, value)
156 -}
157 -
158 -func (c *callbackDatastore) Get(key ds.Key) (value interface{}, err error) {
159 - c.CallF()
160 - return c.ds.Get(key)
161 -}
162 -
163 -func (c *callbackDatastore) Has(key ds.Key) (exists bool, err error) {
164 - c.CallF()
165 - return c.ds.Has(key)
166 -}
167 -
168 -func (c *callbackDatastore) Delete(key ds.Key) (err error) {
169 - c.CallF()
170 - return c.ds.Delete(key)
171 -}
172 -
173 -func (c *callbackDatastore) Query(q dsq.Query) (dsq.Results, error) {
174 - c.CallF()
175 - return c.ds.Query(q)
176 -}
177 -
178 -func (c *callbackDatastore) Batch() (ds.Batch, error) {
179 - return ds.NewBasicBatch(c), nil
180 -}
blocks/blockstore/caching.go deleted
-56
@@ -1,56 +0,0 @@
1 -package blockstore
2 -
3 -import (
4 - "errors"
5 -
6 - context "context"
7 -
8 - "gx/ipfs/QmRg1gKTHzc3CZXSKzem8aR4E3TubFhbgXwfVuWnSK5CC5/go-metrics-interface"
9 -)
10 -
11 -// CacheOpts wraps options for CachedBlockStore().
12 -// Next to each option is it aproximate memory usage per unit
13 -type CacheOpts struct {
14 - HasBloomFilterSize int // 1 byte
15 - HasBloomFilterHashes int // No size, 7 is usually best, consult bloom papers
16 - HasARCCacheSize int // 32 bytes
17 -}
18 -
19 -// DefaultCacheOpts returns a CacheOpts initialized with default values.
20 -func DefaultCacheOpts() CacheOpts {
21 - return CacheOpts{
22 - HasBloomFilterSize: 512 << 10,
23 - HasBloomFilterHashes: 7,
24 - HasARCCacheSize: 64 << 10,
25 - }
26 -}
27 -
28 -// CachedBlockstore returns a blockstore wrapped in an ARCCache and
29 -// then in a bloom filter cache, if the options indicate it.
30 -func CachedBlockstore(
31 - ctx context.Context,
32 - bs Blockstore,
33 - opts CacheOpts) (cbs Blockstore, err error) {
34 - cbs = bs
35 -
36 - if opts.HasBloomFilterSize < 0 || opts.HasBloomFilterHashes < 0 ||
37 - opts.HasARCCacheSize < 0 {
38 - return nil, errors.New("all options for cache need to be greater than zero")
39 - }
40 -
41 - if opts.HasBloomFilterSize != 0 && opts.HasBloomFilterHashes == 0 {
42 - return nil, errors.New("bloom filter hash count can't be 0 when there is size set")
43 - }
44 -
45 - ctx = metrics.CtxSubScope(ctx, "bs.cache")
46 -
47 - if opts.HasARCCacheSize > 0 {
48 - cbs, err = newARCCachedBS(ctx, cbs, opts.HasARCCacheSize)
49 - }
50 - if opts.HasBloomFilterSize != 0 {
51 - // *8 because of bytes to bits conversion
52 - cbs, err = bloomCached(ctx, cbs, opts.HasBloomFilterSize*8, opts.HasBloomFilterHashes)
53 - }
54 -
55 - return cbs, err
56 -}
blocks/blockstore/caching_test.go deleted
-38
@@ -1,38 +0,0 @@
1 -package blockstore
2 -
3 -import (
4 - "context"
5 - "testing"
6 -)
7 -
8 -func TestCachingOptsLessThanZero(t *testing.T) {
9 - opts := DefaultCacheOpts()
10 - opts.HasARCCacheSize = -1
11 -
12 - if _, err := CachedBlockstore(context.TODO(), nil, opts); err == nil {
13 - t.Error("wrong ARC setting was not detected")
14 - }
15 -
16 - opts = DefaultCacheOpts()
17 - opts.HasBloomFilterSize = -1
18 -
19 - if _, err := CachedBlockstore(context.TODO(), nil, opts); err == nil {
20 - t.Error("negative bloom size was not detected")
21 - }
22 -
23 - opts = DefaultCacheOpts()
24 - opts.HasBloomFilterHashes = -1
25 -
26 - if _, err := CachedBlockstore(context.TODO(), nil, opts); err == nil {
27 - t.Error("negative hashes setting was not detected")
28 - }
29 -}
30 -
31 -func TestBloomHashesAtZero(t *testing.T) {
32 - opts := DefaultCacheOpts()
33 - opts.HasBloomFilterHashes = 0
34 -
35 - if _, err := CachedBlockstore(context.TODO(), nil, opts); err == nil {
36 - t.Error("zero hashes setting with positive size was not detected")
37 - }
38 -}
blocks/blockstoreutil/remove.go renamed
+3 -3
@@ -5,11 +5,11 @@ import (
5 "fmt"
6 "io"
7
8 + "github.com/ipfs/go-ipfs/pin"
9 +
10 ds "gx/ipfs/QmPpegoMqhAEqjncrzArm7KVWAkCm78rqL2DPuNjhPrshg/go-datastore"
11 + bs "gx/ipfs/QmTVDM4LCSUMFNQzbDLL9zQwp8usE6QHymFdh3h8vL9v6b/go-ipfs-blockstore"
12 cid "gx/ipfs/QmcZfnkapfECQGcLZaf9B79NRg7cRa9EnZh4LSbkCzwNvY/go-cid"
10 -
11 - bs "github.com/ipfs/go-ipfs/blocks/blockstore"
12 - "github.com/ipfs/go-ipfs/pin"
13 )
14
15 // RemovedBlock is used to respresent the result of removing a block.
blockservice/blockservice.go
+1 -1
@@ -9,11 +9,11 @@ import (
9 "fmt"
10 "io"
11
12 - "github.com/ipfs/go-ipfs/blocks/blockstore"
12 exchange "github.com/ipfs/go-ipfs/exchange"
13 bitswap "github.com/ipfs/go-ipfs/exchange/bitswap"
14
15 logging "gx/ipfs/QmRb5jh8z2E8hMGN2tkvs1yHynUanqnZ3UeKwgN1i9P1F8/go-log"
16 + blockstore "gx/ipfs/QmTVDM4LCSUMFNQzbDLL9zQwp8usE6QHymFdh3h8vL9v6b/go-ipfs-blockstore"
17 cid "gx/ipfs/QmcZfnkapfECQGcLZaf9B79NRg7cRa9EnZh4LSbkCzwNvY/go-cid"
18 blocks "gx/ipfs/Qmej7nf81hi2x2tvjRBF3mcp74sQyuDH4VMYDGd1YtXjb2/go-block-format"
19 )
blockservice/blockservice_test.go
+2 -2
@@ -3,13 +3,13 @@ package blockservice
3 import (
4 "testing"
5
6 - "github.com/ipfs/go-ipfs/blocks/blockstore"
6 butil "github.com/ipfs/go-ipfs/blocks/blocksutil"
7 offline "github.com/ipfs/go-ipfs/exchange/offline"
9 - "gx/ipfs/Qmej7nf81hi2x2tvjRBF3mcp74sQyuDH4VMYDGd1YtXjb2/go-block-format"
8
9 ds "gx/ipfs/QmPpegoMqhAEqjncrzArm7KVWAkCm78rqL2DPuNjhPrshg/go-datastore"
10 dssync "gx/ipfs/QmPpegoMqhAEqjncrzArm7KVWAkCm78rqL2DPuNjhPrshg/go-datastore/sync"
11 + blockstore "gx/ipfs/QmTVDM4LCSUMFNQzbDLL9zQwp8usE6QHymFdh3h8vL9v6b/go-ipfs-blockstore"
12 + blocks "gx/ipfs/Qmej7nf81hi2x2tvjRBF3mcp74sQyuDH4VMYDGd1YtXjb2/go-block-format"
13 )
14
15 func TestWriteThroughWorks(t *testing.T) {
blockservice/test/blocks_test.go
+2 -2
@@ -7,15 +7,15 @@ import (
7 "testing"
8 "time"
9
10 - blockstore "github.com/ipfs/go-ipfs/blocks/blockstore"
10 . "github.com/ipfs/go-ipfs/blockservice"
11 offline "github.com/ipfs/go-ipfs/exchange/offline"
13 - blocks "gx/ipfs/Qmej7nf81hi2x2tvjRBF3mcp74sQyuDH4VMYDGd1YtXjb2/go-block-format"
12
13 u "gx/ipfs/QmNiJuT8Ja3hMVpBHXv3Q6dwmperaQ6JjLtpMQgMCD7xvx/go-ipfs-util"
14 ds "gx/ipfs/QmPpegoMqhAEqjncrzArm7KVWAkCm78rqL2DPuNjhPrshg/go-datastore"
15 dssync "gx/ipfs/QmPpegoMqhAEqjncrzArm7KVWAkCm78rqL2DPuNjhPrshg/go-datastore/sync"
16 + blockstore "gx/ipfs/QmTVDM4LCSUMFNQzbDLL9zQwp8usE6QHymFdh3h8vL9v6b/go-ipfs-blockstore"
17 cid "gx/ipfs/QmcZfnkapfECQGcLZaf9B79NRg7cRa9EnZh4LSbkCzwNvY/go-cid"
18 + blocks "gx/ipfs/Qmej7nf81hi2x2tvjRBF3mcp74sQyuDH4VMYDGd1YtXjb2/go-block-format"
19 )
20
21 func newObject(data []byte) blocks.Block {
core/builder.go
+1 -1
@@ -9,7 +9,6 @@ import (
9 "syscall"
10 "time"
11
12 - bstore "github.com/ipfs/go-ipfs/blocks/blockstore"
12 bserv "github.com/ipfs/go-ipfs/blockservice"
13 offline "github.com/ipfs/go-ipfs/exchange/offline"
14 filestore "github.com/ipfs/go-ipfs/filestore"
@@ -24,6 +23,7 @@ import (
23 dsync "gx/ipfs/QmPpegoMqhAEqjncrzArm7KVWAkCm78rqL2DPuNjhPrshg/go-datastore/sync"
24 metrics "gx/ipfs/QmRg1gKTHzc3CZXSKzem8aR4E3TubFhbgXwfVuWnSK5CC5/go-metrics-interface"
25 goprocessctx "gx/ipfs/QmSF8fPo3jgVBAy8fpdjjYqgG87dkJgUprRBHRd2tmfgpP/goprocess/context"
26 + bstore "gx/ipfs/QmTVDM4LCSUMFNQzbDLL9zQwp8usE6QHymFdh3h8vL9v6b/go-ipfs-blockstore"
27 pstore "gx/ipfs/QmXauCuJzmzapetmC6W4TuDJLL1yFFrVzSHoWv8YdbmnxH/go-libp2p-peerstore"
28 peer "gx/ipfs/QmZoWKhxUmZ2seW4BzX6fJkNR8hh9PsGModr7q171yq2SS/go-libp2p-peer"
29 ci "gx/ipfs/QmaPbCnUMBohSGo3KnxEa2bHqyJVVeEEcwtqJAYxerieBo/go-libp2p-crypto"
core/commands/add.go
+5 -5
@@ -7,7 +7,6 @@ import (
7 "os"
8 "strings"
9
10 - bstore "github.com/ipfs/go-ipfs/blocks/blockstore"
10 blockservice "github.com/ipfs/go-ipfs/blockservice"
11 core "github.com/ipfs/go-ipfs/core"
12 "github.com/ipfs/go-ipfs/core/coreunix"
@@ -17,11 +16,12 @@ import (
16 mfs "github.com/ipfs/go-ipfs/mfs"
17 ft "github.com/ipfs/go-ipfs/unixfs"
18
20 - "gx/ipfs/QmZ9hww8R3FKrDRCYPxhN13m6XgjPDpaSvdUfisPvERzXz/go-ipfs-cmds"
19 + bstore "gx/ipfs/QmTVDM4LCSUMFNQzbDLL9zQwp8usE6QHymFdh3h8vL9v6b/go-ipfs-blockstore"
20 + cmds "gx/ipfs/QmZ9hww8R3FKrDRCYPxhN13m6XgjPDpaSvdUfisPvERzXz/go-ipfs-cmds"
21 mh "gx/ipfs/QmZyZDi491cCNTLfAhwcaDii2Kg4pwKRkhqQzURGDvY6ua/go-multihash"
22 - "gx/ipfs/QmceUdzxkimdYsgtX733uNgzf1DLHyBKN6ehGSp85ayppM/go-ipfs-cmdkit"
23 - "gx/ipfs/QmceUdzxkimdYsgtX733uNgzf1DLHyBKN6ehGSp85ayppM/go-ipfs-cmdkit/files"
24 - "gx/ipfs/QmeWjRodbcZFKe5tMN7poEx3izym6osrLSnTLf9UjJZBbs/pb"
22 + cmdkit "gx/ipfs/QmceUdzxkimdYsgtX733uNgzf1DLHyBKN6ehGSp85ayppM/go-ipfs-cmdkit"
23 + files "gx/ipfs/QmceUdzxkimdYsgtX733uNgzf1DLHyBKN6ehGSp85ayppM/go-ipfs-cmdkit/files"
24 + pb "gx/ipfs/QmeWjRodbcZFKe5tMN7poEx3izym6osrLSnTLf9UjJZBbs/pb"
25 )
26
27 // ErrDepthLimitExceeded indicates that the max depth has been exceded.
core/commands/block.go
+1 -1
@@ -8,7 +8,7 @@ import (
8 "io/ioutil"
9 "os"
10
11 - util "github.com/ipfs/go-ipfs/blocks/blockstore/util"
11 + util "github.com/ipfs/go-ipfs/blocks/blockstoreutil"
12 e "github.com/ipfs/go-ipfs/core/commands/e"
13
14 "gx/ipfs/QmZ9hww8R3FKrDRCYPxhN13m6XgjPDpaSvdUfisPvERzXz/go-ipfs-cmds"
core/commands/repo.go
+2 -2
@@ -9,15 +9,15 @@ import (
9 "strings"
10 "text/tabwriter"
11
12 - bstore "github.com/ipfs/go-ipfs/blocks/blockstore"
12 oldcmds "github.com/ipfs/go-ipfs/commands"
13 + lgc "github.com/ipfs/go-ipfs/commands/legacy"
14 e "github.com/ipfs/go-ipfs/core/commands/e"
15 corerepo "github.com/ipfs/go-ipfs/core/corerepo"
16 config "github.com/ipfs/go-ipfs/repo/config"
17 fsrepo "github.com/ipfs/go-ipfs/repo/fsrepo"
18 lockfile "github.com/ipfs/go-ipfs/repo/fsrepo/lock"
19
20 - lgc "github.com/ipfs/go-ipfs/commands/legacy"
20 + bstore "gx/ipfs/QmTVDM4LCSUMFNQzbDLL9zQwp8usE6QHymFdh3h8vL9v6b/go-ipfs-blockstore"
21 cmds "gx/ipfs/QmZ9hww8R3FKrDRCYPxhN13m6XgjPDpaSvdUfisPvERzXz/go-ipfs-cmds"
22 cid "gx/ipfs/QmcZfnkapfECQGcLZaf9B79NRg7cRa9EnZh4LSbkCzwNvY/go-cid"
23 cmdkit "gx/ipfs/QmceUdzxkimdYsgtX733uNgzf1DLHyBKN6ehGSp85ayppM/go-ipfs-cmdkit"
core/core.go
+1 -1
@@ -21,7 +21,6 @@ import (
21 "strings"
22 "time"
23
24 - bstore "github.com/ipfs/go-ipfs/blocks/blockstore"
24 bserv "github.com/ipfs/go-ipfs/blockservice"
25 exchange "github.com/ipfs/go-ipfs/exchange"
26 bitswap "github.com/ipfs/go-ipfs/exchange/bitswap"
@@ -55,6 +54,7 @@ import (
54 floodsub "gx/ipfs/QmSFihvoND3eDaAYRCeLgLPt62yCPgMZs1NSZmKFEtJQQw/go-libp2p-floodsub"
55 mamask "gx/ipfs/QmSMZwvs3n4GBikZ7hKzT17c3bk65FmyZo2JqtJ16swqCv/multiaddr-filter"
56 swarm "gx/ipfs/QmSwZMWwFZSUpe5muU2xgTUwppH24KfMwdPXiwbEp2c6G5/go-libp2p-swarm"
57 + bstore "gx/ipfs/QmTVDM4LCSUMFNQzbDLL9zQwp8usE6QHymFdh3h8vL9v6b/go-ipfs-blockstore"
58 routing "gx/ipfs/QmTiWLZ6Fo5j4KcTVutZJ5KWRRJrbxzmxA4td8NfEdrPh7/go-libp2p-routing"
59 dht "gx/ipfs/QmVSep2WwKcXxMonPASsAJ3nZVjfVMKgMcaSigxKnUWpJv/go-libp2p-kad-dht"
60 circuit "gx/ipfs/QmVTnHzuyECV9JzbXXfZRj1pKtgknp1esamUb2EH33mJkA/go-libp2p-circuit"
core/coreapi/block.go
+1 -1
@@ -8,7 +8,7 @@ import (
8 "io"
9 "io/ioutil"
10
11 - util "github.com/ipfs/go-ipfs/blocks/blockstore/util"
11 + util "github.com/ipfs/go-ipfs/blocks/blockstoreutil"
12 coreiface "github.com/ipfs/go-ipfs/core/coreapi/interface"
13 caopts "github.com/ipfs/go-ipfs/core/coreapi/interface/options"
14
core/coreunix/add.go
+3 -4
@@ -9,8 +9,6 @@ import (
9 gopath "path"
10 "strconv"
11
12 - bs "github.com/ipfs/go-ipfs/blocks/blockstore"
13 - bstore "github.com/ipfs/go-ipfs/blocks/blockstore"
12 bserv "github.com/ipfs/go-ipfs/blockservice"
13 core "github.com/ipfs/go-ipfs/core"
14 "github.com/ipfs/go-ipfs/exchange/offline"
@@ -21,12 +19,13 @@ import (
19 mfs "github.com/ipfs/go-ipfs/mfs"
20 "github.com/ipfs/go-ipfs/pin"
21 unixfs "github.com/ipfs/go-ipfs/unixfs"
24 - posinfo "gx/ipfs/Qmb3jLEFAQrqdVgWUajqEyuuDoavkSq1XQXz6tWdFWF995/go-ipfs-posinfo"
22
23 ds "gx/ipfs/QmPpegoMqhAEqjncrzArm7KVWAkCm78rqL2DPuNjhPrshg/go-datastore"
24 syncds "gx/ipfs/QmPpegoMqhAEqjncrzArm7KVWAkCm78rqL2DPuNjhPrshg/go-datastore/sync"
25 logging "gx/ipfs/QmRb5jh8z2E8hMGN2tkvs1yHynUanqnZ3UeKwgN1i9P1F8/go-log"
26 + bstore "gx/ipfs/QmTVDM4LCSUMFNQzbDLL9zQwp8usE6QHymFdh3h8vL9v6b/go-ipfs-blockstore"
27 chunker "gx/ipfs/QmWo8jYc19ppG7YoTsrr2kEtLRbARTJho5oNXFTR6B7Peq/go-ipfs-chunker"
28 + posinfo "gx/ipfs/Qmb3jLEFAQrqdVgWUajqEyuuDoavkSq1XQXz6tWdFWF995/go-ipfs-posinfo"
29 cid "gx/ipfs/QmcZfnkapfECQGcLZaf9B79NRg7cRa9EnZh4LSbkCzwNvY/go-cid"
30 files "gx/ipfs/QmceUdzxkimdYsgtX733uNgzf1DLHyBKN6ehGSp85ayppM/go-ipfs-cmdkit/files"
31 ipld "gx/ipfs/Qme5bWv7wtjUNGsK2BNGVUFPKiuxWrsqrtvYwCLRw8YFES/go-ipld-format"
@@ -107,7 +106,7 @@ type Adder struct {
106 Chunker string
107 root ipld.Node
108 mroot *mfs.Root
110 - unlocker bs.Unlocker
109 + unlocker bstore.Unlocker
110 tempRoot *cid.Cid
111 Prefix *cid.Prefix
112 liveNodes uint64
core/coreunix/add_test.go
+4 -4
@@ -10,7 +10,6 @@ import (
10 "testing"
11 "time"
12
13 - "github.com/ipfs/go-ipfs/blocks/blockstore"
13 "github.com/ipfs/go-ipfs/blockservice"
14 "github.com/ipfs/go-ipfs/core"
15 dag "github.com/ipfs/go-ipfs/merkledag"
@@ -18,11 +17,12 @@ import (
17 "github.com/ipfs/go-ipfs/repo"
18 "github.com/ipfs/go-ipfs/repo/config"
19 ds2 "github.com/ipfs/go-ipfs/thirdparty/datastore2"
21 - pi "gx/ipfs/Qmb3jLEFAQrqdVgWUajqEyuuDoavkSq1XQXz6tWdFWF995/go-ipfs-posinfo"
20
21 + blockstore "gx/ipfs/QmTVDM4LCSUMFNQzbDLL9zQwp8usE6QHymFdh3h8vL9v6b/go-ipfs-blockstore"
22 + pi "gx/ipfs/Qmb3jLEFAQrqdVgWUajqEyuuDoavkSq1XQXz6tWdFWF995/go-ipfs-posinfo"
23 cid "gx/ipfs/QmcZfnkapfECQGcLZaf9B79NRg7cRa9EnZh4LSbkCzwNvY/go-cid"
24 - "gx/ipfs/QmceUdzxkimdYsgtX733uNgzf1DLHyBKN6ehGSp85ayppM/go-ipfs-cmdkit/files"
25 - "gx/ipfs/Qmej7nf81hi2x2tvjRBF3mcp74sQyuDH4VMYDGd1YtXjb2/go-block-format"
24 + files "gx/ipfs/QmceUdzxkimdYsgtX733uNgzf1DLHyBKN6ehGSp85ayppM/go-ipfs-cmdkit/files"
25 + blocks "gx/ipfs/Qmej7nf81hi2x2tvjRBF3mcp74sQyuDH4VMYDGd1YtXjb2/go-block-format"
26 )
27
28 const testPeerID = "QmTFauExutTsy4XP6JbMFcw2Wa9645HJt2bTqL6qYDCKfe"
core/coreunix/metadata_test.go
+1 -1
@@ -6,7 +6,6 @@ import (
6 "io/ioutil"
7 "testing"
8
9 - bstore "github.com/ipfs/go-ipfs/blocks/blockstore"
9 bserv "github.com/ipfs/go-ipfs/blockservice"
10 core "github.com/ipfs/go-ipfs/core"
11 offline "github.com/ipfs/go-ipfs/exchange/offline"
@@ -18,6 +17,7 @@ import (
17 u "gx/ipfs/QmNiJuT8Ja3hMVpBHXv3Q6dwmperaQ6JjLtpMQgMCD7xvx/go-ipfs-util"
18 ds "gx/ipfs/QmPpegoMqhAEqjncrzArm7KVWAkCm78rqL2DPuNjhPrshg/go-datastore"
19 dssync "gx/ipfs/QmPpegoMqhAEqjncrzArm7KVWAkCm78rqL2DPuNjhPrshg/go-datastore/sync"
20 + bstore "gx/ipfs/QmTVDM4LCSUMFNQzbDLL9zQwp8usE6QHymFdh3h8vL9v6b/go-ipfs-blockstore"
21 chunker "gx/ipfs/QmWo8jYc19ppG7YoTsrr2kEtLRbARTJho5oNXFTR6B7Peq/go-ipfs-chunker"
22 cid "gx/ipfs/QmcZfnkapfECQGcLZaf9B79NRg7cRa9EnZh4LSbkCzwNvY/go-cid"
23 ipld "gx/ipfs/Qme5bWv7wtjUNGsK2BNGVUFPKiuxWrsqrtvYwCLRw8YFES/go-ipld-format"
exchange/bitswap/bitswap.go
+1 -1
@@ -10,7 +10,6 @@ import (
10 "sync/atomic"
11 "time"
12
13 - blockstore "github.com/ipfs/go-ipfs/blocks/blockstore"
13 exchange "github.com/ipfs/go-ipfs/exchange"
14 decision "github.com/ipfs/go-ipfs/exchange/bitswap/decision"
15 bsmsg "github.com/ipfs/go-ipfs/exchange/bitswap/message"
@@ -23,6 +22,7 @@ import (
22 metrics "gx/ipfs/QmRg1gKTHzc3CZXSKzem8aR4E3TubFhbgXwfVuWnSK5CC5/go-metrics-interface"
23 process "gx/ipfs/QmSF8fPo3jgVBAy8fpdjjYqgG87dkJgUprRBHRd2tmfgpP/goprocess"
24 procctx "gx/ipfs/QmSF8fPo3jgVBAy8fpdjjYqgG87dkJgUprRBHRd2tmfgpP/goprocess/context"
25 + blockstore "gx/ipfs/QmTVDM4LCSUMFNQzbDLL9zQwp8usE6QHymFdh3h8vL9v6b/go-ipfs-blockstore"
26 peer "gx/ipfs/QmZoWKhxUmZ2seW4BzX6fJkNR8hh9PsGModr7q171yq2SS/go-libp2p-peer"
27 cid "gx/ipfs/QmcZfnkapfECQGcLZaf9B79NRg7cRa9EnZh4LSbkCzwNvY/go-cid"
28 blocks "gx/ipfs/Qmej7nf81hi2x2tvjRBF3mcp74sQyuDH4VMYDGd1YtXjb2/go-block-format"
exchange/bitswap/bitswap_test.go
+1 -1
@@ -8,12 +8,12 @@ import (
8 "testing"
9 "time"
10
11 - blockstore "github.com/ipfs/go-ipfs/blocks/blockstore"
11 blocksutil "github.com/ipfs/go-ipfs/blocks/blocksutil"
12 decision "github.com/ipfs/go-ipfs/exchange/bitswap/decision"
13 tn "github.com/ipfs/go-ipfs/exchange/bitswap/testnet"
14
15 delay "gx/ipfs/QmRJVNatYJwTAHgdSM1Xef9QVQ1Ch3XHdmcrykjP5Y4soL/go-ipfs-delay"
16 + blockstore "gx/ipfs/QmTVDM4LCSUMFNQzbDLL9zQwp8usE6QHymFdh3h8vL9v6b/go-ipfs-blockstore"
17 tu "gx/ipfs/QmVvkK7s5imCiq3JVbL3pGfnhcCnf3LrFJPF4GE2sAoGZf/go-testutil"
18 travis "gx/ipfs/QmVvkK7s5imCiq3JVbL3pGfnhcCnf3LrFJPF4GE2sAoGZf/go-testutil/ci/travis"
19 p2ptestutil "gx/ipfs/QmYVR3C8DWPHdHxvLtNFYfjsXgaRAdh6hPMNH3KiwCgu4o/go-libp2p-netutil"
exchange/bitswap/decision/engine.go
+2 -1
@@ -6,10 +6,11 @@ import (
6 "sync"
7 "time"
8
9 - bstore "github.com/ipfs/go-ipfs/blocks/blockstore"
9 bsmsg "github.com/ipfs/go-ipfs/exchange/bitswap/message"
10 wl "github.com/ipfs/go-ipfs/exchange/bitswap/wantlist"
11 +
12 logging "gx/ipfs/QmRb5jh8z2E8hMGN2tkvs1yHynUanqnZ3UeKwgN1i9P1F8/go-log"
13 + bstore "gx/ipfs/QmTVDM4LCSUMFNQzbDLL9zQwp8usE6QHymFdh3h8vL9v6b/go-ipfs-blockstore"
14 peer "gx/ipfs/QmZoWKhxUmZ2seW4BzX6fJkNR8hh9PsGModr7q171yq2SS/go-libp2p-peer"
15 blocks "gx/ipfs/Qmej7nf81hi2x2tvjRBF3mcp74sQyuDH4VMYDGd1YtXjb2/go-block-format"
16 )
exchange/bitswap/decision/engine_test.go
+2 -1
@@ -9,10 +9,11 @@ import (
9 "sync"
10 "testing"
11
12 - blockstore "github.com/ipfs/go-ipfs/blocks/blockstore"
12 message "github.com/ipfs/go-ipfs/exchange/bitswap/message"
13 +
14 ds "gx/ipfs/QmPpegoMqhAEqjncrzArm7KVWAkCm78rqL2DPuNjhPrshg/go-datastore"
15 dssync "gx/ipfs/QmPpegoMqhAEqjncrzArm7KVWAkCm78rqL2DPuNjhPrshg/go-datastore/sync"
16 + blockstore "gx/ipfs/QmTVDM4LCSUMFNQzbDLL9zQwp8usE6QHymFdh3h8vL9v6b/go-ipfs-blockstore"
17 testutil "gx/ipfs/QmVvkK7s5imCiq3JVbL3pGfnhcCnf3LrFJPF4GE2sAoGZf/go-testutil"
18 peer "gx/ipfs/QmZoWKhxUmZ2seW4BzX6fJkNR8hh9PsGModr7q171yq2SS/go-libp2p-peer"
19 blocks "gx/ipfs/Qmej7nf81hi2x2tvjRBF3mcp74sQyuDH4VMYDGd1YtXjb2/go-block-format"
exchange/bitswap/get.go
+2 -2
@@ -4,11 +4,11 @@ import (
4 "context"
5 "errors"
6
7 - blockstore "github.com/ipfs/go-ipfs/blocks/blockstore"
7 notifications "github.com/ipfs/go-ipfs/exchange/bitswap/notifications"
9 - blocks "gx/ipfs/Qmej7nf81hi2x2tvjRBF3mcp74sQyuDH4VMYDGd1YtXjb2/go-block-format"
8
9 + blockstore "gx/ipfs/QmTVDM4LCSUMFNQzbDLL9zQwp8usE6QHymFdh3h8vL9v6b/go-ipfs-blockstore"
10 cid "gx/ipfs/QmcZfnkapfECQGcLZaf9B79NRg7cRa9EnZh4LSbkCzwNvY/go-cid"
11 + blocks "gx/ipfs/Qmej7nf81hi2x2tvjRBF3mcp74sQyuDH4VMYDGd1YtXjb2/go-block-format"
12 )
13
14 type getBlocksFunc func(context.Context, []*cid.Cid) (<-chan blocks.Block, error)
exchange/bitswap/testutils.go
+1 -1
@@ -4,13 +4,13 @@ import (
4 "context"
5 "time"
6
7 - blockstore "github.com/ipfs/go-ipfs/blocks/blockstore"
7 tn "github.com/ipfs/go-ipfs/exchange/bitswap/testnet"
8 datastore2 "github.com/ipfs/go-ipfs/thirdparty/datastore2"
9
10 ds "gx/ipfs/QmPpegoMqhAEqjncrzArm7KVWAkCm78rqL2DPuNjhPrshg/go-datastore"
11 ds_sync "gx/ipfs/QmPpegoMqhAEqjncrzArm7KVWAkCm78rqL2DPuNjhPrshg/go-datastore/sync"
12 delay "gx/ipfs/QmRJVNatYJwTAHgdSM1Xef9QVQ1Ch3XHdmcrykjP5Y4soL/go-ipfs-delay"
13 + blockstore "gx/ipfs/QmTVDM4LCSUMFNQzbDLL9zQwp8usE6QHymFdh3h8vL9v6b/go-ipfs-blockstore"
14 testutil "gx/ipfs/QmVvkK7s5imCiq3JVbL3pGfnhcCnf3LrFJPF4GE2sAoGZf/go-testutil"
15 p2ptestutil "gx/ipfs/QmYVR3C8DWPHdHxvLtNFYfjsXgaRAdh6hPMNH3KiwCgu4o/go-libp2p-netutil"
16 peer "gx/ipfs/QmZoWKhxUmZ2seW4BzX6fJkNR8hh9PsGModr7q171yq2SS/go-libp2p-peer"
exchange/offline/offline.go
+2 -2
@@ -5,11 +5,11 @@ package offline
5 import (
6 "context"
7
8 - "github.com/ipfs/go-ipfs/blocks/blockstore"
8 exchange "github.com/ipfs/go-ipfs/exchange"
10 - blocks "gx/ipfs/Qmej7nf81hi2x2tvjRBF3mcp74sQyuDH4VMYDGd1YtXjb2/go-block-format"
9
10 + blockstore "gx/ipfs/QmTVDM4LCSUMFNQzbDLL9zQwp8usE6QHymFdh3h8vL9v6b/go-ipfs-blockstore"
11 cid "gx/ipfs/QmcZfnkapfECQGcLZaf9B79NRg7cRa9EnZh4LSbkCzwNvY/go-cid"
12 + blocks "gx/ipfs/Qmej7nf81hi2x2tvjRBF3mcp74sQyuDH4VMYDGd1YtXjb2/go-block-format"
13 )
14
15 func Exchange(bs blockstore.Blockstore) exchange.Interface {
exchange/offline/offline_test.go
+2 -2
@@ -4,14 +4,14 @@ import (
4 "context"
5 "testing"
6
7 - "github.com/ipfs/go-ipfs/blocks/blockstore"
7 "github.com/ipfs/go-ipfs/blocks/blocksutil"
9 - blocks "gx/ipfs/Qmej7nf81hi2x2tvjRBF3mcp74sQyuDH4VMYDGd1YtXjb2/go-block-format"
8
9 u "gx/ipfs/QmNiJuT8Ja3hMVpBHXv3Q6dwmperaQ6JjLtpMQgMCD7xvx/go-ipfs-util"
10 ds "gx/ipfs/QmPpegoMqhAEqjncrzArm7KVWAkCm78rqL2DPuNjhPrshg/go-datastore"
11 ds_sync "gx/ipfs/QmPpegoMqhAEqjncrzArm7KVWAkCm78rqL2DPuNjhPrshg/go-datastore/sync"
12 + blockstore "gx/ipfs/QmTVDM4LCSUMFNQzbDLL9zQwp8usE6QHymFdh3h8vL9v6b/go-ipfs-blockstore"
13 cid "gx/ipfs/QmcZfnkapfECQGcLZaf9B79NRg7cRa9EnZh4LSbkCzwNvY/go-cid"
14 + blocks "gx/ipfs/Qmej7nf81hi2x2tvjRBF3mcp74sQyuDH4VMYDGd1YtXjb2/go-block-format"
15 )
16
17 func TestBlockReturnsErr(t *testing.T) {
exchange/reprovide/providers.go
+2 -2
@@ -3,12 +3,12 @@ package reprovide
3 import (
4 "context"
5
6 - blocks "github.com/ipfs/go-ipfs/blocks/blockstore"
6 merkledag "github.com/ipfs/go-ipfs/merkledag"
7 pin "github.com/ipfs/go-ipfs/pin"
9 - ipld "gx/ipfs/Qme5bWv7wtjUNGsK2BNGVUFPKiuxWrsqrtvYwCLRw8YFES/go-ipld-format"
8
9 + blocks "gx/ipfs/QmTVDM4LCSUMFNQzbDLL9zQwp8usE6QHymFdh3h8vL9v6b/go-ipfs-blockstore"
10 cid "gx/ipfs/QmcZfnkapfECQGcLZaf9B79NRg7cRa9EnZh4LSbkCzwNvY/go-cid"
11 + ipld "gx/ipfs/Qme5bWv7wtjUNGsK2BNGVUFPKiuxWrsqrtvYwCLRw8YFES/go-ipld-format"
12 )
13
14 // NewBlockstoreProvider returns key provider using bstore.AllKeysChan
exchange/reprovide/reprovide_test.go
+1 -2
@@ -4,10 +4,9 @@ import (
4 "context"
5 "testing"
6
7 - blockstore "github.com/ipfs/go-ipfs/blocks/blockstore"
8 -
7 ds "gx/ipfs/QmPpegoMqhAEqjncrzArm7KVWAkCm78rqL2DPuNjhPrshg/go-datastore"
8 dssync "gx/ipfs/QmPpegoMqhAEqjncrzArm7KVWAkCm78rqL2DPuNjhPrshg/go-datastore/sync"
9 + blockstore "gx/ipfs/QmTVDM4LCSUMFNQzbDLL9zQwp8usE6QHymFdh3h8vL9v6b/go-ipfs-blockstore"
10 testutil "gx/ipfs/QmVvkK7s5imCiq3JVbL3pGfnhcCnf3LrFJPF4GE2sAoGZf/go-testutil"
11 pstore "gx/ipfs/QmXauCuJzmzapetmC6W4TuDJLL1yFFrVzSHoWv8YdbmnxH/go-libp2p-peerstore"
12 mock "gx/ipfs/QmZRcGYvxdauCd7hHnMYLYqcZRaDjv24c7eUNyJojAcdBb/go-ipfs-routing/mock"
filestore/filestore.go
+1 -2
@@ -10,10 +10,9 @@ package filestore
10 import (
11 "context"
12
13 - "github.com/ipfs/go-ipfs/blocks/blockstore"
14 -
13 dsq "gx/ipfs/QmPpegoMqhAEqjncrzArm7KVWAkCm78rqL2DPuNjhPrshg/go-datastore/query"
14 logging "gx/ipfs/QmRb5jh8z2E8hMGN2tkvs1yHynUanqnZ3UeKwgN1i9P1F8/go-log"
15 + blockstore "gx/ipfs/QmTVDM4LCSUMFNQzbDLL9zQwp8usE6QHymFdh3h8vL9v6b/go-ipfs-blockstore"
16 posinfo "gx/ipfs/Qmb3jLEFAQrqdVgWUajqEyuuDoavkSq1XQXz6tWdFWF995/go-ipfs-posinfo"
17 cid "gx/ipfs/QmcZfnkapfECQGcLZaf9B79NRg7cRa9EnZh4LSbkCzwNvY/go-cid"
18 blocks "gx/ipfs/Qmej7nf81hi2x2tvjRBF3mcp74sQyuDH4VMYDGd1YtXjb2/go-block-format"
filestore/filestore_test.go
+2 -2
@@ -7,11 +7,11 @@ import (
7 "math/rand"
8 "testing"
9
10 - "github.com/ipfs/go-ipfs/blocks/blockstore"
10 dag "github.com/ipfs/go-ipfs/merkledag"
12 - posinfo "gx/ipfs/Qmb3jLEFAQrqdVgWUajqEyuuDoavkSq1XQXz6tWdFWF995/go-ipfs-posinfo"
11
12 ds "gx/ipfs/QmPpegoMqhAEqjncrzArm7KVWAkCm78rqL2DPuNjhPrshg/go-datastore"
13 + blockstore "gx/ipfs/QmTVDM4LCSUMFNQzbDLL9zQwp8usE6QHymFdh3h8vL9v6b/go-ipfs-blockstore"
14 + posinfo "gx/ipfs/Qmb3jLEFAQrqdVgWUajqEyuuDoavkSq1XQXz6tWdFWF995/go-ipfs-posinfo"
15 cid "gx/ipfs/QmcZfnkapfECQGcLZaf9B79NRg7cRa9EnZh4LSbkCzwNvY/go-cid"
16 )
17
filestore/fsrefstore.go
+1 -1
@@ -7,13 +7,13 @@ import (
7 "os"
8 "path/filepath"
9
10 - "github.com/ipfs/go-ipfs/blocks/blockstore"
10 pb "github.com/ipfs/go-ipfs/filestore/pb"
11
12 ds "gx/ipfs/QmPpegoMqhAEqjncrzArm7KVWAkCm78rqL2DPuNjhPrshg/go-datastore"
13 dsns "gx/ipfs/QmPpegoMqhAEqjncrzArm7KVWAkCm78rqL2DPuNjhPrshg/go-datastore/namespace"
14 dsq "gx/ipfs/QmPpegoMqhAEqjncrzArm7KVWAkCm78rqL2DPuNjhPrshg/go-datastore/query"
15 proto "gx/ipfs/QmT6n4mspWYEya864BhCUJEgyxiRfmiSY9ruQwTUNpRKaM/protobuf/proto"
16 + blockstore "gx/ipfs/QmTVDM4LCSUMFNQzbDLL9zQwp8usE6QHymFdh3h8vL9v6b/go-ipfs-blockstore"
17 posinfo "gx/ipfs/Qmb3jLEFAQrqdVgWUajqEyuuDoavkSq1XQXz6tWdFWF995/go-ipfs-posinfo"
18 cid "gx/ipfs/QmcZfnkapfECQGcLZaf9B79NRg7cRa9EnZh4LSbkCzwNvY/go-cid"
19 dshelp "gx/ipfs/QmdQTPWduSeyveSxeCAte33M592isSW5Z979g81aJphrgn/go-ipfs-ds-help"
filestore/util.go
+1 -1
@@ -4,11 +4,11 @@ import (
4 "fmt"
5 "sort"
6
7 - "github.com/ipfs/go-ipfs/blocks/blockstore"
7 pb "github.com/ipfs/go-ipfs/filestore/pb"
8
9 ds "gx/ipfs/QmPpegoMqhAEqjncrzArm7KVWAkCm78rqL2DPuNjhPrshg/go-datastore"
10 dsq "gx/ipfs/QmPpegoMqhAEqjncrzArm7KVWAkCm78rqL2DPuNjhPrshg/go-datastore/query"
11 + blockstore "gx/ipfs/QmTVDM4LCSUMFNQzbDLL9zQwp8usE6QHymFdh3h8vL9v6b/go-ipfs-blockstore"
12 cid "gx/ipfs/QmcZfnkapfECQGcLZaf9B79NRg7cRa9EnZh4LSbkCzwNvY/go-cid"
13 dshelp "gx/ipfs/QmdQTPWduSeyveSxeCAte33M592isSW5Z979g81aJphrgn/go-ipfs-ds-help"
14 )
merkledag/test/utils.go
+1 -1
@@ -1,13 +1,13 @@
1 package mdutils
2
3 import (
4 - "github.com/ipfs/go-ipfs/blocks/blockstore"
4 bsrv "github.com/ipfs/go-ipfs/blockservice"
5 "github.com/ipfs/go-ipfs/exchange/offline"
6 dag "github.com/ipfs/go-ipfs/merkledag"
7
8 ds "gx/ipfs/QmPpegoMqhAEqjncrzArm7KVWAkCm78rqL2DPuNjhPrshg/go-datastore"
9 dssync "gx/ipfs/QmPpegoMqhAEqjncrzArm7KVWAkCm78rqL2DPuNjhPrshg/go-datastore/sync"
10 + blockstore "gx/ipfs/QmTVDM4LCSUMFNQzbDLL9zQwp8usE6QHymFdh3h8vL9v6b/go-ipfs-blockstore"
11 ipld "gx/ipfs/Qme5bWv7wtjUNGsK2BNGVUFPKiuxWrsqrtvYwCLRw8YFES/go-ipld-format"
12 )
13
merkledag/utils/utils.go
+1 -1
@@ -4,7 +4,6 @@ import (
4 "context"
5 "errors"
6
7 - bstore "github.com/ipfs/go-ipfs/blocks/blockstore"
7 bserv "github.com/ipfs/go-ipfs/blockservice"
8 offline "github.com/ipfs/go-ipfs/exchange/offline"
9 dag "github.com/ipfs/go-ipfs/merkledag"
@@ -12,6 +11,7 @@ import (
11
12 ds "gx/ipfs/QmPpegoMqhAEqjncrzArm7KVWAkCm78rqL2DPuNjhPrshg/go-datastore"
13 syncds "gx/ipfs/QmPpegoMqhAEqjncrzArm7KVWAkCm78rqL2DPuNjhPrshg/go-datastore/sync"
14 + bstore "gx/ipfs/QmTVDM4LCSUMFNQzbDLL9zQwp8usE6QHymFdh3h8vL9v6b/go-ipfs-blockstore"
15 ipld "gx/ipfs/Qme5bWv7wtjUNGsK2BNGVUFPKiuxWrsqrtvYwCLRw8YFES/go-ipld-format"
16 )
17
mfs/mfs_test.go
+1 -1
@@ -14,7 +14,6 @@ import (
14 "testing"
15 "time"
16
17 - bstore "github.com/ipfs/go-ipfs/blocks/blockstore"
17 bserv "github.com/ipfs/go-ipfs/blockservice"
18 offline "github.com/ipfs/go-ipfs/exchange/offline"
19 importer "github.com/ipfs/go-ipfs/importer"
@@ -26,6 +25,7 @@ import (
25 u "gx/ipfs/QmNiJuT8Ja3hMVpBHXv3Q6dwmperaQ6JjLtpMQgMCD7xvx/go-ipfs-util"
26 ds "gx/ipfs/QmPpegoMqhAEqjncrzArm7KVWAkCm78rqL2DPuNjhPrshg/go-datastore"
27 dssync "gx/ipfs/QmPpegoMqhAEqjncrzArm7KVWAkCm78rqL2DPuNjhPrshg/go-datastore/sync"
28 + bstore "gx/ipfs/QmTVDM4LCSUMFNQzbDLL9zQwp8usE6QHymFdh3h8vL9v6b/go-ipfs-blockstore"
29 chunker "gx/ipfs/QmWo8jYc19ppG7YoTsrr2kEtLRbARTJho5oNXFTR6B7Peq/go-ipfs-chunker"
30 cid "gx/ipfs/QmcZfnkapfECQGcLZaf9B79NRg7cRa9EnZh4LSbkCzwNvY/go-cid"
31 ipld "gx/ipfs/Qme5bWv7wtjUNGsK2BNGVUFPKiuxWrsqrtvYwCLRw8YFES/go-ipld-format"
package.json
+6
@@ -557,6 +557,12 @@
557 "hash": "QmZRcGYvxdauCd7hHnMYLYqcZRaDjv24c7eUNyJojAcdBb",
558 "name": "go-ipfs-routing",
559 "version": "0.0.1"
560 + },
561 + {
562 + "author": "hsanjuan",
563 + "hash": "QmTVDM4LCSUMFNQzbDLL9zQwp8usE6QHymFdh3h8vL9v6b",
564 + "name": "go-ipfs-blockstore",
565 + "version": "0.0.1"
566 }
567 ],
568 "gxVersion": "0.10.0",
pin/gc/gc.go
+1 -1
@@ -6,7 +6,6 @@ import (
6 "errors"
7 "fmt"
8
9 - bstore "github.com/ipfs/go-ipfs/blocks/blockstore"
9 bserv "github.com/ipfs/go-ipfs/blockservice"
10 offline "github.com/ipfs/go-ipfs/exchange/offline"
11 dag "github.com/ipfs/go-ipfs/merkledag"
@@ -14,6 +13,7 @@ import (
13
14 dstore "gx/ipfs/QmPpegoMqhAEqjncrzArm7KVWAkCm78rqL2DPuNjhPrshg/go-datastore"
15 logging "gx/ipfs/QmRb5jh8z2E8hMGN2tkvs1yHynUanqnZ3UeKwgN1i9P1F8/go-log"
16 + bstore "gx/ipfs/QmTVDM4LCSUMFNQzbDLL9zQwp8usE6QHymFdh3h8vL9v6b/go-ipfs-blockstore"
17 cid "gx/ipfs/QmcZfnkapfECQGcLZaf9B79NRg7cRa9EnZh4LSbkCzwNvY/go-cid"
18 ipld "gx/ipfs/Qme5bWv7wtjUNGsK2BNGVUFPKiuxWrsqrtvYwCLRw8YFES/go-ipld-format"
19 )
pin/pin_test.go
+2 -2
@@ -5,14 +5,14 @@ import (
5 "testing"
6 "time"
7
8 - "github.com/ipfs/go-ipfs/blocks/blockstore"
8 bs "github.com/ipfs/go-ipfs/blockservice"
9 "github.com/ipfs/go-ipfs/exchange/offline"
10 mdag "github.com/ipfs/go-ipfs/merkledag"
11
13 - "gx/ipfs/QmNiJuT8Ja3hMVpBHXv3Q6dwmperaQ6JjLtpMQgMCD7xvx/go-ipfs-util"
12 + util "gx/ipfs/QmNiJuT8Ja3hMVpBHXv3Q6dwmperaQ6JjLtpMQgMCD7xvx/go-ipfs-util"
13 ds "gx/ipfs/QmPpegoMqhAEqjncrzArm7KVWAkCm78rqL2DPuNjhPrshg/go-datastore"
14 dssync "gx/ipfs/QmPpegoMqhAEqjncrzArm7KVWAkCm78rqL2DPuNjhPrshg/go-datastore/sync"
15 + blockstore "gx/ipfs/QmTVDM4LCSUMFNQzbDLL9zQwp8usE6QHymFdh3h8vL9v6b/go-ipfs-blockstore"
16 cid "gx/ipfs/QmcZfnkapfECQGcLZaf9B79NRg7cRa9EnZh4LSbkCzwNvY/go-cid"
17 )
18
pin/set_test.go
+1 -1
@@ -5,13 +5,13 @@ import (
5 "encoding/binary"
6 "testing"
7
8 - blockstore "github.com/ipfs/go-ipfs/blocks/blockstore"
8 bserv "github.com/ipfs/go-ipfs/blockservice"
9 offline "github.com/ipfs/go-ipfs/exchange/offline"
10 dag "github.com/ipfs/go-ipfs/merkledag"
11
12 ds "gx/ipfs/QmPpegoMqhAEqjncrzArm7KVWAkCm78rqL2DPuNjhPrshg/go-datastore"
13 dsq "gx/ipfs/QmPpegoMqhAEqjncrzArm7KVWAkCm78rqL2DPuNjhPrshg/go-datastore/query"
14 + blockstore "gx/ipfs/QmTVDM4LCSUMFNQzbDLL9zQwp8usE6QHymFdh3h8vL9v6b/go-ipfs-blockstore"
15 cid "gx/ipfs/QmcZfnkapfECQGcLZaf9B79NRg7cRa9EnZh4LSbkCzwNvY/go-cid"
16 )
17