Merge pull request #5792 from filecoin-project/fix/timed-cache-locking
fix: avoid holding a lock while calling the View callback
This commit is contained in:
commit
25725110e7
@ -103,13 +103,20 @@ func (t *TimedCacheBlockstore) PutMany(bs []blocks.Block) error {
|
||||
}
|
||||
|
||||
func (t *TimedCacheBlockstore) View(k cid.Cid, callback func([]byte) error) error {
|
||||
// The underlying blockstore is always a "mem" blockstore so there's no difference,
|
||||
// from a performance perspective, between view & get. So we call Get to avoid
|
||||
// calling an arbitrary callback while holding a lock.
|
||||
t.mu.RLock()
|
||||
defer t.mu.RUnlock()
|
||||
err := t.active.View(k, callback)
|
||||
block, err := t.active.Get(k)
|
||||
if err == ErrNotFound {
|
||||
err = t.inactive.View(k, callback)
|
||||
block, err = t.inactive.Get(k)
|
||||
}
|
||||
return err
|
||||
t.mu.RUnlock()
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return callback(block.RawData())
|
||||
}
|
||||
|
||||
func (t *TimedCacheBlockstore) Get(k cid.Cid) (blocks.Block, error) {
|
||||
|
Loading…
Reference in New Issue
Block a user