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

ffs: enable auto-repair & update to new interopnet & ipfs pinset cache #272

Merged
merged 18 commits into from
Apr 24, 2020
Merged
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ build: build-cli build-server
.PHONY: build

test:
go test -short -p 1 -race ./...
go test -short -p 4 -race ./...
.PHONY: test
8 changes: 4 additions & 4 deletions deals/deals.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@ func (m *Module) Store(ctx context.Context, waddr string, data io.Reader, dcfgs
Data: &storagemarket.DataRef{
Root: dataCid,
},
BlocksDuration: dur,
EpochPrice: types.NewInt(c.EpochPrice),
Miner: maddr,
Wallet: addr,
MinBlocksDuration: dur,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

New interopnet API change.

EpochPrice: types.NewInt(c.EpochPrice),
Miner: maddr,
Wallet: addr,
}
p, err := m.api.ClientStartDeal(ctx, params)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion docker/docker-compose-embedded.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ services:
- 5001:5001

lotus:
image: textile/lotus-devnet:sha-9aab2c6
image: textile/lotus-devnet:sha-c755791
ports:
- 7777:7777
environment:
Expand Down
2 changes: 1 addition & 1 deletion docker/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ services:
- textile-fc-lotus:/root/lotus

lotus:
image: textile/lotus:custom
image: textile/lotus:a99875f
volumes:
- textile-fc-lotus:/data
ports:
Expand Down
4 changes: 2 additions & 2 deletions fchost/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (

var (
addrs = []string{
"/dns4/t01000.miner.interopnet.kittyhawk.wtf/tcp/1347/p2p/12D3KooWGzxzKZYveHXtpG6AsrUJBcWxHBFS2HsEoGTxrMLvKXtf",
"/ip4/52.36.61.156/tcp/1347/p2p/12D3KooWFETiESTf1v4PGUvtnxMAcEFMzLZbJGg4tjWfGEimYior",
"/dns4/t01000.miner.interopnet.kittyhawk.wtf/tcp/1347/p2p/12D3KooWNjqGTNZ592wG5DmX7Rbmb76V3NHMdZMqjqPJ1xiax7w6",
"/ip4/54.186.82.90/tcp/1347/p2p/12D3KooWGf4ggd3cdZJKZPHkgSe8Lxf4MDsKhVC7npRGXgsPP4fz",
Comment on lines +12 to +13
Copy link
Contributor Author

Choose a reason for hiding this comment

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

New bootstrap peers of interopnet.

}
)

Expand Down
41 changes: 33 additions & 8 deletions ffs/coreipfs/coreipfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Make a pinset cache. Basically is loaded on first use instead of in New. From that point forward, since PG is the only one touching the pinset of the IPFS node it's safe to assume that cache will be always valid and the API call to the IPFS node to get pinsets can be avoided.

Copy link
Member

Choose a reason for hiding this comment

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

Sweet.

Copy link
Member

Choose a reason for hiding this comment

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

It's an in-memory only thing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, just a guarded map of cid.Cid.

"fmt"
"io"
"sync"

blocks "github.com/ipfs/go-block-format"
"github.com/ipfs/go-cid"
Expand All @@ -25,6 +26,9 @@ var (
type CoreIpfs struct {
ipfs iface.CoreAPI
l ffs.CidLogger

lock sync.Mutex
pinset map[cid.Cid]struct{}
}

var _ ffs.HotStorage = (*CoreIpfs)(nil)
Expand Down Expand Up @@ -58,16 +62,13 @@ func (ci *CoreIpfs) Remove(ctx context.Context, c cid.Cid) error {

// IsStored return if a particular Cid is stored.
func (ci *CoreIpfs) IsStored(ctx context.Context, c cid.Cid) (bool, error) {
pins, err := ci.ipfs.Pin().Ls(ctx)
if err != nil {
return false, fmt.Errorf("getting pins from IPFS: %s", err)
}
for _, p := range pins {
if p.Path().Cid() == c {
return true, nil
if ci.pinset == nil {
if err := ci.ensurePinsetCache(ctx); err != nil {
return false, err
}
}
return false, nil
_, ok := ci.pinset[c]
return ok, nil
}

// Add adds an io.Reader data as file in the IPFS node.
Expand Down Expand Up @@ -106,6 +107,12 @@ func (ci *CoreIpfs) Store(ctx context.Context, c cid.Cid) (int, error) {
if err != nil {
return 0, fmt.Errorf("getting stats of cid %s: %s", c, err)
}
if err := ci.ensurePinsetCache(ctx); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

Could this just be done on startup?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, that's an option. But I tried to avoid adding load to bootstrapping and just load it on first use. But this can perfectly be moved to New.

Copy link
Member

Choose a reason for hiding this comment

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

Cool, makes sense. I guess the only downside of having it here is that there will one (the first after start) lucky user that gets a slow response time.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, that's a good point.
The other option is spinning a go routine on New... "nobody" pays a cost. :P

Copy link
Member

Choose a reason for hiding this comment

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

Oh yeah, sounds good 💯

return 0, err
}
ci.lock.Lock()
ci.pinset[c] = struct{}{}
ci.lock.Unlock()
return s.Size(), nil
}

Expand All @@ -123,3 +130,21 @@ func (ci *CoreIpfs) Replace(ctx context.Context, c1 cid.Cid, c2 cid.Cid) (int, e
}
return stat.Size(), nil
}

func (ci *CoreIpfs) ensurePinsetCache(ctx context.Context) error {
ci.lock.Lock()
defer ci.lock.Unlock()
if ci.pinset != nil {
return nil
}
pins, err := ci.ipfs.Pin().Ls(ctx)
if err != nil {
ci.lock.Unlock()
return fmt.Errorf("getting pins from IPFS: %s", err)
}
ci.pinset = make(map[cid.Cid]struct{}, len(pins))
for _, p := range pins {
ci.pinset[p.Path().Cid()] = struct{}{}
}
return nil
}
Loading