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

support threshold based automatic sharding and unsharding of directories #88

Merged
merged 6 commits into from
Nov 16, 2021
Merged
Show file tree
Hide file tree
Changes from 5 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
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
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ 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-cid v0.0.7
github.com/ipfs/go-datastore v0.0.5
github.com/ipfs/go-ipfs-blockstore v0.0.1
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-log v1.0.5
github.com/ipfs/go-merkledag v0.2.3
github.com/ipfs/go-path v0.0.7
github.com/ipfs/go-unixfs v0.1.0
github.com/ipfs/go-unixfs v0.2.7-0.20211112011223-bd53b6a811b1
aschmahmann marked this conversation as resolved.
Show resolved Hide resolved
github.com/libp2p/go-libp2p-testing v0.0.4
)

Expand Down
Loading