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(pruning): fair pruning #8180

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open

feat(pruning): fair pruning #8180

wants to merge 7 commits into from

Conversation

emhane
Copy link
Member

@emhane emhane commented May 9, 2024

Closes #7343, related to pruner interruption ref #6770.

  • Models exhaustive list of prunable tables as a ring.
  • Implements a segment iterator, that generates a cycle of segments, wrt to given start table.
  • Saves last pruned table between prune jobs. This ensures fair pruning, as the next job can pick up where the last one left off.

@emhane emhane added C-enhancement New feature or request A-pruning Related to pruning or full node labels May 9, 2024
@emhane emhane requested a review from onbjerg May 9, 2024 15:59
@github-actions github-actions bot added the C-bug An unexpected or incorrect behavior label May 9, 2024
@emhane
Copy link
Member Author

emhane commented May 9, 2024

still have to build some tests

@shekhirin shekhirin removed the C-bug An unexpected or incorrect behavior label May 9, 2024
@emhane emhane requested a review from DaniPopes May 9, 2024 16:11
@shekhirin
Copy link
Collaborator

It feels a bit overcomplicated, can we just have a VecDeque of segments that we pop/push from/to?

How I see it:

  1. VecDeque of segments initialized when the pruner is initialized
  2. When we prune, we pop segments from the VecDeque one by one until there's none left
  3. When a limit (with timeout or items deleted) is hit, push segments that we ran to the end of the VecDeque
  4. On the next run, pop will return segments that we didn't run first

WDYT?

@shekhirin
Copy link
Collaborator

Saves last pruned table between prune jobs

I am not sure if we need it, what is the case when we want to continue pruning some table inside a segment, and not the whole segment from the beginning?

@emhane
Copy link
Member Author

emhane commented May 10, 2024

It feels a bit overcomplicated, can we just have a VecDeque of segments that we pop/push from/to?

How I see it:

  1. VecDeque of segments initialized when the pruner is initialized
  2. When we prune, we pop segments from the VecDeque one by one until there's none left
  3. When a limit (with timeout or items deleted) is hit, push segments that we ran to the end of the VecDeque
  4. On the next run, pop will return segments that we didn't run first

WDYT?

No need to reallocate memory, easiest is to just save the index we would have pruned next in the Vec<Box<dyn Segment>>.

True that there is no need to generate the segments, other than for static files, on each call to prune_segments. On second look, I saw that PruneMode::Before is not used in the static allocation of Vec<Box<dyn Segment>> which is built using PruneModes.

@emhane
Copy link
Member Author

emhane commented May 13, 2024

Saves last pruned table between prune jobs

I am not sure if we need it, what is the case when we want to continue pruning some table inside a segment, and not the whole segment from the beginning?

checkpoints are saved when pruning stops

@shekhirin
Copy link
Collaborator

No need to reallocate memory, easiest is to just save the index we would have pruned next in the Vec<Box<dyn Segment>>.

up to you, I'd prefer a VecDeque for a more intuitive API. Since all segments are Box, it's not a big overhead. Also, VecDeque doesn't have a requirement for the elements to be contiguous in memory.

"Since VecDeque is a ring buffer, its elements are not necessarily contiguous in memory." – from https://doc.rust-lang.org/std/collections/struct.VecDeque.html

@emhane
Copy link
Member Author

emhane commented May 16, 2024

don't think it makes that big difference now that this is implemented + tested

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-pruning Related to pruning or full node C-enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

segment ring for fair pruning
2 participants