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

re-factor: cleanup snapshot config usage #4629

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

JoeySlomowitz
Copy link

Problem

Cleanup task was requested on the old repo here

Summary of Changes

This does a lot of renaming.

Replaced SnapshotConfig struct with SnapshotMode enum, and included more relevant associated types, following the suggestions put forward in the original issue

@mergify mergify bot requested a review from a team January 25, 2025 09:09
Copy link

mergify bot commented Jan 25, 2025

If this PR represents a change to the public RPC API:

  1. Make sure it includes a complementary update to rpc-client/ (example)
  2. Open a follow-up PR to update the JavaScript client @solana/web3.js (example)

Thank you for keeping the RPC clients in sync with the server API @JoeySlomowitz.

@JoeySlomowitz JoeySlomowitz force-pushed the cleanup-snapshot-config-usage branch 6 times, most recently from bcfd6b2 to 41ff77c Compare January 25, 2025 12:31
resolve call sites

more cleanup

fix up tests

cleanup

more cleanup

fix compile issue

fix waring

minor cleanup
@JoeySlomowitz JoeySlomowitz force-pushed the cleanup-snapshot-config-usage branch from 41ff77c to 7ba47c0 Compare January 25, 2025 12:38
@alexpyattaev
Copy link

This is a good initiative, thank you. However, to keep this from exploding out of proportion (and getting pretty difficult to test), I suggest you split this PR into two:

  1. Introduce the SnapshotMode and its associated structs.
  2. Integrate the new SnapshotMode enum into agave.

Choose a reason for hiding this comment

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

Not sure what the benefit of renaming the file is.

Copy link
Author

@JoeySlomowitz JoeySlomowitz Jan 25, 2025

Choose a reason for hiding this comment

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

Thanks @alexpyattaev after changing the config struct over to an enum and renaming, snapshot_config felt like a legacy namespace and out of place. I agree there's no huge benefit here, happy to revert if you disagree.

Choose a reason for hiding this comment

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

The main issue with renaming files is that it breaks tools like git blame. But I guess since this is a complete rewrite it does not matter much.

pub archives_to_retain: NonZeroUsize,
}

impl SnapshotStorageConfig {
Copy link

@alexpyattaev alexpyattaev Jan 25, 2025

Choose a reason for hiding this comment

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

does it make sense to have archives_dir empty? If not, these defaults are not really initializing a valid instance. If yes, it would make sense to document what it means.

renice_this_thread(
snapshot_mode
.get_snapshot_generate_config()
.unwrap()
Copy link

@alexpyattaev alexpyattaev Jan 25, 2025

Choose a reason for hiding this comment

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

This unwrap here will likely blow up in the worst possible way. If you are sure this can not happen, use .expect(), otherwise a better way would be to exit the thread and report something like error!("wrong snapshot config") .

snapshot_config.maximum_full_snapshot_archives_to_retain,
snapshot_config.maximum_incremental_snapshot_archives_to_retain,
&snapshot_load_config.full_snapshot_config.archives_dir,
&incremental_snapshot_config.archives_dir, // FIXME: Should this param be optional too?

Choose a reason for hiding this comment

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

probably you can split the function into two. One for full, and one for incremental snapshots. In a separate PR.

snapshot_mode
.get_snapshot_load_config()
.incremental_snapshot_config
.unwrap()

Choose a reason for hiding this comment

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

this unwrap can explode. need a better way / proof this can never explode.

Comment on lines +93 to +102
pub struct SnapshotLoadOnlyModeConfig {
pub load_config: SnapshotLoadConfig,
}

#[derive(Debug, Clone, Eq, PartialEq)]
pub struct SnapshotLoadAndGenerateModeConfig {
pub load_config: SnapshotLoadConfig,
pub generate_config: SnapshotGenerateConfig,
}

Choose a reason for hiding this comment

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

Since these structs only have a couple of fields, you can probably inline them into SnapshotMode enum to improve readability.

Copy link
Author

@JoeySlomowitz JoeySlomowitz Jan 26, 2025

Choose a reason for hiding this comment

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

thank @alexpyattaev just to confirm, do you mean defining it as a tuple like the following?;

pub enum SnapshotMode {
    Disabled,
    LoadOnly(SnapshotLoadOnlyModeConfig),
    LoadAndGenerate(SnapshotLoadConfig, SnapshotGenerateConfig),
}

Copy link

@alexpyattaev alexpyattaev Jan 26, 2025

Choose a reason for hiding this comment

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

You can go further with

pub enum SnapshotMode {
    Disabled,
    Load(SnapshotLoadConfig),
    LoadAndGenerate{load:SnapshotLoadConfig, generate:SnapshotGenerateConfig},
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants