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 --halt-after-import flag to CLI #1835

Merged
merged 12 commits into from
Aug 23, 2022
Merged

Conversation

connormullett
Copy link
Contributor

@connormullett connormullett commented Aug 17, 2022

Summary of changes
Changes introduced in this pull request:

  • Add ability to import a snapshot and immediately exit after completion
  • Small improvements to RocksDb configuration ergonomics with set_auto_disable_compactions
  • Add log level from string for RocksDb for testing and debugging purposes

Reference issue to close (if applicable)

Closes #1834

Other information and links

@@ -23,6 +23,7 @@ pub struct Client {
pub snapshot: bool,
pub snapshot_height: Option<i64>,
pub snapshot_path: Option<String>,
pub exit_after_import: bool,
Copy link
Contributor

Choose a reason for hiding this comment

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

Would be great to use the same wording as in Lotus which is --halt-after-import.

https://lotus.filecoin.io/lotus/manage/chain-management/#restoring-a-custom-snapshot

Most of Forest cli args are already similar to theirs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, I didn't know this was a thing. I'll rename it

@connormullett connormullett marked this pull request as ready for review August 18, 2022 15:31
@lemmih lemmih changed the title Add --import-snapshot-and-exit flag to CLI Add --halt-after-import flag to CLI Aug 19, 2022

if config.client.halt_after_import {
info!("Forest finish shutdown");
process::exit(0);
Copy link
Contributor

Choose a reason for hiding this comment

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

@elmattic Do you think it'll cause problems with RocksDB if we call exit(0) here? Do we need to properly shutdown the database?

Copy link
Contributor

@elmattic elmattic Aug 19, 2022

Choose a reason for hiding this comment

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

Sure we should avoid this and this is possible to do (from my experience, the main source of resource leaks are situated after the import).

But more problematic with this PR is that the code exits before import_chain in case of user --halt-after-importing, resulting in a no-op. We need to do it after the import_chain.

Plus we also need to run this code:

   match chain_store.heaviest_tipset().await { ...

This is for checking that the user is not importing too old snapshots.

If you do it just after:

    // Halt
    if config.client.halt_after_import {
        info!("Forest finished import");
        return;
    }

this should terminate forest properly. Also make sure you check rocksdb LOG file to verify that it closed properly the db (you need to enable rocksdb debug log level).

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 we could also promote this log debug!("Imported snapshot in: {}s", ... to an info! one.

This is useful information to know for troubleshooting, and it won't really bloat our logs.

@@ -143,6 +143,8 @@ pub struct CliOpts {
pub height: Option<i64>,
#[structopt(long, help = "Import a snapshot from a local CAR file or url")]
pub import_snapshot: Option<String>,
#[structopt(long)]
pub halt_after_import: bool,
Copy link
Contributor

@elmattic elmattic Aug 19, 2022

Choose a reason for hiding this comment

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

Please add some doc comment help for this new flag. Consider refactoring to use doc comments for the other flags too (this will gives us documentation like IDE tooltip and spell checking for free).

Copy link
Contributor

@elmattic elmattic Aug 19, 2022

Choose a reason for hiding this comment

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

@lemmih do you think such self-describing flags need help comments?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes. The help message could even add more details such as "Halt with exit code 0 after successfully importing a snapshot".

@@ -143,6 +143,11 @@ pub struct CliOpts {
pub height: Option<i64>,
#[structopt(long, help = "Import a snapshot from a local CAR file or url")]
pub import_snapshot: Option<String>,
#[structopt(
long,
help = "Halt with exit code 0 after successfully importing a snapshot"
Copy link
Contributor

Choose a reason for hiding this comment

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

You can put this into a doc comment like this:

/// Halt with exit code 0 after successfully importing a snapshot
#[structopt(long)]
pub halt_after_import: bool,

compression_type: Some("lz4".into()),
enable_statistics: false,
log_level: "debug".into(),
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't activate debug log by default here. What do you think of warn?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That makes more sense for a default, yeah

Comment on lines +45 to +47
db_opts.set_disable_auto_compactions(false);
} else {
db_opts.set_disable_auto_compactions(true);
Copy link
Contributor

Choose a reason for hiding this comment

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

This appears to be unrelated to the --halt-after-import flag. Could you explain the RocksDB changes in the PR description?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right, this was part of testing to see if RocksDb was being dropped after import. I've left some of the configuration logic in as it was part of @elmattic 's work

Copy link
Contributor

@lemmih lemmih left a comment

Choose a reason for hiding this comment

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

Tentative approval. The RocksDB changes are probably fine but I think they're unrelated to the original goal of this PR. Please describe what you've changed and why in the PR description.

@connormullett connormullett merged commit 314baef into main Aug 23, 2022
@connormullett connormullett deleted the connor/import-and-exit-flag branch August 23, 2022 16:51
tyshko5 pushed a commit that referenced this pull request Sep 7, 2022
* add flag to cliopts

* and options to config

* move exit logig to sync_from_snapshot

* rename to match lotus cli

* changes for testing; move halt to after import chain

* verify that rocksdb is dropped

* requested changes and remove testing logs

* move comment

* default rocks log level debug -> warn

* fix workflow errors
tyshko5 pushed a commit that referenced this pull request Sep 7, 2022
* add flag to cliopts

* and options to config

* move exit logig to sync_from_snapshot

* rename to match lotus cli

* changes for testing; move halt to after import chain

* verify that rocksdb is dropped

* requested changes and remove testing logs

* move comment

* default rocks log level debug -> warn

* fix workflow errors
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.

Add flag for exiting immediately after a snapshot has been imported.
4 participants