Skip to content
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

feat: dagstore: Add DestroyShard() in dagstore wrapper #205

Merged
merged 2 commits into from
Oct 9, 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
5 changes: 3 additions & 2 deletions cmd/market-client/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -703,8 +703,9 @@ uiLoop:
continue
}

if days < int(MinDealDuration/builtin.EpochsInDay) {
printErr(fmt.Errorf("minimum duration is %d days", int(MinDealDuration/builtin.EpochsInDay)))
minDealDurationDays := uint64(MinDealDuration) / (builtin.SecondsInDay / BlockDelaySecs)
if days < int(minDealDurationDays) {
printErr(fmt.Errorf("minimum duration is %d days", minDealDurationDays))
continue
}

Expand Down
14 changes: 14 additions & 0 deletions dagstore/wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,20 @@ func (w *Wrapper) RegisterShard(ctx context.Context, pieceCid cid.Cid, carPath s
return nil
}

func (w *Wrapper) DestroyShard(ctx context.Context, pieceCid cid.Cid, resch chan dagstore.ShardResult) error {
key := shard.KeyFromCID(pieceCid)

opts := dagstore.DestroyOpts{}

err := w.dagst.DestroyShard(ctx, key, resch, opts)
if err != nil {
return fmt.Errorf("failed to schedule destroy shard for piece CID %s: %w", pieceCid, err)
}
log.Debugf("successfully submitted destroy Shard request for piece CID %s", pieceCid)

return nil
}

func (w *Wrapper) MigrateDeals(ctx context.Context, deals []storagemarket.MinerDeal) (bool, error) {
log := log.Named("migrator")

Expand Down
32 changes: 29 additions & 3 deletions dagstore/wrapper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ import (
"github.com/stretchr/testify/require"
)

// TestWrapperAcquireRecovery verifies that if acquire shard returns a "not found"
// TestWrapperAcquireRecoveryDestroy verifies that if acquire shard returns a "not found"
// error, the wrapper will attempt to register the shard then reacquire
func TestWrapperAcquireRecovery(t *testing.T) {
func TestWrapperAcquireRecoveryDestroy(t *testing.T) {
ctx := context.Background()
pieceCid, err := cid.Parse("bafkqaaa")
require.NoError(t, err)
Expand All @@ -48,6 +48,7 @@ func TestWrapperAcquireRecovery(t *testing.T) {
Accessor: getShardAccessor(t),
},
register: make(chan shard.Key, 1),
destroy: make(chan shard.Key, 1),
}
w.dagst = mock

Expand All @@ -73,6 +74,28 @@ func TestWrapperAcquireRecovery(t *testing.T) {
count++
}
require.Greater(t, count, 0)

// Destroy the shard
dr := make(chan dagstore.ShardResult, 1)
err = w.DestroyShard(ctx, pieceCid, dr)
require.NoError(t, err)

dctx, cancel := context.WithTimeout(ctx, time.Second)
defer cancel()
select {
case <-dctx.Done():
require.Fail(t, "failed to call destroy")
case k := <-mock.destroy:
require.Equal(t, k.String(), pieceCid.String())
}

var dcount int
dch, err := mybs.AllKeysChan(ctx)
require.NoError(t, err)
for range dch {
count++
}
require.Equal(t, dcount, 0)
}

// TestWrapperBackground verifies the behaviour of the background go routine
Expand Down Expand Up @@ -130,6 +153,7 @@ type mockDagStore struct {

gc chan struct{}
recover chan shard.Key
destroy chan shard.Key
close chan struct{}
}

Expand All @@ -142,7 +166,9 @@ func (m *mockDagStore) ShardsContainingMultihash(ctx context.Context, h mh.Multi
}

func (m *mockDagStore) DestroyShard(ctx context.Context, key shard.Key, out chan dagstore.ShardResult, _ dagstore.DestroyOpts) error {
panic("implement me")
m.destroy <- key
out <- dagstore.ShardResult{Key: key}
return nil
}

func (m *mockDagStore) GetShardInfo(k shard.Key) (dagstore.ShardInfo, error) {
Expand Down