// Ensures that the subnet has enough memory capacity left to install the
// canister.
Ensures that the subnet has enough memory capacity left to install the
canister.
Ensures that the subnet has enough memory capacity left to install the canister .
fn validate_memory_allocation(
        &self,
        total_subnet_memory_taken: NumBytes,
        canister: &CanisterState,
        memory_allocation: Option<MemoryAllocation>,
    ) -> Result<(), CanisterManagerError> {
        if let Some(memory_allocation) = memory_allocation {
            if let MemoryAllocation::Reserved(requested_allocation) = memory_allocation {
                if requested_allocation < canister.memory_usage(self.config.own_subnet_type) {
                    return Err(CanisterManagerError::NotEnoughMemoryAllocationGiven {
                        canister_id: canister.canister_id(),
                        memory_allocation_given: memory_allocation,
                        memory_usage_needed: canister.memory_usage(self.config.own_subnet_type),
                    });
                }
            }
            let canister_current_allocation = match canister.memory_allocation() {
                MemoryAllocation::Reserved(bytes) => bytes,
                MemoryAllocation::BestEffort => canister.memory_usage(self.config.own_subnet_type),
            };
            if memory_allocation.bytes() + total_subnet_memory_taken - canister_current_allocation
                > self.config.subnet_memory_capacity
            {
                return Err(CanisterManagerError::SubnetMemoryCapacityOverSubscribed {
                    requested: memory_allocation.bytes(),
                    available: self.config.subnet_memory_capacity
                        - total_subnet_memory_taken
                        - canister_current_allocation,
                });
            }
        }
        Ok(())
    }
fn validate_memory_allocation ( & self , total_subnet_memory_taken : NumBytes , canister : & CanisterState , memory_allocation : Option < MemoryAllocation > , ) -> Result < ( ) , CanisterManagerError > { if let Some ( memory_allocation ) = memory_allocation { if let MemoryAllocation :: Reserved ( requested_allocation ) = memory_allocation { if requested_allocation < canister . memory_usage ( self . config . own_subnet_type ) { return Err ( CanisterManagerError :: NotEnoughMemoryAllocationGiven { canister_id : canister . canister_id ( ) , memory_allocation_given : memory_allocation , memory_usage_needed : canister . memory_usage ( self . config . own_subnet_type ) , } ) ; } } let canister_current_allocation = match canister . memory_allocation ( ) { MemoryAllocation :: Reserved ( bytes ) => bytes , MemoryAllocation :: BestEffort => canister . memory_usage ( self . config . own_subnet_type ) , } ; if memory_allocation . bytes ( ) + total_subnet_memory_taken - canister_current_allocation > self . config . subnet_memory_capacity { return Err ( CanisterManagerError :: SubnetMemoryCapacityOverSubscribed { requested : memory_allocation . bytes ( ) , available : self . config . subnet_memory_capacity - total_subnet_memory_taken - canister_current_allocation , } ) ; } } Ok ( ( ) ) }
Ensures that the subnet has enough memory capacity left to install the
canister.
Ensures that the subnet has enough memory capacity left to install the canister .
&self
total_subnet_memory_taken
NumBytes
canister
&CanisterState
memory_allocation
Option<MemoryAllocation>