Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fail to construct preload hamt shards when traversal fails #55

Merged
merged 1 commit into from
Jul 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 24 additions & 7 deletions hamt/shardeddir.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,13 @@ func NewUnixFSHAMTShardWithPreload(ctx context.Context, substrate dagpb.PBNode,
return n, err
}

traverse := n.Length()
traverse, err := n.(*_UnixFSHAMTShard).length()
if traverse == -1 {
return n, fmt.Errorf("could not fully explore hamt during preload")
}
if err != nil {
return n, err
}

return n, nil
}
Expand Down Expand Up @@ -261,9 +264,9 @@ func (n UnixFSHAMTShard) ListIterator() ipld.ListIterator {

// Length returns the length of a list, or the number of entries in a map,
// or -1 if the node is not of list nor map kind.
func (n UnixFSHAMTShard) Length() int64 {
func (n UnixFSHAMTShard) length() (int64, error) {
if n.cachedLength != -1 {
return n.cachedLength
return n.cachedLength, nil
}
maxPadLen := maxPadLength(n.data)
total := int64(0)
Expand All @@ -272,20 +275,34 @@ func (n UnixFSHAMTShard) Length() int64 {
_, pbLink := itr.Next()
isValue, err := isValueLink(pbLink, maxPadLen)
if err != nil {
continue
return 0, err
}
if isValue {
total++
} else {
child, err := n.loadChild(pbLink)
if err != nil {
continue
return 0, err
}
total += child.Length()
cl, err := child.length()
if err != nil {
return 0, err
}
total += cl
}
}
n.cachedLength = total
return total
return total, nil
}

// Length returns the length of a list, or the number of entries in a map,
// or -1 if the node is not of list nor map kind.
func (n UnixFSHAMTShard) Length() int64 {
len, err := n.length()
if err != nil {
return 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't feel strongly about the number chosen here, as mentioned in ipld/go-ipld-prime#531 we're really in a rough spot here.

This is a behavior change from previously, but if you don't want to return -1 or a different negative number then 0 is probably more reasonable than what we were doing here before.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm happy to take suggestions - do you think it makes sense to do -2 or similar in this case?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer 0 until we have some kind of agreement on the best way to deal with ipld/go-ipld-prime#531, otherwise this is an outlier.

}
return len
}

func (n UnixFSHAMTShard) IsAbsent() bool {
Expand Down