Skip to content

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 <[email protected]>
Co-authored-by: Gus Eggert <[email protected]>

This commit was moved from ipfs/go-mfs@e61420f
  • Loading branch information
schomatis authored Nov 16, 2021
1 parent e736d65 commit 91853fb
Showing 1 changed file with 3 additions and 26 deletions.
29 changes: 3 additions & 26 deletions mfs/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

0 comments on commit 91853fb

Please sign in to comment.