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

fix: handle not found errors in pdcleaner #1905

Merged
merged 5 commits into from
Apr 1, 2024
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 itests/framework/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ func (f *TestFramework) MakeDummyDeal(dealUuid uuid.UUID, carFilepath string, ro
if err != nil {
return nil, fmt.Errorf("getting chain head: %w", err)
}
startEpoch := head.Height() + abi.ChainEpoch(600)
startEpoch := head.Height() + abi.ChainEpoch(1000)
l, err := market.NewLabelFromString(rootCid.String())
if err != nil {
return nil, err
Expand Down
21 changes: 20 additions & 1 deletion itests/lid_cleanup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func TestLIDCleanup(t *testing.T) {
head, err := f.FullNode.ChainHead(ctx)
require.NoError(t, err)

startEpoch := head.Height() + 200
startEpoch := head.Height() + 1000
endEpoch := head.Height() + +2880*400

dealUuid := uuid.New()
Expand Down Expand Up @@ -275,6 +275,25 @@ func TestLIDCleanup(t *testing.T) {
return len(stateList) == 2
}, time.Second*15, 1*time.Second, "timeout waiting for sectors to reach TerminateFinality")

var bigger abi.ChainEpoch

bigger = res2.DealParams.ClientDealProposal.Proposal.StartEpoch

if res1.DealParams.ClientDealProposal.Proposal.StartEpoch > res2.DealParams.ClientDealProposal.Proposal.StartEpoch {
bigger = res1.DealParams.ClientDealProposal.Proposal.StartEpoch
}

if bigger < ddParams.StartEpoch {
bigger = ddParams.StartEpoch
}

// Wait till all deal start epochs have passed
require.Eventuallyf(t, func() bool {
h, err := f.FullNode.ChainHead(ctx)
require.NoError(t, err)
return h.Height() > bigger
}, time.Minute*5, time.Second, "timeout waiting for start epochs")

// Clean up LID
err = f.Boost.PdCleanup(ctx)
require.NoError(t, err)
Expand Down
23 changes: 19 additions & 4 deletions lib/pdcleaner/pdcleaner.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package pdcleaner

import (
"fmt"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -98,6 +99,12 @@ func (p *pdcleaner) Start(ctx context.Context) {
}

func (p *pdcleaner) clean() {
// Run at start up
log.Infof("Starting LID clean up")
serr := p.CleanOnce(p.ctx)
log.Errorf("Failed to cleanup LID: %s", serr)
log.Debugf("Finished cleaning up LID")

// Create a ticker with an hour tick
ticker := time.NewTicker(p.cleanupInterval)
defer ticker.Stop()
Expand Down Expand Up @@ -173,7 +180,9 @@ func (p *pdcleaner) CleanOnce(ctx context.Context) error {
if !present && deal.ClientDealProposal.Proposal.StartEpoch < head.Height() {
err = p.pd.RemoveDealForPiece(ctx, deal.ClientDealProposal.Proposal.PieceCID, deal.DealUuid.String())
if err != nil {
// Don't return if cleaning up a deal results in error. Try them all.
if strings.Contains(err.Error(), "not found") {
return nil
}
return fmt.Errorf("cleaning up boost deal %s for piece %s: %s", deal.DealUuid.String(), deal.ClientDealProposal.Proposal.PieceCID.String(), err.Error())
}
}
Expand All @@ -198,7 +207,9 @@ func (p *pdcleaner) CleanOnce(ctx context.Context) error {
if !present {
err = p.pd.RemoveDealForPiece(ctx, deal.ClientDealProposal.Proposal.PieceCID, deal.ProposalCid.String())
if err != nil {
// Don't return if cleaning up a deal results in error. Try them all.
if strings.Contains(err.Error(), "not found") {
return nil
}
return fmt.Errorf("cleaning up legacy deal %s for piece %s: %s", deal.ProposalCid.String(), deal.ClientDealProposal.Proposal.PieceCID.String(), err.Error())
}
}
Expand All @@ -224,7 +235,9 @@ func (p *pdcleaner) CleanOnce(ctx context.Context) error {
if !present {
err = p.pd.RemoveDealForPiece(ctx, deal.PieceCID, deal.ID.String())
if err != nil {
// Don't return if cleaning up a deal results in error. Try them all.
if strings.Contains(err.Error(), "not found") {
return nil
}
return fmt.Errorf("cleaning up direct deal %s for piece %s: %s", deal.ID.String(), deal.PieceCID, err.Error())
}
}
Expand Down Expand Up @@ -281,7 +294,9 @@ func (p *pdcleaner) CleanOnce(ctx context.Context) error {

err = p.pd.RemoveDealForPiece(ctx, piece, deal.DealUuid)
if err != nil {
// Don't return if cleaning up a deal results in error. Try them all.
if strings.Contains(err.Error(), "not found") {
return nil
}
log.Errorf("cleaning up dangling deal %s for piece %s: %s", deal.DealUuid, piece, err.Error())
}
}
Expand Down
Loading