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

Improve storage monitor API #2899

Merged
merged 5 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion polkadot/cli/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ where

sc_storage_monitor::StorageMonitorService::try_spawn(
cli.storage_monitor,
database_source,
database_source.path(),
&task_manager.spawn_essential_handle(),
)?;

Expand Down
2 changes: 1 addition & 1 deletion substrate/bin/node/cli/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,7 @@ pub fn new_full(config: Configuration, cli: Cli) -> Result<TaskManager, ServiceE

sc_storage_monitor::StorageMonitorService::try_spawn(
cli.storage_monitor,
database_source,
database_source.path(),
&task_manager.spawn_essential_handle(),
)
.map_err(|e| ServiceError::Application(e.into()))?;
Expand Down
1 change: 0 additions & 1 deletion substrate/client/storage-monitor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ workspace = true
clap = { version = "4.4.14", features = ["derive", "string"] }
log = "0.4.17"
fs4 = "0.7.0"
sc-client-db = { path = "../db", default-features = false }
sp-core = { path = "../../primitives/core" }
tokio = "1.22.0"
thiserror = "1.0.48"
10 changes: 5 additions & 5 deletions substrate/client/storage-monitor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use clap::Args;
use sc_client_db::DatabaseSource;
use sp_core::traits::SpawnEssentialNamed;
use std::{
io,
Expand Down Expand Up @@ -70,10 +69,10 @@ impl StorageMonitorService {
/// Creates new StorageMonitorService for given client config
pub fn try_spawn(
parameters: StorageMonitorParams,
database: DatabaseSource,
path: Option<&Path>,
Copy link
Contributor

@michalkucharczyk michalkucharczyk Jan 10, 2024

Choose a reason for hiding this comment

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

Option is not really needed here, could just be &Path.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, but then if/else needs to be checked at call site + there is logging that would need to be copied as well. I looked at that and decided to keep it an option.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hm.. None may not always mean/require logging, it could be handled in other way. And IMO handling None seems like part of caller responsibility.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah good point by @michalkucharczyk. We probably also don't need the logging at the caller side and just setup the service if there is a db path. @nazar-pc can you fix this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, done in last commit

Copy link
Member

Choose a reason for hiding this comment

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

Ty!

spawner: &impl SpawnEssentialNamed,
) -> Result<()> {
Ok(match (parameters.threshold, database.path()) {
Ok(match (parameters.threshold, path) {
(0, _) => {
log::info!(
target: LOG_TARGET,
Expand All @@ -89,10 +88,11 @@ impl StorageMonitorService {
(threshold, Some(path)) => {
log::debug!(
target: LOG_TARGET,
"Initializing StorageMonitorService for db path: {path:?}",
"Initializing StorageMonitorService for db path: {}",
path.display()
);

Self::check_free_space(&path, threshold)?;
Self::check_free_space(path, threshold)?;

let storage_monitor_service = StorageMonitorService {
path: path.to_path_buf(),
Expand Down
Loading