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

opt: farmer cache flatten piece_caches #2925

Merged
merged 5 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ use std::future::{ready, Future};
use std::pin::{pin, Pin};
use std::sync::Arc;
use std::time::{Duration, Instant};
use subspace_farmer::cluster::cache::{ClusterCacheIdentifyBroadcast, ClusterPieceCache};
use subspace_farmer::cluster::cache::{
ClusterCacheIdentifyBroadcast, ClusterCacheIndex, ClusterPieceCache,
};
use subspace_farmer::cluster::controller::ClusterControllerCacheIdentifyBroadcast;
use subspace_farmer::cluster::nats_client::NatsClient;
use subspace_farmer::farm::{PieceCache, PieceCacheId};
Expand Down Expand Up @@ -86,7 +88,7 @@ impl KnownCaches {
pub(super) async fn maintain_caches(
cache_group: &str,
nats_client: &NatsClient,
farmer_cache: FarmerCache,
farmer_cache: FarmerCache<ClusterCacheIndex>,
) -> anyhow::Result<()> {
let mut known_caches = KnownCaches::default();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ const GET_PIECE_MAX_INTERVAL: Duration = Duration::from_secs(40);
const MAX_SPACE_PLEDGED_FOR_PLOT_CACHE_ON_WINDOWS: u64 = 7 * 1024 * 1024 * 1024 * 1024;
const FARM_ERROR_PRINT_INTERVAL: Duration = Duration::from_secs(30);

type CacheIndex = u8;

/// Arguments for farmer
#[derive(Debug, Parser)]
pub(crate) struct FarmingArgs {
Expand Down Expand Up @@ -342,7 +344,7 @@ where
let should_start_prometheus_server = !prometheus_listen_on.is_empty();

let (farmer_cache, farmer_cache_worker) =
FarmerCache::new(node_client.clone(), peer_id, Some(&mut registry));
FarmerCache::<CacheIndex>::new(node_client.clone(), peer_id, Some(&mut registry));

let node_client = CachingProxyNodeClient::new(node_client)
.await
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ pub(in super::super) struct NetworkArgs {
}

#[allow(clippy::too_many_arguments)]
pub(in super::super) fn configure_network<FarmIndex, NC>(
pub(in super::super) fn configure_network<FarmIndex, CacheIndex, NC>(
protocol_prefix: String,
base_path: &Path,
keypair: Keypair,
Expand All @@ -87,12 +87,15 @@ pub(in super::super) fn configure_network<FarmIndex, NC>(
}: NetworkArgs,
weak_plotted_pieces: Weak<AsyncRwLock<PlottedPieces<FarmIndex>>>,
node_client: NC,
farmer_cache: FarmerCache,
farmer_cache: FarmerCache<CacheIndex>,
prometheus_metrics_registry: Option<&mut Registry>,
) -> Result<(Node, NodeRunner<FarmerCache>), anyhow::Error>
) -> Result<(Node, NodeRunner<FarmerCache<CacheIndex>>), anyhow::Error>
where
FarmIndex: Hash + Eq + Copy + fmt::Debug + Send + Sync + 'static,
usize: From<FarmIndex>,
CacheIndex: Hash + Eq + Copy + fmt::Debug + fmt::Display + Send + Sync + 'static,
usize: From<CacheIndex>,
CacheIndex: TryFrom<usize>,
NC: NodeClientExt + Clone,
{
let known_peers_registry = KnownPeersManager::new(KnownPeersManagerConfig {
Expand Down
3 changes: 3 additions & 0 deletions crates/subspace-farmer/src/cluster/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ use tracing::{debug, error, info, trace, warn};

const MIN_CACHE_IDENTIFICATION_INTERVAL: Duration = Duration::from_secs(1);

/// Type alias for cache index used by cluster.
pub type ClusterCacheIndex = u16;

/// Broadcast with identification details by caches
#[derive(Debug, Clone, Encode, Decode)]
pub struct ClusterCacheIdentifyBroadcast {
Expand Down
6 changes: 3 additions & 3 deletions crates/subspace-farmer/src/cluster/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//! client implementations designed to work with cluster controller and a service function to drive
//! the backend part of the controller.

use crate::cluster::cache::ClusterCacheReadPieceRequest;
use crate::cluster::cache::{ClusterCacheIndex, ClusterCacheReadPieceRequest};
use crate::cluster::nats_client::{
GenericBroadcast, GenericNotification, GenericRequest, NatsClient,
};
Expand Down Expand Up @@ -435,7 +435,7 @@ pub async fn controller_service<NC, PG>(
nats_client: &NatsClient,
node_client: &NC,
piece_getter: &PG,
farmer_cache: &FarmerCache,
farmer_cache: &FarmerCache<ClusterCacheIndex>,
instance: &str,
primary_instance: bool,
) -> anyhow::Result<()>
Expand Down Expand Up @@ -721,7 +721,7 @@ where

async fn find_piece_responder(
nats_client: &NatsClient,
farmer_cache: &FarmerCache,
farmer_cache: &FarmerCache<ClusterCacheIndex>,
) -> anyhow::Result<()> {
nats_client
.request_responder(
Expand Down
Loading
Loading