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

Add new compaction abstraction, simulator, and implementation. #6830

Merged
merged 14 commits into from
Feb 27, 2024

Conversation

arpad-m
Copy link
Member

@arpad-m arpad-m commented Feb 20, 2024

Rebased version of #5234, part of #6768

This consists of three parts:

  1. A refactoring and new contract for implementing and testing compaction.

The logic is now in a separate crate, with no dependency on the 'pageserver' crate. It defines an interface that the real pageserver must implement, in order to call the compaction algorithm. The interface models things like delta and image layers, but just the parts that the compaction algorithm needs to make decisions. That makes it easier unit test the algorithm and experiment with different implementations.

I did not convert the current code to the new abstraction, however. When compaction algorithm is set to "Legacy", we just use the old code. It might be worthwhile to convert the old code to the new abstraction, so that we can compare the behavior of the new algorithm against the old one, using the same simulated cases. If we do that, have to be careful that the converted code really is equivalent to the old.

This inclues only trivial changes to the main pageserver code. All the new code is behind a tenant config option. So this should be pretty safe to merge, even if the new implementation is buggy, as long as we don't enable it.

  1. A new compaction algorithm, implemented using the new abstraction.

The new algorithm is tiered compaction. It is inspired by the PoC at PR #4539, although I did not use that code directly, as I needed the new implementation to fit the new abstraction. The algorithm here is less advanced, I did not implement partial image layers, for example. I wanted to keep it simple on purpose, so that as we add bells and whistles, we can see the effects using the included simulator.

One difference to #4539 and your typical LSM tree implementations is how we keep track of the LSM tree levels. This PR doesn't have a permanent concept of a level, tier or sorted run at all. There are just delta and image layers. However, when compaction starts, we look at the layers that exist, and arrange them into levels, depending on their shapes. That is ephemeral: when the compaction finishes, we forget that information. This allows the new algorithm to work without any extra bookkeeping. That makes it easier to transition from the old algorithm to new, and back again.

There is just a new tenant config option to choose the compaction algorithm. The default is "Legacy", meaning the current algorithm in 'main'. If you set it to "Tiered", the new algorithm is used.

  1. A simulator, which implements the new abstraction.

The simulator can be used to analyze write and storage amplification, without running a test with the full pageserver. It can also draw an SVG animation of the simulation, to visualize how layers are created and deleted.

To run the simulator:

cargo run --bin compaction-simulator run-suite

This consists of three parts:

1. A refactoring and new contract for implementing and testing
compaction.

The logic is now in a separate crate, with no dependency on the
'pageserver' crate. It defines an interface that the real pageserver
must implement, in order to call the compaction algorithm. The
interface models things like delta and image layers, but just the
parts that the compaction algorithm needs to make decisions. That
makes it easier unit test the algorithm and experiment with different
implementations.

I did not convert the current code to the new abstraction, however.
When compaction algorithm is set to "Legacy", we just use the old
code. It might be worthwhile to convert the old code to the new
abstraction, so that we can compare the behavior of the new algorithm
against the old one, using the same simulated cases. If we do that,
have to be careful that the converted code really is equivalent to the
old.

This inclues only trivial changes to the main pageserver code. All the
new code is behind a tenant config option. So this should be pretty
safe to merge, even if the new implementation is buggy, as long as we
don't enable it.

2. A new compaction algorithm, implemented using the new
abstraction.

The new algorithm is tiered compaction.  It is inspired by the PoC at
PR #4539, although I did not use that code directly, as I needed the
new implementation to fit the new abstraction. The algorithm here is
less advanced, I did not implement partial image layers, for example.
I wanted to keep it simple on purpose, so that as we add bells and
whistles, we can see the effects using the included simulator.

One difference to #4539 and your typical LSM tree implementations is
how we keep track of the LSM tree levels. This PR doesn't have a
permanent concept of a level, tier or sorted run at all. There are
just delta and image layers. However, when compaction starts, we look
at the layers that exist, and arrange them into levels, depending on
their shapes. That is ephemeral: when the compaction finishes, we
forget that information. This allows the new algorithm to work without
any extra bookkeeping. That makes it easier to transition from the old
algorithm to new, and back again.

There is just a new tenant config option to choose the compaction
algorithm. The default is "Legacy", meaning the current algorithm in
'main'. If you set it to "Tiered".

3. A simulator, which implements the new abstraction.

The simulator can be used to analyze write and storage amplification,
without running a test with the full pageserver. It can also draw an
SVG animation of the simulation, to visualize how layers are created
and deleted.

To run the simulator:

    ./target/debug/compaction-simulator run-suite
@arpad-m arpad-m requested review from a team as code owners February 20, 2024 01:37
@arpad-m arpad-m requested review from jcsp and lubennikovaav and removed request for a team February 20, 2024 01:37
Copy link

github-actions bot commented Feb 20, 2024

2418 tests run: 2297 passed, 0 failed, 121 skipped (full report)


Flaky tests (1)

Postgres 16

  • test_location_conf_churn[3]: debug

Code coverage* (full report)

  • functions: 28.4% (6811 of 23982 functions)
  • lines: 46.8% (41553 of 88730 lines)

* collected from Rust tests only


The comment gets automatically updated with the latest test results
55de35c at 2024-02-23T16:49:08.832Z :recycle:

@arpad-m
Copy link
Member Author

arpad-m commented Feb 20, 2024

cc @hlinnaka

I pushed this with the last published state of #5234 . Have only spent 4-5 hours today rebasing it and adjusting it for the changes that happened since, not done anything else (large part was waiting for the compiler).

Next is to address the review comments on #5234 by @koivunej and me, or put them as followups.

Copy link
Member

@koivunej koivunej left a comment

Choose a reason for hiding this comment

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

Assuming tests pass, it seems to the new tiered compaction should not be used by default so all good for follow-ups. There is one rebase introduction I noticed, which is sadly pub struct ....

And ignoring the generated html.

Left suggestions for few left-over cleanups.

pageserver/src/tenant/config.rs Outdated Show resolved Hide resolved
pageserver/src/tenant/timeline.rs Show resolved Hide resolved
pageserver/compaction/tests/tests.rs Show resolved Hide resolved
pageserver/compaction/tests/tests.rs Outdated Show resolved Hide resolved
pageserver/compaction/src/compact_tiered.rs Outdated Show resolved Hide resolved
pageserver/src/tenant/timeline.rs Show resolved Hide resolved
@arpad-m
Copy link
Member Author

arpad-m commented Feb 22, 2024

Force pushed to get rid of the stray files

@arpad-m arpad-m merged commit 045bc6a into main Feb 27, 2024
50 checks passed
@arpad-m arpad-m deleted the arpad/compaction branch February 27, 2024 16:15
arpad-m added a commit that referenced this pull request Mar 5, 2024
Minor non-functional improvements to tiered compaction, mostly
consisting of comment fixes.

Followup of  #6830, part of #6768
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants