Skip to content

Commit

Permalink
Merge pull request #2626 from subspace/farm-trait
Browse files Browse the repository at this point in the history
Farm trait
  • Loading branch information
nazar-pc authored Mar 19, 2024
2 parents 284b10c + 7d050c3 commit ddda10c
Show file tree
Hide file tree
Showing 21 changed files with 1,068 additions and 751 deletions.
294 changes: 139 additions & 155 deletions crates/subspace-farmer/src/bin/subspace-farmer/commands/farm.rs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ pub(super) fn configure_dsn(
}
};

plotted_pieces.read_piece(&piece_index)?.in_current_span()
plotted_pieces.read_piece(piece_index)?.in_current_span()
};

let piece = read_piece_fut.await;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ use std::fmt;
use std::sync::atomic::{AtomicI64, AtomicU64};
use std::time::Duration;
use subspace_core_primitives::SectorIndex;
use subspace_farmer::single_disk_farm::farming::ProvingResult;
use subspace_farmer::single_disk_farm::{FarmingError, SingleDiskFarmId};
use subspace_farmer::farm::{FarmId, FarmingError, ProvingResult};

#[derive(Debug, Copy, Clone)]
pub(super) enum SectorState {
Expand Down Expand Up @@ -228,68 +227,53 @@ impl FarmerMetrics {
}
}

pub(super) fn observe_auditing_time(
&self,
single_disk_farm_id: &SingleDiskFarmId,
time: &Duration,
) {
pub(super) fn observe_auditing_time(&self, farm_id: &FarmId, time: &Duration) {
self.auditing_time
.get_or_create(&vec![(
"farm_id".to_string(),
single_disk_farm_id.to_string(),
)])
.get_or_create(&vec![("farm_id".to_string(), farm_id.to_string())])
.observe(time.as_secs_f64());
}

pub(super) fn observe_proving_time(
&self,
single_disk_farm_id: &SingleDiskFarmId,
farm_id: &FarmId,
time: &Duration,
result: ProvingResult,
) {
self.proving_time
.get_or_create(&vec![
("farm_id".to_string(), single_disk_farm_id.to_string()),
("farm_id".to_string(), farm_id.to_string()),
("result".to_string(), result.to_string()),
])
.observe(time.as_secs_f64());
}

pub(super) fn note_farming_error(
&self,
single_disk_farm_id: &SingleDiskFarmId,
error: &FarmingError,
) {
pub(super) fn note_farming_error(&self, farm_id: &FarmId, error: &FarmingError) {
self.farming_errors
.get_or_create(&vec![
("farm_id".to_string(), single_disk_farm_id.to_string()),
("farm_id".to_string(), farm_id.to_string()),
("error".to_string(), error.str_variant().to_string()),
])
.inc();
}

pub(super) fn update_sectors_total(
&self,
single_disk_farm_id: &SingleDiskFarmId,
farm_id: &FarmId,
sectors: SectorIndex,
state: SectorState,
) {
self.sectors_total
.get_or_create(&vec![
("farm_id".to_string(), single_disk_farm_id.to_string()),
("farm_id".to_string(), farm_id.to_string()),
("state".to_string(), state.to_string()),
])
.set(i64::from(sectors));
}

pub(super) fn update_sector_state(
&self,
single_disk_farm_id: &SingleDiskFarmId,
state: SectorState,
) {
pub(super) fn update_sector_state(&self, farm_id: &FarmId, state: SectorState) {
self.sectors_total
.get_or_create(&vec![
("farm_id".to_string(), single_disk_farm_id.to_string()),
("farm_id".to_string(), farm_id.to_string()),
("state".to_string(), state.to_string()),
])
.inc();
Expand All @@ -302,7 +286,7 @@ impl FarmerMetrics {
// in deadlock otherwise
{
let not_plotted_sectors = self.sectors_total.get_or_create(&vec![
("farm_id".to_string(), single_disk_farm_id.to_string()),
("farm_id".to_string(), farm_id.to_string()),
("state".to_string(), SectorState::NotPlotted.to_string()),
]);
if not_plotted_sectors.get() > 0 {
Expand All @@ -313,7 +297,7 @@ impl FarmerMetrics {
}
{
let expired_sectors = self.sectors_total.get_or_create(&vec![
("farm_id".to_string(), single_disk_farm_id.to_string()),
("farm_id".to_string(), farm_id.to_string()),
("state".to_string(), SectorState::Expired.to_string()),
]);
if expired_sectors.get() > 0 {
Expand All @@ -325,71 +309,43 @@ impl FarmerMetrics {
// Replaced about to expire sector
self.sectors_total
.get_or_create(&vec![
("farm_id".to_string(), single_disk_farm_id.to_string()),
("farm_id".to_string(), farm_id.to_string()),
("state".to_string(), SectorState::AboutToExpire.to_string()),
])
.dec();
}
SectorState::AboutToExpire | SectorState::Expired => {
self.sectors_total
.get_or_create(&vec![
("farm_id".to_string(), single_disk_farm_id.to_string()),
("farm_id".to_string(), farm_id.to_string()),
("state".to_string(), SectorState::Plotted.to_string()),
])
.dec();
}
}
}

pub(super) fn observe_sector_downloading_time(
&self,
single_disk_farm_id: &SingleDiskFarmId,
time: &Duration,
) {
pub(super) fn observe_sector_downloading_time(&self, farm_id: &FarmId, time: &Duration) {
self.sector_downloading_time
.get_or_create(&vec![(
"farm_id".to_string(),
single_disk_farm_id.to_string(),
)])
.get_or_create(&vec![("farm_id".to_string(), farm_id.to_string())])
.observe(time.as_secs_f64());
}

pub(super) fn observe_sector_encoding_time(
&self,
single_disk_farm_id: &SingleDiskFarmId,
time: &Duration,
) {
pub(super) fn observe_sector_encoding_time(&self, farm_id: &FarmId, time: &Duration) {
self.sector_encoding_time
.get_or_create(&vec![(
"farm_id".to_string(),
single_disk_farm_id.to_string(),
)])
.get_or_create(&vec![("farm_id".to_string(), farm_id.to_string())])
.observe(time.as_secs_f64());
}

pub(super) fn observe_sector_writing_time(
&self,
single_disk_farm_id: &SingleDiskFarmId,
time: &Duration,
) {
pub(super) fn observe_sector_writing_time(&self, farm_id: &FarmId, time: &Duration) {
self.sector_writing_time
.get_or_create(&vec![(
"farm_id".to_string(),
single_disk_farm_id.to_string(),
)])
.get_or_create(&vec![("farm_id".to_string(), farm_id.to_string())])
.observe(time.as_secs_f64());
}

pub(super) fn observe_sector_plotting_time(
&self,
single_disk_farm_id: &SingleDiskFarmId,
time: &Duration,
) {
pub(super) fn observe_sector_plotting_time(&self, farm_id: &FarmId, time: &Duration) {
self.sector_plotting_time
.get_or_create(&vec![(
"farm_id".to_string(),
single_disk_farm_id.to_string(),
)])
.get_or_create(&vec![("farm_id".to_string(), farm_id.to_string())])
.observe(time.as_secs_f64());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ use crate::commands::shared::print_disk_farm_info;
use std::path::PathBuf;

pub(crate) fn info(disk_farms: Vec<PathBuf>) {
for (disk_farm_index, disk_farm) in disk_farms.into_iter().enumerate() {
if disk_farm_index > 0 {
for (farm_index, disk_farm) in disk_farms.into_iter().enumerate() {
if farm_index > 0 {
println!();
}

print_disk_farm_info(disk_farm, disk_farm_index);
print_disk_farm_info(disk_farm, farm_index);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ pub(crate) fn scrub(disk_farms: &[PathBuf], disable_farm_locking: bool) {
disk_farms
.into_par_iter()
.enumerate()
.for_each(|(disk_farm_index, directory)| {
let span = info_span!("", %disk_farm_index);
.for_each(|(farm_index, directory)| {
let span = info_span!("", %farm_index);
let _span_guard = span.enter();
info!(
path = %directory.display(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::path::PathBuf;
use subspace_farmer::single_disk_farm::{SingleDiskFarm, SingleDiskFarmSummary};

pub(crate) fn print_disk_farm_info(directory: PathBuf, disk_farm_index: usize) {
println!("Single disk farm {disk_farm_index}:");
pub(crate) fn print_disk_farm_info(directory: PathBuf, farm_index: usize) {
println!("Single disk farm {farm_index}:");
match SingleDiskFarm::collect_summary(directory) {
SingleDiskFarmSummary::Found { info, directory } => {
println!(" ID: {}", info.id());
Expand Down
Loading

0 comments on commit ddda10c

Please sign in to comment.