@@ -2,6 +2,7 @@ package pdcleaner
2
2
3
3
import (
4
4
"fmt"
5
+ "strings"
5
6
"sync"
6
7
"time"
7
8
@@ -98,6 +99,12 @@ func (p *pdcleaner) Start(ctx context.Context) {
98
99
}
99
100
100
101
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
+
101
108
// Create a ticker with an hour tick
102
109
ticker := time .NewTicker (p .cleanupInterval )
103
110
defer ticker .Stop ()
@@ -173,7 +180,9 @@ func (p *pdcleaner) CleanOnce(ctx context.Context) error {
173
180
if ! present && deal .ClientDealProposal .Proposal .StartEpoch < head .Height () {
174
181
err = p .pd .RemoveDealForPiece (ctx , deal .ClientDealProposal .Proposal .PieceCID , deal .DealUuid .String ())
175
182
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
+ }
177
186
return fmt .Errorf ("cleaning up boost deal %s for piece %s: %s" , deal .DealUuid .String (), deal .ClientDealProposal .Proposal .PieceCID .String (), err .Error ())
178
187
}
179
188
}
@@ -198,7 +207,9 @@ func (p *pdcleaner) CleanOnce(ctx context.Context) error {
198
207
if ! present {
199
208
err = p .pd .RemoveDealForPiece (ctx , deal .ClientDealProposal .Proposal .PieceCID , deal .ProposalCid .String ())
200
209
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
+ }
202
213
return fmt .Errorf ("cleaning up legacy deal %s for piece %s: %s" , deal .ProposalCid .String (), deal .ClientDealProposal .Proposal .PieceCID .String (), err .Error ())
203
214
}
204
215
}
@@ -224,7 +235,9 @@ func (p *pdcleaner) CleanOnce(ctx context.Context) error {
224
235
if ! present {
225
236
err = p .pd .RemoveDealForPiece (ctx , deal .PieceCID , deal .ID .String ())
226
237
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
+ }
228
241
return fmt .Errorf ("cleaning up direct deal %s for piece %s: %s" , deal .ID .String (), deal .PieceCID , err .Error ())
229
242
}
230
243
}
@@ -281,7 +294,9 @@ func (p *pdcleaner) CleanOnce(ctx context.Context) error {
281
294
282
295
err = p .pd .RemoveDealForPiece (ctx , piece , deal .DealUuid )
283
296
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
+ }
285
300
log .Errorf ("cleaning up dangling deal %s for piece %s: %s" , deal .DealUuid , piece , err .Error ())
286
301
}
287
302
}
0 commit comments