Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
34577eb
service: storage monitor added
michalkucharczyk Jan 5, 2023
b5f970b
Merge remote-tracking branch 'origin/master' into mku-storage-monitor
michalkucharczyk Jan 6, 2023
37bbba4
Cargo.lock updated
michalkucharczyk Jan 6, 2023
ba0f28f
misspell
michalkucharczyk Jan 9, 2023
e360685
fs events throttling added
michalkucharczyk Jan 9, 2023
fd5679f
minor updates
michalkucharczyk Jan 9, 2023
217234f
filter out non mutating events
michalkucharczyk Jan 9, 2023
8b3310b
misspell
michalkucharczyk Jan 9, 2023
931339c
".git/.scripts/commands/fmt/fmt.sh"
Jan 10, 2023
c200159
Update client/service/src/storage_monitor.rs
michalkucharczyk Jan 12, 2023
f5501f2
storage-monitor crate added
michalkucharczyk Jan 13, 2023
45171dc
cleanup: configuration + service builder
michalkucharczyk Jan 13, 2023
f346394
storage_monitor in custom service (wip)
michalkucharczyk Jan 13, 2023
eb49400
copy-paste bad desc fixed
michalkucharczyk Jan 13, 2023
8619766
notify removed
michalkucharczyk Jan 16, 2023
a0cd44d
storage_monitor added to node
michalkucharczyk Jan 16, 2023
d3f143c
Merge remote-tracking branch 'origin/master' into mku-storage-monitor
Jan 16, 2023
a79af9a
fix for clippy
michalkucharczyk Jan 16, 2023
00e7264
publish = false
michalkucharczyk Jan 16, 2023
6c3eb1c
Update bin/node/cli/src/command.rs
michalkucharczyk Jan 17, 2023
58dcf55
Apply suggestions from code review
michalkucharczyk Jan 23, 2023
95b576b
crate name: storage-monitor -> sc-storage-monitor
michalkucharczyk Jan 23, 2023
0b8697e
error handling improved
michalkucharczyk Jan 23, 2023
c0fc2ca
Merge remote-tracking branch 'origin/master' into mku-storage-monitor
michalkucharczyk Jan 23, 2023
de35dda
Apply suggestions from code review
michalkucharczyk Jan 23, 2023
4e32f3d
publish=false removed
michalkucharczyk Jan 24, 2023
0578588
Merge remote-tracking branch 'origin/master' into mku-storage-monitor
Jan 24, 2023
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
Prev Previous commit
Next Next commit
Apply suggestions from code review
Co-authored-by: Bastian Köcher <git@kchr.de>
  • Loading branch information
michalkucharczyk and bkchr authored Jan 23, 2023
commit de35ddad9e1d9fe2c7cefc977d47c71b286cc8dc
15 changes: 4 additions & 11 deletions client/storage-monitor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use std::{

const LOG_TARGET: &str = "storage-monitor";

#[allow(missing_docs)]
/// Error type used in this crate.
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("IO Error")]
Expand All @@ -36,9 +36,6 @@ pub enum Error {
StorageOutOfSpace(u64, u64),
}

#[allow(missing_docs)]
pub type Result<T> = std::result::Result<T, Error>;

/// Parameters used to create the storage monitor.
#[derive(Default, Debug, Clone, Args)]
pub struct StorageMonitorParams {
Expand Down Expand Up @@ -69,7 +66,7 @@ impl StorageMonitorService {
parameters: StorageMonitorParams,
database: DatabaseSource,
spawner: &impl SpawnEssentialNamed,
) -> Result<()> {
) -> Result<(), Error> {
Ok(match (parameters.threshold, database.path()) {
(0, _) => {
log::info!(
Expand Down Expand Up @@ -119,7 +116,7 @@ impl StorageMonitorService {
}

/// Returns free space in MB, or error if statvfs failed.
fn free_space(path: &Path) -> Result<u64> {
fn free_space(path: &Path) -> Result<u64, Error> {
statvfs(path)
.map(|stats| stats.blocks_available() * stats.block_size() / 1_000_000)
.map_err(Error::from)
Expand All @@ -128,7 +125,7 @@ impl StorageMonitorService {
/// Checks if the amount of free space for given `path` is above given `threshold`.
/// If it dropped below, error is returned.
/// System errors are silently ignored.
fn check_free_space(path: &Path, threshold: u64) -> Result<()> {
fn check_free_space(path: &Path, threshold: u64) -> Result<(), Error> {
match StorageMonitorService::free_space(path) {
Ok(available_space) => {
log::trace!(
Expand All @@ -138,10 +135,6 @@ impl StorageMonitorService {

if available_space < threshold {
log::error!(target: LOG_TARGET, "Available space {available_space}MB for path `{}` dropped below threshold: {threshold}MB , terminating...", path.display());
println!(
"----> {:?}",
Error::StorageOutOfSpace(available_space, threshold).to_string()
);
Err(Error::StorageOutOfSpace(available_space, threshold))
} else {
Ok(())
Expand Down