Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(manager): run dymint store block pruning in background #1053

Merged
merged 9 commits into from
Sep 25, 2024

Conversation

srene
Copy link
Contributor

@srene srene commented Aug 30, 2024

PR Standards

Opening a pull request should be able to meet the following requirements

--

PR naming convention: https://hackmd.io/@nZpxHZ0CT7O5ngTp0TP9mg/HJP_jrm7A


Close #1038

<-- Briefly describe the content of this pull request -->

For Author:

  • Targeted PR against correct branch
  • included the correct type prefix in the PR title
  • Linked to Github issue with discussion and accepted design
  • Targets only one github issue
  • Wrote unit and integration tests
  • All CI checks have passed
  • Added relevant godoc comments

For Reviewer:

  • confirmed the correct type prefix in the PR title
  • Reviewers assigned
  • confirmed all author checklist items have been addressed

After reviewer approval:

  • In case targets main branch, PR should be squashed and merged.
  • In case PR targets a release branch, PR should be rebased.

@srene srene requested a review from a team as a code owner August 30, 2024 08:42
@srene srene marked this pull request as draft August 30, 2024 08:42
@srene srene self-assigned this Aug 30, 2024
@srene srene marked this pull request as ready for review August 30, 2024 10:33
@srene srene changed the base branch from main to srene/rolapp_params_refactor August 30, 2024 13:13
@srene srene changed the base branch from srene/rolapp_params_refactor to main August 30, 2024 13:13
Copy link
Contributor

github-actions bot commented Sep 8, 2024

This pull request has been automatically marked as stale because it has not had any recent activity. It will be closed if no further activity occurs. Thank you!

@github-actions github-actions bot added the Stale label Sep 8, 2024
@github-actions github-actions bot closed this Sep 12, 2024
@srene srene reopened this Sep 13, 2024
@srene srene added dym-internal and removed Stale labels Sep 13, 2024
omritoptix
omritoptix previously approved these changes Sep 15, 2024
Copy link
Contributor

@danwt danwt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't see any bugs but there are a lot of errors which are not logged or propogated

Also it's not very DRY wrt other pruning code, especially things like if pruned%1000 == 0 && pruned > 0 where these magic numbers

Are you sure everywhere the error is ignored it's really a good idea?
Could you clean up some of the duplicated code/magic nums?

Not a blocker so will approve if you think it's ok

blockCache: &Cache{
cache: make(map[uint64]types.CachedBlock),
},
pruningC: make(chan int64, 10), // use of buffered channel to avoid blocking applyBlock thread. In case channel is full, pruning will be skipped, but the retain height can be pruned in the next iteration.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the different between using size 10 and size 0 here? isn't 0 effectively the same, but simpler?

Copy link
Contributor Author

@srene srene Sep 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

imo is very similar but not exactly the same. in very active rollapps is probably the same. in not that active rollapps it gives some more chance to finish and prune later blocks that otherwise can be left unpruned till new blocks are created, but i agree there is not a big difference.

Comment on lines 540 to 588
func (idx *BlockerIndexer) pruneBlocks(from, to uint64) (uint64, error) {
pruned := uint64(0)
batch := idx.store.NewBatch()
defer batch.Discard()

flush := func(batch store.KVBatch, height int64) error {
err := batch.Commit()
if err != nil {
return fmt.Errorf("flush batch to disk: height %d: %w", height, err)
}
return nil
}

for h := int64(from); h < int64(to); h++ {
ok, err := idx.Has(h)
if err != nil || !ok {
continue
}
key, err := heightKey(h)
if err != nil {
continue
}
if err := batch.Delete(key); err != nil {
continue
}
if err := idx.pruneEvents(h, batch); err != nil {
continue
}
pruned++

// flush every 1000 blocks to avoid batches becoming too large
if pruned%1000 == 0 && pruned > 0 {
err := flush(batch, h)
if err != nil {
return 0, err
}
batch.Discard()
batch = idx.store.NewBatch()
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like a bit duplicated logic with the other PR/other pruning logic? nevermind

@@ -326,6 +372,49 @@ func txResultWithEvents(events []abci.Event) *abci.TxResult {
},
}
}
func getRandomTxResult(height int64, events []abci.Event) *abci.TxResult {
tx := types.Tx(randomTxHash())
fmt.Println(tx.Hash())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

print

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

Comment on lines 559 to 577
if err != nil {
continue
}
if err := batch.Delete(key); err != nil {
continue
}
if err := idx.pruneEvents(h, batch); err != nil {
continue
}
pruned++
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

want to log?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logs added

Comment on lines +529 to +537
if from <= 0 {
return 0, fmt.Errorf("from height must be greater than 0: %w", gerrc.ErrInvalidArgument)
}

if to <= from {
return 0, fmt.Errorf("to height must be greater than from height: to: %d: from: %d: %w", to, from, gerrc.ErrInvalidArgument)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this really necessary?

Copy link
Contributor Author

@srene srene Sep 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think it does not harm, and it avoids executing unnecessary code, although it should not happen.

danwt
danwt previously approved these changes Sep 17, 2024
@omritoptix omritoptix merged commit 5055ae7 into main Sep 25, 2024
6 checks passed
@omritoptix omritoptix deleted the srene/1038-pruning-bg branch September 25, 2024 10:25
srene added a commit that referenced this pull request Sep 25, 2024
omritoptix pushed a commit that referenced this pull request Sep 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

move pruning to be in the background
3 participants