Commit 707e5498 authored by Whyrusleeping's avatar Whyrusleeping Committed by GitHub

Merge pull request #4649 from ipfs/feat/blockservice-events

blockservice: add BlockedFetched/Added/Removed events
parents 9764858e 3d6da969
...@@ -146,6 +146,8 @@ func (s *blockService) AddBlock(o blocks.Block) error { ...@@ -146,6 +146,8 @@ func (s *blockService) AddBlock(o blocks.Block) error {
return err return err
} }
log.Event(context.TODO(), "BlockService.BlockAdded", c)
if err := s.exchange.HasBlock(o); err != nil { if err := s.exchange.HasBlock(o); err != nil {
// TODO(#4623): really an error? // TODO(#4623): really an error?
return errors.New("blockservice is closed") return errors.New("blockservice is closed")
...@@ -184,6 +186,7 @@ func (s *blockService) AddBlocks(bs []blocks.Block) error { ...@@ -184,6 +186,7 @@ func (s *blockService) AddBlocks(bs []blocks.Block) error {
} }
for _, o := range toput { for _, o := range toput {
log.Event(context.TODO(), "BlockService.BlockAdded", o.Cid())
if err := s.exchange.HasBlock(o); err != nil { if err := s.exchange.HasBlock(o); err != nil {
// TODO(#4623): Should this really *return*? // TODO(#4623): Should this really *return*?
return fmt.Errorf("blockservice is closed (%s)", err) return fmt.Errorf("blockservice is closed (%s)", err)
...@@ -227,6 +230,7 @@ func getBlock(ctx context.Context, c *cid.Cid, bs blockstore.Blockstore, f excha ...@@ -227,6 +230,7 @@ func getBlock(ctx context.Context, c *cid.Cid, bs blockstore.Blockstore, f excha
} }
return nil, err return nil, err
} }
log.Event(ctx, "BlockService.BlockFetched", c)
return blk, nil return blk, nil
} }
...@@ -263,7 +267,6 @@ func getBlocks(ctx context.Context, ks []*cid.Cid, bs blockstore.Blockstore, f e ...@@ -263,7 +267,6 @@ func getBlocks(ctx context.Context, ks []*cid.Cid, bs blockstore.Blockstore, f e
misses = append(misses, c) misses = append(misses, c)
continue continue
} }
log.Debug("Blockservice: Got data in datastore")
select { select {
case out <- hit: case out <- hit:
case <-ctx.Done(): case <-ctx.Done():
...@@ -282,6 +285,7 @@ func getBlocks(ctx context.Context, ks []*cid.Cid, bs blockstore.Blockstore, f e ...@@ -282,6 +285,7 @@ func getBlocks(ctx context.Context, ks []*cid.Cid, bs blockstore.Blockstore, f e
} }
for b := range rblocks { for b := range rblocks {
log.Event(ctx, "BlockService.BlockFetched", b.Cid())
select { select {
case out <- b: case out <- b:
case <-ctx.Done(): case <-ctx.Done():
...@@ -294,7 +298,11 @@ func getBlocks(ctx context.Context, ks []*cid.Cid, bs blockstore.Blockstore, f e ...@@ -294,7 +298,11 @@ func getBlocks(ctx context.Context, ks []*cid.Cid, bs blockstore.Blockstore, f e
// DeleteBlock deletes a block in the blockservice from the datastore // DeleteBlock deletes a block in the blockservice from the datastore
func (s *blockService) DeleteBlock(c *cid.Cid) error { func (s *blockService) DeleteBlock(c *cid.Cid) error {
return s.blockstore.DeleteBlock(c) err := s.blockstore.DeleteBlock(c)
if err == nil {
log.Event(context.TODO(), "BlockService.BlockDeleted", c)
}
return err
} }
func (s *blockService) Close() error { func (s *blockService) Close() 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