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

dedup keys in GetMany #4888

Merged
merged 2 commits into from
Apr 8, 2018
Merged

dedup keys in GetMany #4888

merged 2 commits into from
Apr 8, 2018

Conversation

Stebalien
Copy link
Member

Otherwise, GetMany on the children of a node with duplicate links may fail

Otherwise, GetMany on the children of a node with duplicate links may fail

License: MIT
Signed-off-by: Steven Allen <[email protected]>
License: MIT
Signed-off-by: Steven Allen <[email protected]>
@Stebalien Stebalien requested a review from Kubuxu as a code owner March 28, 2018 21:13
@ghost ghost assigned Stebalien Mar 28, 2018
@ghost ghost added the status/in-progress In progress label Mar 28, 2018
@kevina
Copy link
Contributor

kevina commented Mar 29, 2018

I can see this adding overhead. Can you elaborate on what you mean by "GetMany on the children of a node with duplicate links may fail".

@Stebalien
Copy link
Member Author

We check to see if we get back the correct number of blocks and, if we don't, write an error to the channel. However, lower layers will (correctly) deduplicate requested keys so we'll end up getting back fewer blocks than we requested and think something has gone wrong.

@kevina
Copy link
Contributor

kevina commented Mar 29, 2018

Okay, deduplicating at every layer seams like unnecessary overhead, and my thoughts are that it maybe we should just not check at this level, but I am not familiar enough with the code to know for sure.

@Stebalien
Copy link
Member Author

Okay, deduplicating at every layer seams like unnecessary overhead, and my thoughts are that it maybe we should just not check at this level, but I am not familiar enough with the code to know for sure.

We could just say "make sure to deduplicate your own keys". Alternatively, we could not return an error when we can't find all requested objects. Really, I think we should go with the second (that's what the datastore does) but that will take some thought.

Also note, this is definitely not the performance bottleneck (unfortunately).

@@ -201,7 +201,20 @@ func (n *dagService) GetMany(ctx context.Context, keys []*cid.Cid) <-chan *ipld.
return getNodesFromBG(ctx, n.Blocks, keys)
}

func dedupKeys(keys []*cid.Cid) []*cid.Cid {
Copy link
Member

Choose a reason for hiding this comment

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

I think this can be done without copying the whole array to map and reverse by running a search over the rest of the array and remembering which indexes are duplicate.

IDK if it would be faster.

Copy link
Member Author

Choose a reason for hiding this comment

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

The "remember which indexes are duplicate" part is exactly what we're doing when copying to the map. We could modify the array instead of creating a new one but then we'd be modifying an argument. We could also sort and then dedup but this is probably faster.

@whyrusleeping
Copy link
Member

Good catch, but AFAIK the only user of GetMany is GetNodes (which is now extracted). I wonder if it would be better to just replace GetMany with GetNodes completely? where did this come up?

@Stebalien
Copy link
Member Author

where did this come up?

A patch I was writing to try to parallelize fetching a bit.

I wonder if it would be better to just replace GetMany with GetNodes completely? where did this come up?

You mean, replace it with an interface that fills in a promise array? This interface is useful when you don't care about the order (first come, first serve). Doing that with the GetNodes interface is tricky.

@Kubuxu Kubuxu added RFM and removed status/in-progress In progress labels Apr 7, 2018
@whyrusleeping whyrusleeping merged commit 8c2a420 into master Apr 8, 2018
@whyrusleeping whyrusleeping deleted the fix/dedup-keys branch April 8, 2018 00:43
ariescodescream pushed a commit to ariescodescream/go-ipfs that referenced this pull request Apr 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants