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

[TieredStorage] Refactor TieredStorage::new_readonly() code path #195

Merged
merged 2 commits into from
Mar 20, 2024

Conversation

yhchiang-sol
Copy link

@yhchiang-sol yhchiang-sol commented Mar 11, 2024

Problem

The TieredStorage::new_readonly() function currently has the following
problems:

  • It opens the file without checking the magic number before checking and loading the footer.
  • It opens the file twice: first to load the footer, then open again by the reader.

Summary of Changes

This PR refactors TieredStorage::new_readonly() so that it first performs all
checks inside the constructor of TieredReadableFile. The TieredReadableFile
instance is then passed to the proper reader (currently HotStorageReader)
when all checks are passed.

Test Plan

  • Added a new test to check MagicNumberMismatch.
  • Existing tiered-storage tests

@codecov-commenter
Copy link

codecov-commenter commented Mar 12, 2024

Codecov Report

Attention: Patch coverage is 96.66667% with 2 lines in your changes are missing coverage. Please review.

Project coverage is 81.9%. Comparing base (184ba6c) to head (daf43bf).

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #195   +/-   ##
=======================================
  Coverage    81.9%    81.9%           
=======================================
  Files         837      837           
  Lines      226898   226932   +34     
=======================================
+ Hits       185871   185953   +82     
+ Misses      41027    40979   -48     

@yhchiang-sol yhchiang-sol marked this pull request as ready for review March 12, 2024 02:57
accounts-db/src/tiered_storage/hot.rs Outdated Show resolved Hide resolved
accounts-db/src/tiered_storage/file.rs Outdated Show resolved Hide resolved
accounts-db/src/tiered_storage/file.rs Outdated Show resolved Hide resolved
accounts-db/src/tiered_storage/file.rs Outdated Show resolved Hide resolved
@yhchiang-sol
Copy link
Author

The test failure doesn't seem related to the PR. Will rebase after the PR is fully reviewed.


git diff --check | 5m 11s
-- | --
  | Checking remote `origin` for updates to target branch `master`
  | ++git diff origin/master --check --oneline
  | .github/workflows/autolock_bot_PR.txt:26: trailing whitespace.
  | +
  | .github/workflows/autolock_bot_closed_issue.txt:26: trailing whitespace.
  | +
  | .github/workflows/solana-action.yml.txt:1: trailing whitespace.
  | +name : minimal
  | .github/workflows/solana-action.yml.txt:33: trailing whitespace.
  | +
  | .github/workflows/solana-action.yml.txt:41: trailing whitespace.
  | +
  | .github/workflows/solana-action.yml.txt:60: trailing whitespace.
  | +
  | .github/workflows/solana-action.yml.txt:64: trailing whitespace.
  | +      fail-fast: false
  | .github/workflows/solana-action.yml.txt:79: trailing whitespace.
  | +      - name: release artifact
  | .github/workflows/solana-action.yml.txt:87: trailing whitespace.
  | +#            choco install openssl
  | .github/workflows/solana-action.yml.txt:92: trailing whitespace.
  | +        uses: actions/checkout@v2
  | .github/workflows/solana-action.yml.txt:104: trailing whitespace.
  | +
  | .github/workflows/solana-action.yml.txt:113: trailing whitespace.
  | :# Received cancellation signal, interrupting
  | >^^^ +++


@yhchiang-sol
Copy link
Author

Rebase to address the unrelated CI failure.

accounts-db/src/tiered_storage/file.rs Outdated Show resolved Hide resolved
accounts-db/src/tiered_storage/file.rs Outdated Show resolved Hide resolved
accounts-db/src/tiered_storage/file.rs Outdated Show resolved Hide resolved
@yhchiang-sol
Copy link
Author

Squash and rebase to include recent tiered-storage PRs.

Copy link

@brooksprumo brooksprumo left a comment

Choose a reason for hiding this comment

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

looks good, just some nits

accounts-db/src/tiered_storage/file.rs Outdated Show resolved Hide resolved
accounts-db/src/tiered_storage/file.rs Outdated Show resolved Hide resolved
accounts-db/src/tiered_storage/file.rs Outdated Show resolved Hide resolved
Comment on lines 119 to 121
// This field is persisted in the storage but not in this struct.
// The number should match FOOTER_MAGIC_NUMBER.
// The number should match FILE_MAGIC_NUMBER.
// pub magic_number: u64,

Choose a reason for hiding this comment

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

IMO the magic number is not part of the footer. And thus this part can be removed. I know this'll cause other necessary changes, so no need to change anything in this PR. (And it's pretty low priority, so no need to address this immediately.)

Copy link
Author

Choose a reason for hiding this comment

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

Magic number is not part of the footer as it is commented out. The comment is to point out that there is one additional field after the footer (and the magic_number: u64 is also commented out). Maybe we can find a better place for this comment.

Choose a reason for hiding this comment

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

It's not part of the struct, but it is part of FOOTER_TAIL_SIZE, so we sometimes consider the magic number as part of the footer.

Copy link
Author

Choose a reason for hiding this comment

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

It's not part of the struct, but it is part of FOOTER_TAIL_SIZE, so we sometimes consider the magic number as part of the footer.

Aghh, got it. The concept of FOOTER_TAIL_SIZE is that the format of the last FOOTER_TAIL_SIZE bytes in any tiered-storage files will not change so that even if we have new versions of the footer that introduces new fields, we can still safely check the magic number and the format version. The tail also has a field describing the size of the footer.

Copy link

@brooksprumo brooksprumo left a comment

Choose a reason for hiding this comment

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

:shipit:

Comment on lines 119 to 121
// This field is persisted in the storage but not in this struct.
// The number should match FOOTER_MAGIC_NUMBER.
// The number should match FILE_MAGIC_NUMBER.
// pub magic_number: u64,

Choose a reason for hiding this comment

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

It's not part of the struct, but it is part of FOOTER_TAIL_SIZE, so we sometimes consider the magic number as part of the footer.

@yhchiang-sol yhchiang-sol merged commit 0e932c7 into anza-xyz:master Mar 20, 2024
32 of 37 checks passed
@yhchiang-sol yhchiang-sol deleted the ts-open-refactor branch March 20, 2024 17:39
codebender828 pushed a commit to codebender828/agave that referenced this pull request Oct 3, 2024
…a-xyz#195)

#### Problem
The TieredStorage::new_readonly() function currently has the following
problems:

* It opens the file without checking the magic number before checking and loading the footer.
* It opens the file twice: first to load the footer, then open again by the reader.

#### Summary of Changes
This PR refactors TieredStorage::new_readonly() so that it first performs all
checks inside the constructor of TieredReadableFile.  The TieredReadableFile
instance is then passed to the proper reader (currently HotStorageReader)
when all checks are passed.

#### Test Plan
* Added a new test to check MagicNumberMismatch.
* Existing tiered-storage tests
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