Skip to content
This repository has been archived by the owner on Jun 26, 2023. It is now read-only.

Avoid loading all pins into memory during migration #5

Merged
merged 3 commits into from
Jan 27, 2021

Conversation

gammazero
Copy link

Converting to datastore-based pins requires loading all dag-storage pins into memory, in addition to indirect pins. This is unnecessary for conversion, and much memory can be saved by avoiding loading all pins. An additional fix removes an unnecessary map that was created during conversion, costing even more memory.

On systems with very large pin sets, this fix helps prevent low memory conditions during migration.

…ins into memory, in addition to indirect pins. This is unnecessary for conversion, and much memory can be saved by avoiding loading all pins.
Copy link

@aschmahmann aschmahmann left a comment

Choose a reason for hiding this comment

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

LGTM, added a couple small comments/suggestions. Feel free to merge + release + bubble to go-ipfs + fs-repo-migrations when ready

ipldpinner/pin_test.go Show resolved Hide resolved
@@ -219,13 +219,15 @@ func walkItems(ctx context.Context, dag ipld.DAGService, n *merkledag.ProtoNode,
// readHdr guarantees fanout is a safe value
fanout := hdr.GetFanout()
for i, l := range n.Links()[fanout:] {
if err := fn(i, l); err != nil {

Choose a reason for hiding this comment

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

why remove the shadow here (and below)? it's fine since we never return err anywhere else, but one of the nice things with shadowing err here is that it's obvious that there's not some higher scope err we're supposed to be keeping track of.

Copy link
Author

@gammazero gammazero Jan 27, 2021

Choose a reason for hiding this comment

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

I thought shadowing err was generally something to avoid. The primary reason being that someone may write a deferred function that closes over err and checks its value, and the author may not notice the shadowing.

However, I can also see the other side of that, that shadowing guarantees that the variable in the outer scope is not overwritten. I generally tend to avoid shadowing as a general pattern since I think more bugs result from shadowing as opposed to not shadowing.

@aschmahmann aschmahmann merged commit 9ed588a into master Jan 27, 2021
@aschmahmann aschmahmann deleted the fix/conv-mem-use branch January 27, 2021 19:40
@aschmahmann aschmahmann mentioned this pull request Feb 18, 2021
73 tasks
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants