Skip to content
This repository has been archived by the owner on Jun 26, 2023. It is now read-only.

Commit

Permalink
support threshold based automatic sharding and unsharding of director…
Browse files Browse the repository at this point in the history
…ies (#88)

* feat: update go-unixfs and use built in automatic sharding and unsharding
* chore: update deps

Co-authored-by: Adin Schmahmann <adin.schmahmann@gmail.com>
Co-authored-by: Gus Eggert <gus@gus.dev>
  • Loading branch information
3 people authored Nov 16, 2021
1 parent bc02883 commit e61420f
Show file tree
Hide file tree
Showing 3 changed files with 973 additions and 162 deletions.
29 changes: 3 additions & 26 deletions dir.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func (d *Directory) localUpdate(c child) (*dag.ProtoNode, error) {

// Update child entry in the underlying UnixFS directory.
func (d *Directory) updateChild(c child) error {
err := d.addUnixFSChild(c)
err := d.unixfsDir.AddChild(d.ctx, c.Name, c.Node)
if err != nil {
return err
}
Expand Down Expand Up @@ -313,7 +313,7 @@ func (d *Directory) Mkdir(name string) (*Directory, error) {
return nil, err
}

err = d.addUnixFSChild(child{name, ndir})
err = d.unixfsDir.AddChild(d.ctx, name, ndir)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -360,7 +360,7 @@ func (d *Directory) AddChild(name string, nd ipld.Node) error {
return err
}

err = d.addUnixFSChild(child{name, nd})
err = d.unixfsDir.AddChild(d.ctx, name, nd)
if err != nil {
return err
}
Expand All @@ -369,29 +369,6 @@ func (d *Directory) AddChild(name string, nd ipld.Node) error {
return nil
}

// addUnixFSChild adds a child to the inner UnixFS directory
// and transitions to a HAMT implementation if needed.
func (d *Directory) addUnixFSChild(c child) error {
if uio.UseHAMTSharding {
// If the directory HAMT implementation is being used and this
// directory is actually a basic implementation switch it to HAMT.
if basicDir, ok := d.unixfsDir.(*uio.BasicDirectory); ok {
hamtDir, err := basicDir.SwitchToSharding(d.ctx)
if err != nil {
return err
}
d.unixfsDir = hamtDir
}
}

err := d.unixfsDir.AddChild(d.ctx, c.Name, c.Node)
if err != nil {
return err
}

return nil
}

func (d *Directory) sync() error {
for name, entry := range d.entriesCache {
nd, err := entry.GetNode()
Expand Down
24 changes: 12 additions & 12 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
module github.com/ipfs/go-mfs

require (
github.com/ipfs/go-blockservice v0.1.1
github.com/ipfs/go-cid v0.0.2
github.com/ipfs/go-datastore v0.0.5
github.com/ipfs/go-ipfs-blockstore v0.0.1
github.com/ipfs/go-blockservice v0.2.0
github.com/ipfs/go-cid v0.1.0
github.com/ipfs/go-datastore v0.5.0
github.com/ipfs/go-ipfs-blockstore v0.2.0
github.com/ipfs/go-ipfs-chunker v0.0.1
github.com/ipfs/go-ipfs-exchange-offline v0.0.1
github.com/ipfs/go-ipfs-util v0.0.1
github.com/ipfs/go-ipld-format v0.0.2
github.com/ipfs/go-log v0.0.1
github.com/ipfs/go-merkledag v0.1.0
github.com/ipfs/go-path v0.0.7
github.com/ipfs/go-unixfs v0.1.0
github.com/libp2p/go-libp2p-testing v0.0.4
github.com/ipfs/go-ipfs-exchange-offline v0.1.0
github.com/ipfs/go-ipfs-util v0.0.2
github.com/ipfs/go-ipld-format v0.2.0
github.com/ipfs/go-log v1.0.5
github.com/ipfs/go-merkledag v0.5.0
github.com/ipfs/go-path v0.2.0
github.com/ipfs/go-unixfs v0.3.0
github.com/libp2p/go-libp2p-testing v0.4.0
)

go 1.16
Loading

0 comments on commit e61420f

Please sign in to comment.