-
Notifications
You must be signed in to change notification settings - Fork 26
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
Make Batch implement a NodeAdder interface #46
Conversation
See: * ipfs/go-unixfs#41 * ipfs/go-ipld-format#46 License: MIT Signed-off-by: Hector Sanjuan <[email protected]>
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.
If we're implementing a DAGService, we need to behave like one. I can think of three ways to fix this:
- Always flush before we perform a get/delete.
- Remove queued blocks (complicated).
- Split out a new NodeWriter interface.
- Split out
batch.go
Outdated
@@ -124,6 +126,39 @@ func (t *Batch) Add(nd Node) error { | |||
return t.err | |||
} | |||
|
|||
// Remove removes a node from the DAGService. This is a non-batching | |||
// operation. | |||
func (t *Batch) Remove(ctx context.Context, c cid.Cid) error { |
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 needs to remove the node from the queue (or flush the queue) and then remove the node.
batch.go
Outdated
|
||
// RemoveMany calls RemoveMany in the underlying DAGService. | ||
func (t *Batch) RemoveMany(ctx context.Context, nodes []cid.Cid) error { | ||
return t.ds.RemoveMany(ctx, nodes) |
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.
Same, needs to remove from the queue.
batch.go
Outdated
|
||
// Get calls Get from the underlying DAGService. | ||
func (t *Batch) Get(ctx context.Context, c cid.Cid) (Node, error) { | ||
return t.ds.Get(ctx, c) |
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.
Same. Needs to get from the queue.
batch.go
Outdated
|
||
// GetMany calls GetMany from the underlying DAGService. | ||
func (t *Batch) GetMany(ctx context.Context, nodes []cid.Cid) <-chan *NodeOption { | ||
return t.ds.GetMany(ctx, nodes) |
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.
ditto
Personally, I think separating out a |
@Stebalien you mean |
type NodeWriter interface {
Add(context.Context, Node) error
AddMany(context.Context, []Node) error
} (we'd also need We don't have to do it this way, I just don't want (as names, |
So it's one more interface to the mix ( Before, doing Get on the DAGService while adding stuff with the batch-importers would cause the same problems (Get on a recently added node could fail it was still uncommitted). I'm leaning towards just doing |
No, having a broken DAGService implementation that sometimes works and sometimes doesn't. It doesn't matter if we're not using it, the issue is that it looks like it should work but won't.
Yes, but that makes perfect sense. The "batch" is effectively a transaction. However, if we're going to claim that
We can, of course, do that. However, I really don't see the issue adding a new interface. It gives us a clean divide so applications can pick what they want to use:
|
I meant with the
Ok i'll do that then |
Ah, got it. Really, either way is fine with me as long as whatever we do is correct. However, this is really like the |
batch.go
Outdated
// commiting them as needed. | ||
func (t *Batch) AddMany(ctx context.Context, nodes []Node) error { | ||
for _, n := range nodes { | ||
err := t.Add(ctx, n) |
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.
Could potentially append all nodes directly but that might get us way over maxSize/maxNodes.
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 shouldn't really be an issue. Going over max nodes/size should just trigger a flush (we don't want to buffer too much in memory).
Maybe we should just:
- Make
Add
call AddMany`. - Move the main logic to
AddMany
(and process all nodes at once).
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.
LGTM. We can mess with performance later. We should probably also be obeying the context but that'll be a bit tricky.
Have a look to latest commit (cfe76e8) @Stebalien I still need to update the gx tag before merging. |
@hsanjuan LGTM. |
This adds a NodeAdder interface (which partially implements a DAGService), and adjusts the Batch type to satisfy it.
Needed for: ipfs/go-unixfs#41