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

Commit

Permalink
fix go vet issues in hamt sharding PR
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Jeromy <jeromyj@gmail.com>
  • Loading branch information
whyrusleeping committed Mar 24, 2017
1 parent bd3637a commit 5e8347c
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 23 deletions.
14 changes: 7 additions & 7 deletions hamt/hamt.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,17 +351,17 @@ func (ds *HamtShard) getValue(ctx context.Context, hv *hashBits, key string, cb
return os.ErrNotExist
}

func (ds *HamtShard) EnumLinks() ([]*node.Link, error) {
func (ds *HamtShard) EnumLinks(ctx context.Context) ([]*node.Link, error) {
var links []*node.Link
err := ds.ForEachLink(func(l *node.Link) error {
err := ds.ForEachLink(ctx, func(l *node.Link) error {
links = append(links, l)
return nil
})
return links, err
}

func (ds *HamtShard) ForEachLink(f func(*node.Link) error) error {
return ds.walkTrie(func(sv *shardValue) error {
func (ds *HamtShard) ForEachLink(ctx context.Context, f func(*node.Link) error) error {
return ds.walkTrie(ctx, func(sv *shardValue) error {
lnk, err := node.MakeLink(sv.val)
if err != nil {
return err
Expand All @@ -373,7 +373,7 @@ func (ds *HamtShard) ForEachLink(f func(*node.Link) error) error {
})
}

func (ds *HamtShard) walkTrie(cb func(*shardValue) error) error {
func (ds *HamtShard) walkTrie(ctx context.Context, cb func(*shardValue) error) error {
for i := 0; i < ds.tableSize; i++ {
if ds.bitfield.Bit(i) == 0 {
continue
Expand All @@ -382,7 +382,7 @@ func (ds *HamtShard) walkTrie(cb func(*shardValue) error) error {
idx := ds.indexForBitPos(i)
// NOTE: an optimized version could simply iterate over each
// element in the 'children' array.
c, err := ds.getChild(context.TODO(), idx)
c, err := ds.getChild(ctx, idx)
if err != nil {
return err
}
Expand All @@ -395,7 +395,7 @@ func (ds *HamtShard) walkTrie(cb func(*shardValue) error) error {
}

case *HamtShard:
err := c.walkTrie(cb)
err := c.walkTrie(ctx, cb)
if err != nil {
return err
}
Expand Down
17 changes: 10 additions & 7 deletions hamt/hamt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ func assertLink(s *HamtShard, name string, found bool) error {
}

func assertSerializationWorks(ds dag.DAGService, s *HamtShard) error {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
nd, err := s.Node()
if err != nil {
return err
Expand All @@ -82,12 +84,12 @@ func assertSerializationWorks(ds dag.DAGService, s *HamtShard) error {
return err
}

linksA, err := s.EnumLinks()
linksA, err := s.EnumLinks(ctx)
if err != nil {
return err
}

linksB, err := nds.EnumLinks()
linksB, err := nds.EnumLinks(ctx)
if err != nil {
return err
}
Expand Down Expand Up @@ -160,7 +162,8 @@ func TestDirBuilding(t *testing.T) {
func TestShardReload(t *testing.T) {
ds := mdtest.Mock()
s, _ := NewHamtShard(ds, 256)
ctx := context.Background()
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

_, s, err := makeDir(ds, 200)
if err != nil {
Expand All @@ -177,7 +180,7 @@ func TestShardReload(t *testing.T) {
t.Fatal(err)
}

lnks, err := nds.EnumLinks()
lnks, err := nds.EnumLinks(ctx)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -270,7 +273,7 @@ func TestSetAfterMarshal(t *testing.T) {
}
}

links, err := nds.EnumLinks()
links, err := nds.EnumLinks(ctx)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -301,7 +304,7 @@ func TestDuplicateAddShard(t *testing.T) {
t.Fatal(err)
}

lnks, err := dir.EnumLinks()
lnks, err := dir.EnumLinks(ctx)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -393,7 +396,7 @@ func TestRemoveElemsAfterMarshal(t *testing.T) {
}
}

links, err := nds.EnumLinks()
links, err := nds.EnumLinks(ctx)
if err != nil {
t.Fatal(err)
}
Expand Down
5 changes: 4 additions & 1 deletion io/dagreader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,10 @@ func TestMetadataNode(t *testing.T) {
ctx, closer := context.WithCancel(context.Background())
defer closer()

data, err := unixfs.BytesForMetadata(&unixfs.Metadata{"text", 125})
data, err := unixfs.BytesForMetadata(&unixfs.Metadata{
MimeType: "text",
Size: 125,
})
if err != nil {
t.Fatal(err)
}
Expand Down
8 changes: 4 additions & 4 deletions io/dirbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func (d *Directory) switchToSharding(ctx context.Context) error {
return nil
}

func (d *Directory) ForEachLink(f func(*node.Link) error) error {
func (d *Directory) ForEachLink(ctx context.Context, f func(*node.Link) error) error {
if d.shard == nil {
for _, l := range d.dirnode.Links() {
if err := f(l); err != nil {
Expand All @@ -129,15 +129,15 @@ func (d *Directory) ForEachLink(f func(*node.Link) error) error {
return nil
}

return d.shard.ForEachLink(f)
return d.shard.ForEachLink(ctx, f)
}

func (d *Directory) Links() ([]*node.Link, error) {
func (d *Directory) Links(ctx context.Context) ([]*node.Link, error) {
if d.shard == nil {
return d.dirnode.Links(), nil
}

return d.shard.EnumLinks()
return d.shard.EnumLinks(ctx)
}

func (d *Directory) Find(ctx context.Context, name string) (node.Node, error) {
Expand Down
8 changes: 4 additions & 4 deletions io/dirbuilder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestDirectoryGrowth(t *testing.T) {
t.Fatal(err)
}

links, err := dir.Links()
links, err := dir.Links(ctx)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -86,7 +86,7 @@ func TestDuplicateAddDir(t *testing.T) {
t.Fatal(err)
}

lnks, err := dir.Links()
lnks, err := dir.Links(ctx)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -121,7 +121,7 @@ func TestDirBuilder(t *testing.T) {
t.Fatal(err)
}

links, err := dir.Links()
links, err := dir.Links(ctx)
if err != nil {
t.Fatal(err)
}
Expand All @@ -135,7 +135,7 @@ func TestDirBuilder(t *testing.T) {
t.Fatal(err)
}

links, err = adir.Links()
links, err = adir.Links(ctx)
if err != nil {
t.Fatal(err)
}
Expand Down

0 comments on commit 5e8347c

Please sign in to comment.