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: add blockstore that is the union of several CAR stores #3288

Merged
merged 34 commits into from
Jul 31, 2023

Conversation

lemmih
Copy link
Contributor

@lemmih lemmih commented Jul 30, 2023

Summary of changes

Changes introduced in this pull request:

  • add ManyCar blockstore which takes the union of several CAR-files.
  • use a shared z-frame cache, limited by byte size rather than pages.
  • use ManyCar in as many commands as possible.

Reference issue to close (if applicable)

Roadmap: #3222

Other information and links

Benchmarks

Linear scan through a mainnet snapshot to find the genesis block:

Command Mean [s] Min [s] Max [s] Relative
Genesis Scan: 0-MiB 7.829 ± 0.120 7.629 7.975 3.38 ± 0.06
Genesis Scan: 32-MiB 2.314 ± 0.019 2.287 2.354 1.00
Genesis Scan: 64-MiB 2.342 ± 0.031 2.316 2.401 1.01 ± 0.02
Genesis Scan: 128-MiB 2.401 ± 0.037 2.357 2.458 1.04 ± 0.02
Genesis Scan: 256-MiB 2.436 ± 0.019 2.400 2.473 1.05 ± 0.01
Genesis Scan: 512-MiB 2.522 ± 0.036 2.489 2.573 1.09 ± 0.02
Genesis Scan: 1024-MiB 2.542 ± 0.024 2.503 2.573 1.10 ± 0.01
Genesis Scan: 2048-MiB 2.523 ± 0.036 2.488 2.602 1.09 ± 0.02

Caching a single frame is sufficient when doing a linear scan. It's surprising that large caches hurt performance, though. Not sure why that is.

Executing 100 tipsets:

Command Mean [s] Min [s] Max [s] Relative
Execute 100 tipsets: 0-MiB 212.465 ± 1.082 211.468 213.615 3.33 ± 0.02
Execute 100 tipsets: 32-MiB 71.316 ± 1.105 70.204 72.415 1.12 ± 0.02
Execute 100 tipsets: 64-MiB 68.967 ± 0.652 68.378 69.667 1.08 ± 0.01
Execute 100 tipsets: 128-MiB 66.412 ± 0.174 66.265 66.604 1.04 ± 0.01
Execute 100 tipsets: 256-MiB 66.021 ± 0.080 65.947 66.106 1.04 ± 0.00
Execute 100 tipsets: 512-MiB 63.754 ± 0.270 63.504 64.039 1.00
Execute 100 tipsets: 1024-MiB 63.764 ± 0.357 63.391 64.102 1.00 ± 0.01
Execute 100 tipsets: 2048-MiB 64.399 ± 0.790 63.865 65.306 1.01 ± 0.01

Change checklist

  • I have performed a self-review of my own code,
  • I have made corresponding changes to the documentation,
  • I have added tests that prove my fix is effective or that my feature works (if possible),
  • I have made sure the CHANGELOG is up-to-date. All user-facing changes should be reflected in this document.

@lemmih lemmih marked this pull request as ready for review July 31, 2023 05:35
@lemmih lemmih requested a review from a team as a code owner July 31, 2023 05:35
@lemmih lemmih removed the request for review from a team July 31, 2023 05:35
}

impl<WriterT> ManyCar<WriterT> {
pub fn read_only<ReaderT: super::CarReader>(&mut self, any_car: AnyCar<ReaderT>) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: push_read_only might be more descriptive

writer: WriterT,
}

impl ManyCar {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: state migration tests could use ManyCar. I can also do that in a separate PR

Copy link
Contributor

Choose a reason for hiding this comment

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

nvm, bundle car is no longer needed once #3276 is merged

Copy link
Member

@LesnyRumcajs LesnyRumcajs left a comment

Choose a reason for hiding this comment

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

Adding subcommand tests, at least for the happy path, would be great.

@lemmih
Copy link
Contributor Author

lemmih commented Jul 31, 2023

Adding subcommand tests, at least for the happy path, would be great.

I can add smoke tests once the --diff PR is merged.

@LesnyRumcajs
Copy link
Member

Adding subcommand tests, at least for the happy path, would be great.

I can add smoke tests once the --diff PR is merged.

What's preventing us from doing a test without the --diff?

@lemmih
Copy link
Contributor Author

lemmih commented Jul 31, 2023

Adding subcommand tests, at least for the happy path, would be great.

I can add smoke tests once the --diff PR is merged.

What's preventing us from doing a test without the --diff?

I don't have two CAR files to merge. :)

The primary use case for ManyCar is to merge a base snapshot and a set of diffs into a single, coherent block store. Without the --diff command, I'm not sure how to test it (other than the unit tests).

@lemmih
Copy link
Contributor Author

lemmih commented Jul 31, 2023

Adding subcommand tests, at least for the happy path, would be great.

Done. Happy path tested.

@LesnyRumcajs
Copy link
Member

@lemmih
Copy link
Contributor Author

lemmih commented Jul 31, 2023

@lemmih Sadly, the happy path is not so happy. https://github.com/ChainSafe/forest/actions/runs/5712759803/job/15477232048?pr=3288

See!? This is why we should never add any tests! :P

Comment on lines +193 to +194
// Frame cache hit, no value. This only happens when hashes collide
Some(None) => {}
Copy link
Member

Choose a reason for hiding this comment

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

Do we expect hash collisions? If not, should we panic here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hash collisions may occur, and it costs us little to handle them correctly. If two CIDs have the same hash, the index returns two possible positions. We check the second position if we don't find the correct CID at the first position.

@lemmih lemmih added this pull request to the merge queue Jul 31, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jul 31, 2023
@LesnyRumcajs LesnyRumcajs added this pull request to the merge queue Jul 31, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jul 31, 2023
@lemmih lemmih added this pull request to the merge queue Jul 31, 2023
Merged via the queue into main with commit 4edc2e4 Jul 31, 2023
@lemmih lemmih deleted the lemmih/many-car branch July 31, 2023 12:48
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