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

Refactor - LoadedPrograms::replenish() #35145

Merged

Conversation

Lichtso
Copy link
Contributor

@Lichtso Lichtso commented Feb 8, 2024

Problem

LoadedPrograms::replenish() was originally implemented to support deduplication of loaded entries when threads raced to load their TX batches. Now, with cooperative loading an entry should never be loaded twice.

Summary of Changes

  • Replaces all occurrences of LoadedPrograms::replenish() by LoadedPrograms::assign_program().
  • Disallows replacement of tombstone, but allows replacement of built-ins

@Lichtso Lichtso force-pushed the refactor/loaded_programs_replenish branch from e086bbd to 89c6c72 Compare February 8, 2024 14:34
Copy link

codecov bot commented Feb 8, 2024

Codecov Report

Attention: 1 lines in your changes are missing coverage. Please review.

Comparison is base (897adb2) 81.6% compared to head (964c410) 81.6%.

❗ Current head 964c410 differs from pull request most recent head 35f74c3. Consider uploading reports for the commit 35f74c3 to get more accurate results

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #35145   +/-   ##
=======================================
  Coverage    81.6%    81.6%           
=======================================
  Files         833      833           
  Lines      224827   224832    +5     
=======================================
+ Hits       183523   183545   +22     
+ Misses      41304    41287   -17     

@Lichtso Lichtso requested a review from pgarg66 February 8, 2024 22:23
@@ -712,7 +707,10 @@ impl<FG: ForkGraph> LoadedPrograms<FG> {
if existing.deployment_slot == entry.deployment_slot
&& existing.effective_slot == entry.effective_slot
{
if matches!(existing.program, LoadedProgramType::Unloaded(_)) {
if matches!(
Copy link
Contributor

Choose a reason for hiding this comment

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

instead of this, we should do

match existing.program {
    LoadedProgramType::Unloaded(_) | LoadedProgramType::Builtin(_) => {
        // The unloaded program is getting reloaded
        ...
    }
    LoadedProgramType::FailedVerification(_) => ...,
    LoadedProgramType::Closed,
    | LoadedProgramType::DelayVisibility
    | LoadedProgramType::LegacyV0(_)
    ... => ...

so we're forced to explicitly express the logic for each variant, which makes it harder to accidentally introduce bugs if the variants change/when the code is updated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This PR is to get us in sync with v1.17 again. Other refactorings can come later separately.

@Lichtso Lichtso force-pushed the refactor/loaded_programs_replenish branch from de86842 to 964c410 Compare February 13, 2024 13:36
@Lichtso Lichtso force-pushed the refactor/loaded_programs_replenish branch 2 times, most recently from 7774733 to 87705e1 Compare February 13, 2024 18:19
Copy link
Contributor

@alessandrod alessandrod left a comment

Choose a reason for hiding this comment

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

I'm approving this, even though I think that #35145 (comment) needs to be done. For the sake of making backporting easier, since we already have this change in 1.17, it makes sense to do that change separately.

}

#[test]
fn test_assign_program_tombstones() {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: a comment explaining what this tests would be great

assert!(cache.replenish(program1, new_test_loaded_program(20, 21)).0);
cache.assign_program(program1, new_test_loaded_program(0, 1));
cache.assign_program(program1, new_test_loaded_program(10, 11));
cache.assign_program(program1, new_test_loaded_program(20, 21));
Copy link
Contributor

Choose a reason for hiding this comment

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

we're not testing what happens when you insert same (deploy, effective) entry anymore?

}) {
Ok(index) => {
let existing = slot_versions.get_mut(index).unwrap();
if std::mem::discriminant(&existing.program)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it would be better to spell out the variants here, and debug_assert on
the invalid combinations. This currently accepts invalid pairs

@Lichtso Lichtso merged commit 716ad54 into solana-labs:master Feb 14, 2024
35 checks passed
@Lichtso Lichtso deleted the refactor/loaded_programs_replenish branch February 14, 2024 11:13
@Lichtso Lichtso added the v1.18 PRs that should be backported to v1.18 label Feb 14, 2024
Copy link
Contributor

mergify bot commented Feb 14, 2024

Backports to the beta branch are to be avoided unless absolutely necessary for fixing bugs, security issues, and perf regressions. Changes intended for backport should be structured such that a minimum effective diff can be committed separately from any refactoring, plumbing, cleanup, etc that are not strictly necessary to achieve the goal. Any of the latter should go only into master and ride the normal stabilization schedule. Exceptions include CI/metrics changes, CLI improvements and documentation updates on a case by case basis.

mergify bot pushed a commit that referenced this pull request Feb 14, 2024
* Replace LoadedPrograms::replenish() with LoadedPrograms::assign_program().

* Removes LoadedPrograms::replenish().

* Defines replacement by having the same loaded program type.

* Implements a proper insertion sort with a two key comparison operator.

(cherry picked from commit 716ad54)
Lichtso added a commit that referenced this pull request Feb 15, 2024
* Replace LoadedPrograms::replenish() with LoadedPrograms::assign_program().

* Removes LoadedPrograms::replenish().

* Defines replacement by having the same loaded program type.

* Implements a proper insertion sort with a two key comparison operator.

(cherry picked from commit 716ad54)
Lichtso added a commit that referenced this pull request Feb 15, 2024
* Replace LoadedPrograms::replenish() with LoadedPrograms::assign_program().

* Removes LoadedPrograms::replenish().

* Defines replacement by having the same loaded program type.

* Implements a proper insertion sort with a two key comparison operator.

(cherry picked from commit 716ad54)
alessandrod pushed a commit that referenced this pull request Feb 16, 2024
* Replace LoadedPrograms::replenish() with LoadedPrograms::assign_program().

* Removes LoadedPrograms::replenish().

* Defines replacement by having the same loaded program type.

* Implements a proper insertion sort with a two key comparison operator.

(cherry picked from commit 716ad54)
Lichtso added a commit that referenced this pull request Feb 16, 2024
…35197)

Refactor - `LoadedPrograms::replenish()` (#35145)

* Replace LoadedPrograms::replenish() with LoadedPrograms::assign_program().

* Removes LoadedPrograms::replenish().

* Defines replacement by having the same loaded program type.

* Implements a proper insertion sort with a two key comparison operator.

(cherry picked from commit 716ad54)

Co-authored-by: Alexander Meißner <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
v1.18 PRs that should be backported to v1.18
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants