Skip to content

Commit

Permalink
ipfs: always get from cache (rather than peek)
Browse files Browse the repository at this point in the history
Previously we were peeking the cache to avoid inflating the hit counter
in commonly seen sequences like `stat;stat;open`. However, it's not
likely to be detrimental / cause unwanted evictions if calls to `stat`
update the hit counter for a file. It may actually allow some paths to
fall out of cache if they're merely being queried/monitored frequently,
which is undesirable.
  • Loading branch information
djdv committed Jun 29, 2023
1 parent f8968b0 commit 748a288
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 deletions internal/filesystem/ipfs/ipfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,9 @@ type (
info *nodeInfo
cid cid.Cid
}
arcMode bool
)

const (
IPFSID filesystem.ID = "IPFS"
arcGet arcMode = true
arcPeek arcMode = false
)
const IPFSID filesystem.ID = "IPFS"

// TODO: move assertions for exported types to a _test file
var (
Expand Down Expand Up @@ -249,7 +244,7 @@ func (fsys *IPFS) getInfo(name string, cid cid.Cid) (*nodeInfo, error) {
}

func (fsys *IPFS) fetchInfo(name string, cid cid.Cid) (*nodeInfo, error) {
node, err := fsys.getNode(arcPeek, cid)
node, err := fsys.getNode(cid)
if err != nil {
return nil, err
}
Expand All @@ -267,18 +262,15 @@ func (fsys *IPFS) fetchInfo(name string, cid cid.Cid) (*nodeInfo, error) {
return &info, nil
}

func (fsys *IPFS) getNode(mode arcMode, cid cid.Cid) (ipld.Node, error) {
func (fsys *IPFS) getNode(cid cid.Cid) (ipld.Node, error) {
cache := fsys.nodeCache
if cacheDisabled := cache == nil; cacheDisabled {
return fsys.fetchNode(cid)
}
var record ipfsRecord
if mode == arcGet {
var (
record, _ = cache.Get(cid)
} else {
record, _ = cache.Peek(cid)
}
node := record.Node
node = record.Node
)
if node != nil {
return node, nil
}
Expand Down Expand Up @@ -310,7 +302,7 @@ func (fsys *IPFS) nodeContext() (context.Context, context.CancelFunc) {

func (fsys *IPFS) walkLinks(root cid.Cid, names []string) (cid.Cid, error) {
return walkLinks(root, names, func(c cid.Cid) (ipld.Node, error) {
return fsys.getNode(arcPeek, c)
return fsys.getNode(c)
})
}

Expand Down Expand Up @@ -446,7 +438,7 @@ func (fsys *IPFS) fetchEntries(ctx context.Context, cid cid.Cid, info *nodeInfo)
}

func (fsys *IPFS) openFile(cid cid.Cid, info *nodeInfo) (fs.File, error) {
ipldNode, err := fsys.getNode(arcGet, cid)
ipldNode, err := fsys.getNode(cid)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 748a288

Please sign in to comment.