-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
change pinning to happen in a callback #1274
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,13 @@ import ( | |
"github.com/ipfs/go-ipfs/pin" | ||
) | ||
|
||
// NodeCB is callback function for dag generation | ||
// the `root` flag signifies whether or not this is | ||
// the root of a dag. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i mean this is weird, right, because every node is the root of a dag. maybe
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SGTM |
||
type NodeCB func(node *dag.Node, root bool) error | ||
|
||
var nilFunc NodeCB = func(_ *dag.Node, _ bool) error { return nil } | ||
|
||
// DagBuilderHelper wraps together a bunch of objects needed to | ||
// efficiently create unixfs dag trees | ||
type DagBuilderHelper struct { | ||
|
@@ -13,6 +20,7 @@ type DagBuilderHelper struct { | |
in <-chan []byte | ||
nextData []byte // the next item to return. | ||
maxlinks int | ||
ncb NodeCB | ||
} | ||
|
||
type DagBuilderParams struct { | ||
|
@@ -22,18 +30,23 @@ type DagBuilderParams struct { | |
// DAGService to write blocks to (required) | ||
Dagserv dag.DAGService | ||
|
||
// Pinner to use for pinning files (optionally nil) | ||
Pinner pin.ManualPinner | ||
// Callback for each block added | ||
NodeCB NodeCB | ||
} | ||
|
||
// Generate a new DagBuilderHelper from the given params, using 'in' as a | ||
// data source | ||
func (dbp *DagBuilderParams) New(in <-chan []byte) *DagBuilderHelper { | ||
ncb := dbp.NodeCB | ||
if ncb == nil { | ||
ncb = nilFunc | ||
} | ||
|
||
return &DagBuilderHelper{ | ||
dserv: dbp.Dagserv, | ||
mp: dbp.Pinner, | ||
in: in, | ||
maxlinks: dbp.Maxlinks, | ||
ncb: ncb, | ||
} | ||
} | ||
|
||
|
@@ -125,17 +138,15 @@ func (db *DagBuilderHelper) Add(node *UnixfsNode) (*dag.Node, error) { | |
return nil, err | ||
} | ||
|
||
key, err := db.dserv.Add(dn) | ||
_, err = db.dserv.Add(dn) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if db.mp != nil { | ||
db.mp.PinWithMode(key, pin.Recursive) | ||
err := db.mp.Flush() | ||
if err != nil { | ||
return nil, err | ||
} | ||
// node callback | ||
err = db.ncb(dn, true) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return dn, nil | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this being removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because it is added below (for all files found) and then re-added here?
why not just not pin anything until the end? i.e. remove the call to pin below and only pin recursively here after adding?
is the worry that something will GC in-between, while adding? (if so, ok makes sense).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thats what this PR is trying to avoid doing. in order to pin after the fact, you have to pull every single block in the dag back off the disk, and write the pin for it. This is really expensive when we get into the 50+GB range of add operations. (or in the 10MB+ range on my pi)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This too, a poorly timed gc could end really badly for us. (although its still not perfectly safe)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe mark and sweep is TRTTD
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On Wed, May 27, 2015 at 11:42:36AM -0700, Jeromy Johnson wrote:
I think the right approach here is to have transactional changes to
the pin tree (see also the commit sessions discussed in #1187).
Coupling that with something like Git's gc.pruneexpire to avoid
garbage-collecting recently-created objects (say, in the last week?)
would give us better safety here. It would also protect folks from
accidentally GC'ing recent objects they'd forgotten to tag.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's a great solution. of course it comes from git.
i'm really concerned about safety here--
@whyrusleeping @tv42 -- what's the plan long term?