Skip to content

Commit

Permalink
Merge pull request #4278 from filecoin-project/tvx/trace-puts
Browse files Browse the repository at this point in the history
tvx: trace puts to blockstore for inclusion in CAR.
  • Loading branch information
magik6k authored Oct 14, 2020
2 parents 465703b + e0dcb0e commit 4ad8d85
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions cmd/tvx/stores.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ type proxyingBlockstore struct {
ctx context.Context
api api.FullNode

lk sync.RWMutex
lk sync.Mutex
tracing bool
traced map[cid.Cid]struct{}

Expand All @@ -113,11 +113,11 @@ func (pb *proxyingBlockstore) FinishTracing() map[cid.Cid]struct{} {
}

func (pb *proxyingBlockstore) Get(cid cid.Cid) (blocks.Block, error) {
pb.lk.RLock()
pb.lk.Lock()
if pb.tracing {
pb.traced[cid] = struct{}{}
}
pb.lk.RUnlock()
pb.lk.Unlock()

if block, err := pb.Blockstore.Get(cid); err == nil {
return block, err
Expand All @@ -140,3 +140,12 @@ func (pb *proxyingBlockstore) Get(cid cid.Cid) (blocks.Block, error) {

return block, nil
}

func (pb *proxyingBlockstore) Put(block blocks.Block) error {
pb.lk.Lock()
if pb.tracing {
pb.traced[block.Cid()] = struct{}{}
}
pb.lk.Unlock()
return pb.Blockstore.Put(block)
}

0 comments on commit 4ad8d85

Please sign in to comment.