8000 fix cast in index backed blockstore by dirkmc · Pull Request #146 · filecoin-project/dagstore · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix cast in index backed blockstore #146

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 3, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion indexbs/indexbacked_bs.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func (ro *IndexBackedBlockstore) execOp(ctx context.Context, c cid.Cid, op Block
// thread was waiting to enter the sync.Once
val, ok := ro.blockstoreCache.Get(sk)
if ok {
return val.(dagstore.ReadBlockstore), nil
return val.(*accessorWithBlockstore).bs, nil
}

// Acquire the blockstore for the selected shard
Expand Down
90 changes: 89 additions & 1 deletion indexbs/indexbacked_bs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package indexbs
import (
"context"
"errors"
"fmt"
"testing"

"golang.org/x/sync/errgroup"
Expand All @@ -26,7 +27,7 @@ var noOpSelector = func(c cid.Cid, shards []shard.Key) (shard.Key, error) {

var carv2mnt = &mount.FSMount{FS: testdata.FS, Path: testdata.FSPathCarV2}

func TestReadOnlyBs(t *testing.T) {
func TestIndexBackedBlockstore(t *testing.T) {
ctx := context.Background()
store := dssync.MutexWrap(datastore.NewMapDatastore())
dagst, err := dagstore.NewDAGStore(dagstore.Config{
Expand Down Expand Up @@ -181,6 +182,93 @@ func TestReadOnlyBs(t *testing.T) {
require.EqualValues(t, 0, sz)
}

func TestIndexBackedBlockstoreFuzz(t *testing.T) {
ctx := context.Background()
store := dssync.MutexWrap(datastore.NewMapDatastore())
dagst, err := dagstore.NewDAGStore(dagstore.Config{
MountRegistry: testRegistry(t),
TransientsDir: t.TempDir(),
Datastore: store,
})
require.NoError(t, err)

err = dagst.Start(context.Background())
require.NoError(t, err)

// register some shards
var sks []shard.Key
for i := 0; i < 3; i++ {
ch := make(chan dagstore.ShardResult, 1)
sk := shard.KeyFromString(fmt.Sprintf("test%d", i))
err = dagst.RegisterShard(context.Background(), sk, carv2mnt, ch, dagstore.RegisterOpts{})
require.NoError(t, err)
res := <-ch
require.NoError(t, res.Error)
sks = append(sks, sk)
}

rbs, err := NewIndexBackedBlockstore(ctx, dagst, noOpSelector, 10)
require.NoError(t, err)

var errg errgroup.Group
for _, sk := range sks {
sk := sk
errg.Go(func() error {
it, err := dagst.GetIterableIndex(sk)
if err != nil {
return err
}

for i := 0; i < 3; i++ {
var skerrg errgroup.Group
it.ForEach(func(mh multihash.Multihash, _ uint64) error {
mhs := mh
c := cid.NewCidV1(cid.Raw, mhs)
skerrg.Go(func() error {
has, err := rbs.Has(ctx, c)
if err != nil {
return err
}
if !has {
return errors.New("has should be true")
}
return nil
})

skerrg.Go(func() error {
blk, err := rbs.Get(ctx, c)
if err != nil {
return err
}
if blk == nil {
return errors.New("block should not be empty")
}

// ensure cids match
if blk.Cid() != c {
return errors.New("cid mismatch")
}
return nil
})

skerrg.Go(func() error {
_, err := rbs.GetSize(ctx, c)
return err
})

return nil
})
err := skerrg.Wait()
if err != nil {
return err
}
}
return nil
})
}
require.NoError(t, errg.Wait())
}

func testRegistry(t *testing.T) *mount.Registry {
r := mount.NewRegistry()
err := r.Register("fs", &mount.FSMount{FS: testdata.FS})
Expand Down
0