Skip to content

Commit dfd9017

Browse files
authoredDec 22, 2023
cleanup older fund manager logs (#1856)
1 parent a90b16e commit dfd9017

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed
 

‎db/funds.go

+11
Original file line numberDiff line numberDiff line change
@@ -188,3 +188,14 @@ func (f *FundsDB) TotalTagged(ctx context.Context) (*TotalTagged, error) {
188188

189189
return tt, nil
190190
}
191+
192+
func (f *FundsDB) CleanupLogs(ctx context.Context, daysOld int) error {
193+
194+
t := time.Now()
195+
td := t.AddDate(0, 0, -1*daysOld)
196+
197+
qry := "DELETE from FundsLogs WHERE DealUUID IN (SELECT DISTINCT DealUUID FROM FundsLogs WHERE CreatedAt < ?)"
198+
199+
_, err := f.db.ExecContext(ctx, qry, td)
200+
return err
201+
}

‎fundmanager/fundmanager.go

+22
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"errors"
66
"fmt"
7+
"time"
78

89
"github.com/filecoin-project/boost-gfm/storagemarket"
910
"github.com/filecoin-project/boost/db"
@@ -254,3 +255,24 @@ func toSharedBalance(bal api.MarketBalance) storagemarket.Balance {
254255
Available: big.Sub(bal.Escrow, bal.Locked),
255256
}
256257
}
258+
259+
func (m *FundManager) LogCleanup(ctx context.Context, FundsLogDurationDays int) {
260+
261+
// Create a ticker with an hour tick
262+
ticker := time.NewTicker(time.Hour)
263+
defer ticker.Stop()
264+
265+
for {
266+
select {
267+
case <-ticker.C:
268+
log.Infof("Cleaning logs older than %d days from fundsDB ", FundsLogDurationDays)
269+
err := m.db.CleanupLogs(ctx, FundsLogDurationDays)
270+
if err != nil {
271+
log.Errorf("Failed to cleanup old logs from fundsDB: %s", err)
272+
}
273+
274+
case <-ctx.Done():
275+
return
276+
}
277+
}
278+
}

‎storagemarket/provider.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -487,9 +487,10 @@ func (p *Provider) Start() error {
487487
// Start the transfer limiter
488488
go p.xferLimiter.run(p.ctx)
489489

490-
// Start hourly deal log cleanup
490+
// Start hourly deal and funds log cleanup
491491
if p.config.DealLogDurationDays > 0 {
492492
go p.dealLogger.LogCleanup(p.ctx, p.config.DealLogDurationDays)
493+
go p.fundManager.LogCleanup(p.ctx, p.config.DealLogDurationDays)
493494
}
494495

495496
log.Infow("storage provider: started")

0 commit comments

Comments
 (0)
Please sign in to comment.