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

Eliminate GetOfflineLinkService method from LinkService interface #4152

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
24 changes: 12 additions & 12 deletions core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
rp "github.com/ipfs/go-ipfs/exchange/reprovide"
filestore "github.com/ipfs/go-ipfs/filestore"
mount "github.com/ipfs/go-ipfs/fuse/mount"
merkledag "github.com/ipfs/go-ipfs/merkledag"
mdag "github.com/ipfs/go-ipfs/merkledag"
mfs "github.com/ipfs/go-ipfs/mfs"
namesys "github.com/ipfs/go-ipfs/namesys"
ipnsrp "github.com/ipfs/go-ipfs/namesys/republisher"
Expand Down Expand Up @@ -110,14 +110,14 @@ type IpfsNode struct {
PNetFingerpint []byte // fingerprint of private network

// Services
Peerstore pstore.Peerstore // storage for other Peer instances
Blockstore bstore.GCBlockstore // the block store (lower level)
Filestore *filestore.Filestore // the filestore blockstore
BaseBlocks bstore.Blockstore // the raw blockstore, no filestore wrapping
GCLocker bstore.GCLocker // the locker used to protect the blockstore during gc
Blocks bserv.BlockService // the block service, get/add blocks.
DAG merkledag.DAGService // the merkle dag service, get/add objects.
Resolver *path.Resolver // the path resolution system
Peerstore pstore.Peerstore // storage for other Peer instances
Blockstore bstore.GCBlockstore // the block store (lower level)
Filestore *filestore.Filestore // the filestore blockstore
BaseBlocks bstore.Blockstore // the raw blockstore, no filestore wrapping
GCLocker bstore.GCLocker // the locker used to protect the blockstore during gc
Blocks bserv.BlockService // the block service, get/add blocks.
DAG *mdag.MerkleDAGService // the merkle dag service, get/add objects.
Resolver *path.Resolver // the path resolution system
Reporter metrics.Reporter
Discovery discovery.Service
FilesRoot *mfs.Root
Expand Down Expand Up @@ -690,7 +690,7 @@ func (n *IpfsNode) loadFilesRoot() error {
return n.Repo.Datastore().Put(dsk, c.Bytes())
}

var nd *merkledag.ProtoNode
var nd *mdag.ProtoNode
val, err := n.Repo.Datastore().Get(dsk)

switch {
Expand All @@ -711,9 +711,9 @@ func (n *IpfsNode) loadFilesRoot() error {
return fmt.Errorf("error loading filesroot from DAG: %s", err)
}

pbnd, ok := rnd.(*merkledag.ProtoNode)
pbnd, ok := rnd.(*mdag.ProtoNode)
if !ok {
return merkledag.ErrNotProtobuf
return mdag.ErrNotProtobuf
}

nd = pbnd
Expand Down
5 changes: 3 additions & 2 deletions core/corerepo/gc.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ func GarbageCollect(n *core.IpfsNode, ctx context.Context) error {
if err != nil {
return err
}
rmed := gc.GC(ctx, n.Blockstore, n.DAG, n.Pinning, roots)

rmed := gc.GC(ctx, n.Blockstore, n.DAG.GetOfflineLinkService(), n.Pinning, roots)

return CollectResult(ctx, rmed, nil)
}
Expand Down Expand Up @@ -154,7 +155,7 @@ func GarbageCollectAsync(n *core.IpfsNode, ctx context.Context) <-chan gc.Result
return out
}

return gc.GC(ctx, n.Blockstore, n.DAG, n.Pinning, roots)
return gc.GC(ctx, n.Blockstore, n.DAG.GetOfflineLinkService(), n.Pinning, roots)
}

func PeriodicGC(ctx context.Context, node *core.IpfsNode) error {
Expand Down
2 changes: 1 addition & 1 deletion core/coreunix/add_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func TestAddGCLive(t *testing.T) {
gcstarted := make(chan struct{})
go func() {
defer close(gcstarted)
gcout = gc.GC(context.Background(), node.Blockstore, node.DAG, node.Pinning, nil)
gcout = gc.GC(context.Background(), node.Blockstore, node.DAG.GetOfflineLinkService(), node.Pinning, nil)
}()

// gc shouldnt start until we let the add finish its current file.
Expand Down
2 changes: 1 addition & 1 deletion core/coreunix/metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
dssync "gx/ipfs/QmVSase1JP7cq9QkPT46oNwdp9pT6kBkG3oqS14y3QcZjG/go-datastore/sync"
)

func getDagserv(t *testing.T) merkledag.DAGService {
func getDagserv(t *testing.T) *merkledag.MerkleDAGService {
db := dssync.MutexWrap(ds.NewMapDatastore())
bs := bstore.NewBlockstore(db)
blockserv := bserv.New(bs, offline.Exchange(bs))
Expand Down
46 changes: 25 additions & 21 deletions merkledag/merkledag.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,33 +47,31 @@ type LinkService interface {
// leaves cannot possibly have links so there is no need to look
// at the node.
GetLinks(context.Context, *cid.Cid) ([]*node.Link, error)

GetOfflineLinkService() LinkService
}

func NewDAGService(bs bserv.BlockService) *dagService {
return &dagService{Blocks: bs}
func NewDAGService(bs bserv.BlockService) *MerkleDAGService {
return &MerkleDAGService{Blocks: bs}
}

// dagService is an IPFS Merkle DAG service.
// MerkleDAGService is an IPFS Merkle DAG service.
// - the root is virtual (like a forest)
// - stores nodes' data in a BlockService
// TODO: should cache Nodes that are in memory, and be
// able to free some of them when vm pressure is high
type dagService struct {
type MerkleDAGService struct {
Blocks bserv.BlockService
}

// Add adds a node to the dagService, storing the block in the BlockService
func (n *dagService) Add(nd node.Node) (*cid.Cid, error) {
// Add adds a node to the MerkleDAGService, storing the block in the BlockService
func (n *MerkleDAGService) Add(nd node.Node) (*cid.Cid, error) {
if n == nil { // FIXME remove this assertion. protect with constructor invariant
return nil, fmt.Errorf("dagService is nil")
return nil, fmt.Errorf("MerkleDAGService is nil")
}

return n.Blocks.AddBlock(nd)
}

func (n *dagService) Batch() *Batch {
func (n *MerkleDAGService) Batch() *Batch {
return &Batch{
ds: n,
MaxSize: 8 << 20,
Expand All @@ -85,10 +83,10 @@ func (n *dagService) Batch() *Batch {
}
}

// Get retrieves a node from the dagService, fetching the block in the BlockService
func (n *dagService) Get(ctx context.Context, c *cid.Cid) (node.Node, error) {
// Get retrieves a node from the MerkleDAGService, fetching the block in the BlockService
func (n *MerkleDAGService) Get(ctx context.Context, c *cid.Cid) (node.Node, error) {
if n == nil {
return nil, fmt.Errorf("dagService is nil")
return nil, fmt.Errorf("MerkleDAGService is nil")
}

ctx, cancel := context.WithCancel(ctx)
Expand All @@ -107,7 +105,7 @@ func (n *dagService) Get(ctx context.Context, c *cid.Cid) (node.Node, error) {

// GetLinks return the links for the node, the node doesn't necessarily have
// to exist locally.
func (n *dagService) GetLinks(ctx context.Context, c *cid.Cid) ([]*node.Link, error) {
func (n *MerkleDAGService) GetLinks(ctx context.Context, c *cid.Cid) ([]*node.Link, error) {
if c.Type() == cid.Raw {
return nil, nil
}
Expand All @@ -118,16 +116,22 @@ func (n *dagService) GetLinks(ctx context.Context, c *cid.Cid) ([]*node.Link, er
return node.Links(), nil
}

func (n *dagService) GetOfflineLinkService() LinkService {
// OfflineLinkService is just a wrapper around LinkService that is
// assumed to be offline.
type OfflineLinkService struct {
LinkService
}

func (n *MerkleDAGService) GetOfflineLinkService() OfflineLinkService {
if n.Blocks.Exchange().IsOnline() {
bsrv := bserv.New(n.Blocks.Blockstore(), offline.Exchange(n.Blocks.Blockstore()))
return NewDAGService(bsrv)
return OfflineLinkService{NewDAGService(bsrv)}
} else {
return n
return OfflineLinkService{n}
}
}

func (n *dagService) Remove(nd node.Node) error {
func (n *MerkleDAGService) Remove(nd node.Node) error {
return n.Blocks.DeleteBlock(nd)
}

Expand Down Expand Up @@ -163,7 +167,7 @@ func (sg *sesGetter) Get(ctx context.Context, c *cid.Cid) (node.Node, error) {
// FetchGraph fetches all nodes that are children of the given node
func FetchGraph(ctx context.Context, root *cid.Cid, serv DAGService) error {
var ng node.NodeGetter = serv
ds, ok := serv.(*dagService)
ds, ok := serv.(*MerkleDAGService)
if ok {
ng = &sesGetter{bserv.NewSession(ctx, ds.Blocks)}
}
Expand Down Expand Up @@ -201,7 +205,7 @@ type NodeOption struct {
Err error
}

func (ds *dagService) GetMany(ctx context.Context, keys []*cid.Cid) <-chan *NodeOption {
func (ds *MerkleDAGService) GetMany(ctx context.Context, keys []*cid.Cid) <-chan *NodeOption {
out := make(chan *NodeOption, len(keys))
blocks := ds.Blocks.GetBlocks(ctx, keys)
var count int
Expand Down Expand Up @@ -385,7 +389,7 @@ func (np *nodePromise) Get(ctx context.Context) (node.Node, error) {
}

type Batch struct {
ds *dagService
ds *MerkleDAGService

blocks []blocks.Block
size int
Expand Down
4 changes: 1 addition & 3 deletions pin/gc/gc.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,14 @@ type Result struct {
// The routine then iterates over every block in the blockstore and
// deletes any block that is not found in the marked set.
//
func GC(ctx context.Context, bs bstore.GCBlockstore, ls dag.LinkService, pn pin.Pinner, bestEffortRoots []*cid.Cid) <-chan Result {
func GC(ctx context.Context, bs bstore.GCBlockstore, ls dag.OfflineLinkService, pn pin.Pinner, bestEffortRoots []*cid.Cid) <-chan Result {

elock := log.EventBegin(ctx, "GC.lockWait")
unlocker := bs.GCLock()
elock.Done()
elock = log.EventBegin(ctx, "GC.locked")
emark := log.EventBegin(ctx, "GC.mark")

ls = ls.GetOfflineLinkService()

output := make(chan Result, 128)

go func() {
Expand Down