Senders prune logging (#2645)

This commit is contained in:
Alex Sharov 2021-09-08 16:11:05 +07:00 committed by GitHub
parent 0d79c19f21
commit fd69b509a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -347,8 +347,12 @@ func UnwindSendersStage(s *UnwindState, tx kv.RwTx, cfg SendersCfg, ctx context.
}
func PruneSendersStage(s *PruneState, tx kv.RwTx, cfg SendersCfg, ctx context.Context) (err error) {
if !cfg.prune.TxIndex.Enabled() {
return nil
}
logEvery := time.NewTicker(logInterval)
defer logEvery.Stop()
to := cfg.prune.TxIndex.PruneTo(s.ForwardProgress)
useExternalTx := tx != nil
if !useExternalTx {
tx, err = cfg.db.BeginRw(ctx)
@ -357,24 +361,32 @@ func PruneSendersStage(s *PruneState, tx kv.RwTx, cfg SendersCfg, ctx context.Co
}
defer tx.Rollback()
}
if cfg.prune.TxIndex.Enabled() {
c, err := tx.RwCursor(kv.Senders)
if err != nil {
return fmt.Errorf("failed to create cursor for pruning %w", err)
}
defer c.Close()
for k, _, err := c.First(); k != nil; k, _, err = c.Next() {
if err != nil {
return err
}
blockNum := binary.BigEndian.Uint64(k)
if blockNum >= to {
break
}
if err = c.DeleteCurrent(); err != nil {
return fmt.Errorf("failed to remove for block %d: %w", blockNum, err)
}
c, err := tx.RwCursor(kv.Senders)
if err != nil {
return fmt.Errorf("failed to create cursor for pruning %w", err)
}
defer c.Close()
for k, _, err := c.First(); k != nil; k, _, err = c.Next() {
if err != nil {
return err
}
blockNum := binary.BigEndian.Uint64(k)
select {
case <-logEvery.C:
log.Info(fmt.Sprintf("[%s]", s.LogPrefix()), "table", kv.Senders, "block", blockNum)
case <-ctx.Done():
return common.ErrStopped
default:
}
if blockNum >= to {
break
}
if err = c.DeleteCurrent(); err != nil {
return fmt.Errorf("failed to remove for block %d: %w", blockNum, err)
}
}
if !useExternalTx {