Skip to content

Commit

Permalink
DeleteLoop exit logic fix
Browse files Browse the repository at this point in the history
  • Loading branch information
urtho committed Oct 3, 2024
1 parent c0b1b05 commit 5434bdb
Showing 1 changed file with 31 additions and 28 deletions.
59 changes: 31 additions & 28 deletions plugin/exporter/idb/cockroach/util/prune.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,37 +72,40 @@ func (p *cdb) DeleteLoop(wg *sync.WaitGroup, nextRound *uint64) {

// round value used for interval calculation
round := *nextRound
for {
select {
case <-p.ctx.Done():
return
case <-time.After(p.duration):
currentRound := *nextRound
// keep, remove data older than keep
keep := currentRound - p.config.Rounds
if p.config.Interval == once {
if currentRound > p.config.Rounds {
err := p.db.DeleteTransactions(p.ctx, keep)
if err != nil {
p.logger.Warnf("DeleteLoop(): data pruning err: %v", err)
}
}
func() {
for {
select {
case <-p.ctx.Done():
return
} else if p.config.Interval > disabled {
// *nextRound should increment as exporter receives new block
if currentRound > p.config.Rounds && currentRound-round >= uint64(p.config.Interval) {
err := p.db.DeleteTransactions(p.ctx, keep)
if err != nil {
p.logger.Warnf("DeleteLoop(): data pruning err: %v", err)
return
case <-time.After(p.duration):
currentRound := *nextRound
// keep, remove data older than keep
keep := currentRound - p.config.Rounds
if p.config.Interval == once {
if currentRound > p.config.Rounds {
err := p.db.DeleteTransactions(p.ctx, keep)
if err != nil {
p.logger.Warnf("DeleteLoop(): data pruning err: %v", err)
}
}
return
} else if p.config.Interval > disabled {
// *nextRound should increment as exporter receives new block
if currentRound > p.config.Rounds && currentRound-round >= uint64(p.config.Interval) {
err := p.db.DeleteTransactions(p.ctx, keep)
if err != nil {
p.logger.Warnf("DeleteLoop(): data pruning err: %v", err)
} else {
// update round value for next interval calculation
round = currentRound
}
}
// update round value for next interval calculation
round = currentRound
} else {
p.logger.Fatalf("DeleteLoop(): unsupported interval value %v", p.config.Interval)
return
}
} else {
p.logger.Fatalf("DeleteLoop(): unsupported interval value %v", p.config.Interval)
return
}
}
}
}()
p.logger.Warn("DeleteLoop(): loop terminated")
}

0 comments on commit 5434bdb

Please sign in to comment.