Skip to content
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

RFC: make GC codec agnostic #5347

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions pin/gc/gc.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"strings"

pin "github.com/ipfs/go-ipfs/pin"
dag "gx/ipfs/Qma2BR57Wqp8w9vPreK4dEzoXXk8DFFRL3LresMZg4QpzN/go-merkledag"
bserv "gx/ipfs/QmfZ5oGGgsx71QcHb6junfFCMGhYWkK8VV61nkCFyt8e5Q/go-blockservice"
bserv "gx/ipfs/QmNqRBAhovtf4jVd5cF7YvHaFSsQHHZBaUFwGQWPM2CV7R/go-blockservice"
dag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"

"gx/ipfs/QmQwgv79RHrRnoXmhnpC1BPtY55HHeneGMpPwmmBU1fUAG/go-verifcid"
offline "gx/ipfs/QmS6mo1dPpHdYsVkm27BRZDLxpKBCiJKUH8fHX15XFfMez/go-ipfs-exchange-offline"
Expand Down Expand Up @@ -76,14 +76,16 @@ func GC(ctx context.Context, bs bstore.GCBlockstore, dstor dstore.Datastore, pn
errors := false
var removed uint64

gchashes := MultihashSetFromCids(gcs)
Copy link
Member Author

Choose a reason for hiding this comment

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

Note: we can't just use a multihash set when generating the colored set as we might visit a node with a raw CID first and then not visit its children when we visit it using a non-raw CID. Basically, traversal cares about CIDs.


loop:
for {
select {
case k, ok := <-keychan:
if !ok {
break loop
}
if !gcs.Has(k) {
if !gchashes.Has(k.Hash()) {
err := bs.DeleteBlock(k)
removed++
if err != nil {
Expand Down
29 changes: 29 additions & 0 deletions pin/gc/mhset.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package gc

import (
mh "gx/ipfs/QmPnFwZ2JXKnXgMw8CdBPxn7FWh6LLdjUjxV1fKHuJnkr8/go-multihash"
cid "gx/ipfs/QmYVNvtQkeZ6AKSwDrjQTs432QtL6umrrK41EBq3cu7iSP/go-cid"
)

type MultihashSet map[string]struct{}

func (m MultihashSet) Add(h mh.Multihash) {
m[string(h)] = struct{}{}
}

func (m MultihashSet) Has(h mh.Multihash) bool {
_, ok := m[string(h)]
return ok
}

func MultihashSetFromCids(cids *cid.Set) MultihashSet {
mhSet := make(MultihashSet, cids.Len())

if err := cids.ForEach(func(c *cid.Cid) error {
mhSet.Add(c.Hash())
return nil
}); err != nil {
log.Panic(err)
}
return mhSet
}