Commit 6f9115bb authored by Steven Allen's avatar Steven Allen

Make remove idempotent.

1. Add is already idempotent. This makes remove match.
2. Generally, all we care about is that the node no longer exists in the DAG. If
two callers remove a node at the same time, they should both succeed. Currently,
we *ignore* the result of Remove in go-ipfs. IMO, it would be better to let
errors be *errors* and only return an error if something goes wrong.
3. This can be significantly faster. It allows us to batch/queue removes (as
long as we guarantee that they'll eventually happen).
4. This matches how most databases/key-value stores operate.

An alternative would be to return `(deleted bool, err error)` but then we don't
get the speedup.
parent 0408f8d6
......@@ -64,11 +64,7 @@ func (d *testDag) AddMany(nodes []Node) ([]*cid.Cid, error) {
func (d *testDag) Remove(c *cid.Cid) error {
d.mu.Lock()
defer d.mu.Unlock()
key := c.KeyString()
if _, exists := d.nodes[key]; !exists {
return ErrNotFound
}
delete(d.nodes, key)
delete(d.nodes, c.KeyString())
return nil
}
......
......@@ -47,7 +47,7 @@ type DAGService interface {
// Remove removes a node from this DAG.
//
// If the node is not in this DAG, Remove returns ErrNotFound.
// Remove returns no error if the requested node is not present in this DAG.
Remove(*cid.Cid) error
// AddMany adds many nodes to this DAG.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment