Skip to content

Commit 076595d

Browse files
authored
temp (pruning): Logs and timers for debugging (#29)
* Added logs to indicate pruning op started and timers to count time * Added pruner max batch size to config * Add UTs for block and state pruning in batches * Added UTs for tx indexer batch removals * Removed println * Expanded UT to confirm subsequent batch is pruned * Add batch limit to ABCI response pruning * Revert "Add batch limit to ABCI response pruning" This reverts commit 886333f. * Revert "Expanded UT to confirm subsequent batch is pruned" This reverts commit e98850a. * Revert "Removed println" This reverts commit 38767be. * Revert "Added UTs for tx indexer batch removals" This reverts commit 18eae71. * Revert "Add UTs for block and state pruning in batches" This reverts commit 0a01939. * Revert "Added pruner max batch size to config" This reverts commit bec5c52. * Unified pruning count prefix * Attemp to fix linter error
1 parent 72fcfe5 commit 076595d

1 file changed

Lines changed: 32 additions & 14 deletions

File tree

state/pruner.go

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -384,23 +384,32 @@ func (p *Pruner) pruneIndexesRoutine() {
384384
}
385385
}
386386

387+
func (p *Pruner) parseError(err error, indexerType string, lastRetainHeight int64) int64 {
388+
// Indexer retain height has not yet been set - do not log any
389+
// errors at this time.
390+
if errors.Is(err, ErrKeyNotFound) {
391+
return 0
392+
}
393+
p.logger.Error("Failed to get "+indexerType+" retain height", "err", err)
394+
return lastRetainHeight
395+
}
396+
387397
func (p *Pruner) pruneTxIndexerToRetainHeight(lastRetainHeight int64) int64 {
398+
388399
targetRetainHeight, err := p.GetTxIndexerRetainHeight()
400+
p.logger.Info("txIndex pruning started", "currentHeight", lastRetainHeight, "targetRetainHeight", targetRetainHeight)
389401
if err != nil {
390-
// Indexer retain height has not yet been set - do not log any
391-
// errors at this time.
392-
if errors.Is(err, ErrKeyNotFound) {
393-
return 0
394-
}
395-
p.logger.Error("Failed to get Indexer retain height", "err", err)
396-
return lastRetainHeight
402+
return p.parseError(err, "txindexer", lastRetainHeight)
397403
}
398404

399405
if lastRetainHeight >= targetRetainHeight {
400406
return lastRetainHeight
401407
}
402408

409+
tStart := time.Now()
403410
numPrunedTxIndexer, newTxIndexerRetainHeight, err := p.txIndexer.Prune(targetRetainHeight)
411+
tElapsed := time.Since(tStart)
412+
p.logger.Info("txIndex pruning time", "elapsed", tElapsed.String(), "pruned", numPrunedTxIndexer, "newTxIndexerRetainHeight", newTxIndexerRetainHeight)
404413
if err != nil {
405414
p.logger.Error("Failed to prune tx indexer", "err", err, "targetRetainHeight", targetRetainHeight, "newTxIndexerRetainHeight", newTxIndexerRetainHeight)
406415
} else if numPrunedTxIndexer > 0 {
@@ -411,22 +420,21 @@ func (p *Pruner) pruneTxIndexerToRetainHeight(lastRetainHeight int64) int64 {
411420
}
412421

413422
func (p *Pruner) pruneBlockIndexerToRetainHeight(lastRetainHeight int64) int64 {
423+
414424
targetRetainHeight, err := p.GetBlockIndexerRetainHeight()
425+
p.logger.Info("block pruning started", "currentHeight", lastRetainHeight, "targetRetainHeight", targetRetainHeight)
415426
if err != nil {
416-
// Indexer retain height has not yet been set - do not log any
417-
// errors at this time.
418-
if errors.Is(err, ErrKeyNotFound) {
419-
return 0
420-
}
421-
p.logger.Error("Failed to get Indexer retain height", "err", err)
422-
return lastRetainHeight
427+
return p.parseError(err, "blockIndexer", lastRetainHeight)
423428
}
424429

425430
if lastRetainHeight >= targetRetainHeight {
426431
return lastRetainHeight
427432
}
428433

434+
tStart := time.Now()
429435
numPrunedBlockIndexer, newBlockIndexerRetainHeight, err := p.blockIndexer.Prune(targetRetainHeight)
436+
tElapsed := time.Since(tStart)
437+
p.logger.Info("block pruning time", "elapsed", tElapsed.String(), "pruned", numPrunedBlockIndexer, "newBlockIndexerRetainHeight", newBlockIndexerRetainHeight)
430438
if err != nil {
431439
p.logger.Error("Failed to prune block indexer", "err", err, "targetRetainHeight", targetRetainHeight, "newBlockIndexerRetainHeight", newBlockIndexerRetainHeight)
432440
} else if numPrunedBlockIndexer > 0 {
@@ -437,11 +445,16 @@ func (p *Pruner) pruneBlockIndexerToRetainHeight(lastRetainHeight int64) int64 {
437445
}
438446

439447
func (p *Pruner) pruneBlocksToRetainHeight(lastRetainHeight int64) int64 {
448+
440449
targetRetainHeight := p.findMinBlockRetainHeight()
450+
p.logger.Info("block pruning started", "currentHeight", lastRetainHeight, "targetRetainHeight", targetRetainHeight)
441451
if targetRetainHeight == lastRetainHeight {
442452
return lastRetainHeight
443453
}
454+
tStart := time.Now()
444455
pruned, evRetainHeight, err := p.pruneBlocksToHeight(targetRetainHeight)
456+
elapsed := time.Since(tStart)
457+
p.logger.Info("block pruning time", "elapsed", elapsed.String(), "pruned", pruned, "evidenceRetainHeight", evRetainHeight)
445458
// The new retain height is the current lowest point of the block store
446459
// indicated by Base()
447460
newRetainHeight := p.bs.Base()
@@ -455,7 +468,9 @@ func (p *Pruner) pruneBlocksToRetainHeight(lastRetainHeight int64) int64 {
455468
}
456469

457470
func (p *Pruner) pruneABCIResToRetainHeight(lastRetainHeight int64) int64 {
471+
458472
targetRetainHeight, err := p.stateStore.GetABCIResRetainHeight()
473+
p.logger.Info("abcires pruning started", "currentHeight", lastRetainHeight, "targetRetainHeight", targetRetainHeight)
459474
if err != nil {
460475
p.logger.Error("Failed to get ABCI response retain height", "err", err)
461476
if errors.Is(err, ErrKeyNotFound) {
@@ -477,7 +492,10 @@ func (p *Pruner) pruneABCIResToRetainHeight(lastRetainHeight int64) int64 {
477492
// newRetainHeight is the height just after that which we have successfully
478493
// pruned. In case of an error it will be 0, but then it will also be
479494
// ignored.
495+
tStart := time.Now()
480496
numPruned, newRetainHeight, err := p.stateStore.PruneABCIResponses(targetRetainHeight, forceCompact)
497+
tElapsed := time.Since(tStart)
498+
p.logger.Info("abcires pruning time", "elapsed", tElapsed.String(), "pruned", numPruned, "newRetainHeight", newRetainHeight)
481499
if err != nil {
482500
p.logger.Error("Failed to prune ABCI responses", "err", err, "targetRetainHeight", targetRetainHeight)
483501
return lastRetainHeight

0 commit comments

Comments
 (0)