Skip to content

Commit 0a73921

Browse files
authored
fix: handle not found errors in pdcleaner (#1905)
* handle not found * run at start up * update itest startEpoch * ensure deal starts in itest * fix lint error
1 parent 4df1ac8 commit 0a73921

File tree

3 files changed

+40
-6
lines changed

3 files changed

+40
-6
lines changed

itests/framework/framework.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ func (f *TestFramework) MakeDummyDeal(dealUuid uuid.UUID, carFilepath string, ro
635635
if err != nil {
636636
return nil, fmt.Errorf("getting chain head: %w", err)
637637
}
638-
startEpoch := head.Height() + abi.ChainEpoch(600)
638+
startEpoch := head.Height() + abi.ChainEpoch(1000)
639639
l, err := market.NewLabelFromString(rootCid.String())
640640
if err != nil {
641641
return nil, err

itests/lid_cleanup_test.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ func TestLIDCleanup(t *testing.T) {
175175
head, err := f.FullNode.ChainHead(ctx)
176176
require.NoError(t, err)
177177

178-
startEpoch := head.Height() + 200
178+
startEpoch := head.Height() + 1000
179179
endEpoch := head.Height() + +2880*400
180180

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

278+
var bigger abi.ChainEpoch
279+
280+
bigger = res2.DealParams.ClientDealProposal.Proposal.StartEpoch
281+
282+
if res1.DealParams.ClientDealProposal.Proposal.StartEpoch > res2.DealParams.ClientDealProposal.Proposal.StartEpoch {
283+
bigger = res1.DealParams.ClientDealProposal.Proposal.StartEpoch
284+
}
285+
286+
if bigger < ddParams.StartEpoch {
287+
bigger = ddParams.StartEpoch
288+
}
289+
290+
// Wait till all deal start epochs have passed
291+
require.Eventuallyf(t, func() bool {
292+
h, err := f.FullNode.ChainHead(ctx)
293+
require.NoError(t, err)
294+
return h.Height() > bigger
295+
}, time.Minute*5, time.Second, "timeout waiting for start epochs")
296+
278297
// Clean up LID
279298
err = f.Boost.PdCleanup(ctx)
280299
require.NoError(t, err)

lib/pdcleaner/pdcleaner.go

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package pdcleaner
22

33
import (
44
"fmt"
5+
"strings"
56
"sync"
67
"time"
78

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

100101
func (p *pdcleaner) clean() {
102+
// Run at start up
103+
log.Infof("Starting LID clean up")
104+
serr := p.CleanOnce(p.ctx)
105+
log.Errorf("Failed to cleanup LID: %s", serr)
106+
log.Debugf("Finished cleaning up LID")
107+
101108
// Create a ticker with an hour tick
102109
ticker := time.NewTicker(p.cleanupInterval)
103110
defer ticker.Stop()
@@ -173,7 +180,9 @@ func (p *pdcleaner) CleanOnce(ctx context.Context) error {
173180
if !present && deal.ClientDealProposal.Proposal.StartEpoch < head.Height() {
174181
err = p.pd.RemoveDealForPiece(ctx, deal.ClientDealProposal.Proposal.PieceCID, deal.DealUuid.String())
175182
if err != nil {
176-
// Don't return if cleaning up a deal results in error. Try them all.
183+
if strings.Contains(err.Error(), "not found") {
184+
return nil
185+
}
177186
return fmt.Errorf("cleaning up boost deal %s for piece %s: %s", deal.DealUuid.String(), deal.ClientDealProposal.Proposal.PieceCID.String(), err.Error())
178187
}
179188
}
@@ -198,7 +207,9 @@ func (p *pdcleaner) CleanOnce(ctx context.Context) error {
198207
if !present {
199208
err = p.pd.RemoveDealForPiece(ctx, deal.ClientDealProposal.Proposal.PieceCID, deal.ProposalCid.String())
200209
if err != nil {
201-
// Don't return if cleaning up a deal results in error. Try them all.
210+
if strings.Contains(err.Error(), "not found") {
211+
return nil
212+
}
202213
return fmt.Errorf("cleaning up legacy deal %s for piece %s: %s", deal.ProposalCid.String(), deal.ClientDealProposal.Proposal.PieceCID.String(), err.Error())
203214
}
204215
}
@@ -224,7 +235,9 @@ func (p *pdcleaner) CleanOnce(ctx context.Context) error {
224235
if !present {
225236
err = p.pd.RemoveDealForPiece(ctx, deal.PieceCID, deal.ID.String())
226237
if err != nil {
227-
// Don't return if cleaning up a deal results in error. Try them all.
238+
if strings.Contains(err.Error(), "not found") {
239+
return nil
240+
}
228241
return fmt.Errorf("cleaning up direct deal %s for piece %s: %s", deal.ID.String(), deal.PieceCID, err.Error())
229242
}
230243
}
@@ -281,7 +294,9 @@ func (p *pdcleaner) CleanOnce(ctx context.Context) error {
281294

282295
err = p.pd.RemoveDealForPiece(ctx, piece, deal.DealUuid)
283296
if err != nil {
284-
// Don't return if cleaning up a deal results in error. Try them all.
297+
if strings.Contains(err.Error(), "not found") {
298+
return nil
299+
}
285300
log.Errorf("cleaning up dangling deal %s for piece %s: %s", deal.DealUuid, piece, err.Error())
286301
}
287302
}

0 commit comments

Comments
 (0)