-
Notifications
You must be signed in to change notification settings - Fork 161
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
Conversation
forest/src/cli/client.rs
Outdated
@@ -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, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
--halt-after-import
flag to CLI
forest/src/daemon.rs
Outdated
|
||
if config.client.halt_after_import { | ||
info!("Forest finish shutdown"); | ||
process::exit(0); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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-import
ing, 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).
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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".
forest/src/cli/mod.rs
Outdated
@@ -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" |
There was a problem hiding this comment.
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,
node/db/src/rocks_config.rs
Outdated
compression_type: Some("lz4".into()), | ||
enable_statistics: false, | ||
log_level: "debug".into(), |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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
db_opts.set_disable_auto_compactions(false); | ||
} else { | ||
db_opts.set_disable_auto_compactions(true); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this 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.
* 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
* 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
Summary of changes
Changes introduced in this pull request:
Reference issue to close (if applicable)
Closes #1834
Other information and links