@cryptotaxi247 / kubo / commits / e86c82c68

Add log events when blocks are added/removed from the blockstore

License: MIT Signed-off-by: Michael Muré <mure.michael@gmail.com>

Michael Muré committed Oct 23, 2015 at 21:57 UTC e86c82c68d95c23bf6f4aba3d48e9182ee1328df
1 file changed +7 -1
blocks/blockstore/write_cache.go
+7 -1
@@ -22,6 +22,7 @@ type writecache struct {
22 }
23
24 func (w *writecache) DeleteBlock(k key.Key) error {
25 + defer log.EventBegin(context.TODO(), "writecache.BlockRemoved", &k).Done()
26 w.cache.Remove(k)
27 return w.blockstore.DeleteBlock(k)
28 }
@@ -38,9 +39,12 @@ func (w *writecache) Get(k key.Key) (*blocks.Block, error) {
39 }
40
41 func (w *writecache) Put(b *blocks.Block) error {
41 - if _, ok := w.cache.Get(b.Key()); ok {
42 + k := b.Key()
43 + if _, ok := w.cache.Get(k); ok {
44 return nil
45 }
46 + defer log.EventBegin(context.TODO(), "writecache.BlockAdded", &k).Done()
47 +
48 w.cache.Add(b.Key(), struct{}{})
49 return w.blockstore.Put(b)
50 }
@@ -50,6 +54,8 @@ func (w *writecache) PutMany(bs []*blocks.Block) error {
54 for _, b := range bs {
55 if _, ok := w.cache.Get(b.Key()); !ok {
56 good = append(good, b)
57 + k := b.Key()
58 + defer log.EventBegin(context.TODO(), "writecache.BlockAdded", &k).Done()
59 }
60 }
61 return w.blockstore.PutMany(good)