Skip to content

Commit ac69697

Browse files
Merge pull request #3042 from ipfs/feat/hamt-sharding
Implement unixfs sharding
2 parents 1d59331 + 65b9716 commit ac69697

26 files changed

+2200
-173
lines changed

assets/assets.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,27 @@ func addAssetList(nd *core.IpfsNode, l []string) (*cid.Cid, error) {
5959
}
6060

6161
fname := filepath.Base(p)
62+
6263
c, err := cid.Decode(s)
6364
if err != nil {
6465
return nil, err
6566
}
6667

67-
if err := dirb.AddChild(nd.Context(), fname, c); err != nil {
68+
node, err := nd.DAG.Get(nd.Context(), c)
69+
if err != nil {
70+
return nil, err
71+
}
72+
73+
if err := dirb.AddChild(nd.Context(), fname, node); err != nil {
6874
return nil, fmt.Errorf("assets: could not add '%s' as a child: %s", fname, err)
6975
}
7076
}
7177

72-
dir := dirb.GetNode()
78+
dir, err := dirb.GetNode()
79+
if err != nil {
80+
return nil, err
81+
}
82+
7383
dcid, err := nd.DAG.Add(dir)
7484
if err != nil {
7585
return nil, fmt.Errorf("assets: DAG.Add(dir) failed: %s", err)

commands/request.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package commands
22

33
import (
44
"bufio"
5+
"context"
56
"errors"
67
"fmt"
78
"io"
@@ -10,7 +11,6 @@ import (
1011
"strconv"
1112
"time"
1213

13-
context "context"
1414
"github.com/ipfs/go-ipfs/commands/files"
1515
"github.com/ipfs/go-ipfs/core"
1616
"github.com/ipfs/go-ipfs/repo/config"

core/builder.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
pin "github.com/ipfs/go-ipfs/pin"
1919
repo "github.com/ipfs/go-ipfs/repo"
2020
cfg "github.com/ipfs/go-ipfs/repo/config"
21+
uio "github.com/ipfs/go-ipfs/unixfs/io"
2122

2223
ci "gx/ipfs/QmPGxZ1DP2w45WcogpW1h43BvseXbfke9N91qotpoQcUeS/go-libp2p-crypto"
2324
ds "gx/ipfs/QmRWDav6mzWseLWeYfVd5fvUKiVe9xNH29YfMF438fG364/go-datastore"
@@ -175,6 +176,9 @@ func setupNode(ctx context.Context, n *IpfsNode, cfg *BuildCfg) error {
175176
return err
176177
}
177178

179+
// TEMP: setting global sharding switch here
180+
uio.UseHAMTSharding = conf.Experimental.ShardingEnabled
181+
178182
opts.HasBloomFilterSize = conf.Datastore.BloomFilterSize
179183
if !cfg.Permament {
180184
opts.HasBloomFilterSize = 0

core/commands/files/files.go

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -265,16 +265,7 @@ func getNodeFromPath(ctx context.Context, node *core.IpfsNode, p string) (node.N
265265
ResolveOnce: uio.ResolveUnixfsOnce,
266266
}
267267

268-
nd, err := core.Resolve(ctx, node.Namesys, resolver, np)
269-
if err != nil {
270-
return nil, err
271-
}
272-
pbnd, ok := nd.(*dag.ProtoNode)
273-
if !ok {
274-
return nil, dag.ErrNotProtobuf
275-
}
276-
277-
return pbnd, nil
268+
return core.Resolve(ctx, node.Namesys, resolver, np)
278269
default:
279270
fsn, err := mfs.Lookup(node.FilesRoot, p)
280271
if err != nil {
@@ -357,14 +348,20 @@ Examples:
357348
case *mfs.Directory:
358349
if !long {
359350
var output []mfs.NodeListing
360-
for _, name := range fsn.ListNames() {
351+
names, err := fsn.ListNames(req.Context())
352+
if err != nil {
353+
res.SetError(err, cmds.ErrNormal)
354+
return
355+
}
356+
357+
for _, name := range names {
361358
output = append(output, mfs.NodeListing{
362359
Name: name,
363360
})
364361
}
365362
res.SetOutput(&FilesLsOutput{output})
366363
} else {
367-
listing, err := fsn.List()
364+
listing, err := fsn.List(req.Context())
368365
if err != nil {
369366
res.SetError(err, cmds.ErrNormal)
370367
return

core/commands/ls.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,24 @@ The JSON output contains type information.
105105

106106
output := make([]LsObject, len(req.Arguments()))
107107
for i, dagnode := range dagnodes {
108+
dir, err := uio.NewDirectoryFromNode(nd.DAG, dagnode)
109+
if err != nil {
110+
res.SetError(err, cmds.ErrNormal)
111+
return
112+
}
113+
114+
links, err := dir.Links(req.Context())
115+
if err != nil {
116+
res.SetError(err, cmds.ErrNormal)
117+
return
118+
}
119+
108120
output[i] = LsObject{
109121
Hash: paths[i],
110-
Links: make([]LsLink, len(dagnode.Links())),
122+
Links: make([]LsLink, len(links)),
111123
}
112-
for j, link := range dagnode.Links() {
124+
125+
for j, link := range links {
113126
t := unixfspb.Data_DataType(-1)
114127

115128
linkNode, err := link.GetNode(req.Context(), dserv)

core/coreunix/add.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
dag "github.com/ipfs/go-ipfs/merkledag"
2222
mfs "github.com/ipfs/go-ipfs/mfs"
2323
"github.com/ipfs/go-ipfs/pin"
24+
posinfo "github.com/ipfs/go-ipfs/thirdparty/posinfo"
2425
unixfs "github.com/ipfs/go-ipfs/unixfs"
2526

2627
ds "gx/ipfs/QmRWDav6mzWseLWeYfVd5fvUKiVe9xNH29YfMF438fG364/go-datastore"
@@ -189,15 +190,18 @@ func (adder *Adder) PinRoot() error {
189190
func (adder *Adder) Finalize() (node.Node, error) {
190191
root := adder.mr.GetValue()
191192

192-
// cant just call adder.RootNode() here as we need the name for printing
193-
rootNode, err := root.GetNode()
193+
err := root.Flush()
194194
if err != nil {
195195
return nil, err
196196
}
197197

198198
var name string
199199
if !adder.Wrap {
200-
name = rootNode.Links()[0].Name
200+
children, err := root.(*mfs.Directory).ListNames(adder.ctx)
201+
if err != nil {
202+
return nil, err
203+
}
204+
name = children[0]
201205

202206
dir, ok := adder.mr.GetValue().(*mfs.Directory)
203207
if !ok {
@@ -228,7 +232,12 @@ func (adder *Adder) outputDirs(path string, fsn mfs.FSNode) error {
228232
case *mfs.File:
229233
return nil
230234
case *mfs.Directory:
231-
for _, name := range fsn.ListNames() {
235+
names, err := fsn.ListNames(adder.ctx)
236+
if err != nil {
237+
return err
238+
}
239+
240+
for _, name := range names {
232241
child, err := fsn.Child(name)
233242
if err != nil {
234243
return err
@@ -344,6 +353,10 @@ func (adder *Adder) addNode(node node.Node, path string) error {
344353
path = node.Cid().String()
345354
}
346355

356+
if pi, ok := node.(*posinfo.FilestoreNode); ok {
357+
node = pi.Node
358+
}
359+
347360
dir := gopath.Dir(path)
348361
if dir != "." {
349362
if err := mfs.Mkdir(adder.mr, dir, true, false); err != nil {

fuse/ipns/ipns_unix.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import (
1616
namesys "github.com/ipfs/go-ipfs/namesys"
1717
path "github.com/ipfs/go-ipfs/path"
1818
ft "github.com/ipfs/go-ipfs/unixfs"
19-
uio "github.com/ipfs/go-ipfs/unixfs/io"
2019

2120
ci "gx/ipfs/QmPGxZ1DP2w45WcogpW1h43BvseXbfke9N91qotpoQcUeS/go-libp2p-crypto"
2221
logging "gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log"
@@ -100,7 +99,7 @@ func loadRoot(ctx context.Context, rt *keyRoot, ipfs *core.IpfsNode, name string
10099
switch err {
101100
case nil:
102101
case namesys.ErrResolveFailed:
103-
node = uio.NewEmptyDirectory()
102+
node = ft.EmptyDirNode()
104103
default:
105104
log.Errorf("looking up %s: %s", p, err)
106105
return nil, err
@@ -325,7 +324,7 @@ func (s *Directory) Lookup(ctx context.Context, name string) (fs.Node, error) {
325324
// ReadDirAll reads the link structure as directory entries
326325
func (dir *Directory) ReadDirAll(ctx context.Context) ([]fuse.Dirent, error) {
327326
var entries []fuse.Dirent
328-
listing, err := dir.dir.List()
327+
listing, err := dir.dir.List(ctx)
329328
if err != nil {
330329
return nil, err
331330
}

0 commit comments

Comments
 (0)