Skip to content

Commit

Permalink
fix(backend): Retireable versions should not include actively used ve…
Browse files Browse the repository at this point in the history
…rsions
  • Loading branch information
sasa-tomic committed Jun 13, 2023
1 parent bf0a14a commit 2cf0f98
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions rs/ic-management-backend/src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use ic_management_types::{
Datacenter, DatacenterOwner, Guest, Network, NetworkError, Node, NodeProviderDetails, Operator, Provider,
ReplicaRelease, Subnet, SubnetMetadata,
};
use ic_protobuf::registry::unassigned_nodes_config::v1::UnassignedNodesConfigRecord;
use ic_registry_keys::{
make_blessed_replica_versions_key, NODE_OPERATOR_RECORD_KEY_PREFIX, NODE_RECORD_KEY_PREFIX,
SUBNET_RECORD_KEY_PREFIX,
Expand Down Expand Up @@ -544,21 +545,24 @@ impl RegistryState {
}

pub async fn retireable_versions(&self) -> Result<Vec<ReplicaRelease>> {
const ACTIVE_RELEASES: usize = 2;
const NUM_RELEASE_BRANCHES_TO_KEEP: usize = 2;
let active_releases = self
.replica_releases
.clone()
.into_iter()
.rev()
.map(|rr| rr.branch)
.unique()
.take(ACTIVE_RELEASES)
.take(NUM_RELEASE_BRANCHES_TO_KEEP)
.collect::<Vec<_>>();
let subnet_versions: HashSet<String> = self.subnets.values().map(|s| s.replica_version.clone()).collect();
let version_on_unassigned_nodes = self.get_unassigned_nodes_version().await?;
Ok(self
.replica_releases
.clone()
.into_iter()
.filter(|rr| !active_releases.contains(&rr.branch))
.filter(|rr| !subnet_versions.contains(&rr.commit_hash) && rr.commit_hash != version_on_unassigned_nodes)
.collect())
}

Expand Down Expand Up @@ -594,6 +598,25 @@ impl RegistryState {
pub fn nns_url(&self) -> String {
self.nns_url.clone()
}

pub async fn get_unassigned_nodes_version(&self) -> Result<String, anyhow::Error> {
let unassigned_config_key = ic_registry_keys::make_unassigned_nodes_config_record_key();

match self
.local_registry
.get_value(&unassigned_config_key, self.local_registry.get_latest_version())
{
Ok(Some(bytes)) => {
let cfg = UnassignedNodesConfigRecord::decode(&bytes[..])
.expect("Error decoding UnassignedNodesConfigRecord from the LocalRegistry");

Ok(cfg.replica_version)
}
_ => Err(anyhow::anyhow!(
"No replica version for unassigned nodes found".to_string(),
)),
}
}
}

impl decentralization::network::TopologyManager for RegistryState {}
Expand Down

0 comments on commit 2cf0f98

Please sign in to comment.