-
-
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
implement mark and sweep garbage collection #1420
Changes from 2 commits
268239d
2d82a20
aa1be6b
c2fc8bc
b521f54
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ import ( | |
context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context" | ||
key "github.com/ipfs/go-ipfs/blocks/key" | ||
"github.com/ipfs/go-ipfs/core" | ||
gc "github.com/ipfs/go-ipfs/pin/gc" | ||
|
||
eventlog "github.com/ipfs/go-ipfs/thirdparty/eventlog" | ||
) | ||
|
@@ -15,54 +16,40 @@ type KeyRemoved struct { | |
} | ||
|
||
func GarbageCollect(n *core.IpfsNode, ctx context.Context) error { | ||
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. we should flip the params here: 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. we've always had the 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. ah. even when there is a ctx involved? i guess that makes sense |
||
ctx, cancel := context.WithCancel(context.Background()) | ||
defer cancel() // in case error occurs during operation | ||
keychan, err := n.Blockstore.AllKeysChan(ctx) | ||
rmed, err := gc.GC(ctx, n.Blockstore, n.Pinning) | ||
if err != nil { | ||
return err | ||
} | ||
for k := range keychan { // rely on AllKeysChan to close chan | ||
if !n.Pinning.IsPinned(k) { | ||
err := n.Blockstore.DeleteBlock(k) | ||
if err != nil { | ||
return err | ||
|
||
for { | ||
select { | ||
case _, ok := <-rmed: | ||
if !ok { | ||
return nil | ||
} | ||
case <-ctx.Done(): | ||
return ctx.Err() | ||
} | ||
} | ||
return nil | ||
|
||
} | ||
|
||
func GarbageCollectAsync(n *core.IpfsNode, ctx context.Context) (<-chan *KeyRemoved, error) { | ||
|
||
keychan, err := n.Blockstore.AllKeysChan(ctx) | ||
rmed, err := gc.GC(ctx, n.Blockstore, n.Pinning) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
output := make(chan *KeyRemoved) | ||
out := make(chan *KeyRemoved) | ||
go func() { | ||
defer close(output) | ||
for { | ||
defer close(out) | ||
for k := range rmed { | ||
select { | ||
case k, ok := <-keychan: | ||
if !ok { | ||
return | ||
} | ||
if !n.Pinning.IsPinned(k) { | ||
err := n.Blockstore.DeleteBlock(k) | ||
if err != nil { | ||
log.Debugf("Error removing key from blockstore: %s", err) | ||
continue | ||
} | ||
select { | ||
case output <- &KeyRemoved{k}: | ||
case <-ctx.Done(): | ||
} | ||
} | ||
case out <- &KeyRemoved{k}: | ||
case <-ctx.Done(): | ||
return | ||
} | ||
} | ||
}() | ||
return output, nil | ||
return out, nil | ||
} |
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.
i believe this needs to be brought back. (with likely a mark and sweep implementation)
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.
no, its okay that this is gone. you can still specify that you want to see indirect keys, but we arent going to bother with counting them anymore. Thats too much hassle and gains us nothing.