I have a data canister that uses the stable region of memory. I am using a StableBTreeMap
to store my assets by key & value pairs. When I use the Bound::Bounded
type and set the MAX_SIZE value, I am able to store more than 4GB of data in the canister. However, when I try to use the Bound::Unbounded
type, the canister stops storing new data when the canister state reaches 4GB and throws the following error:
"IC0503: Error from canister pmm6l-wiaaa-aaaae-aakfq-cai: Canister called `ic0.trap` with message: Used bytes limit reached 4001281850 >= 4000000000.\\\\nConsider gracefully handling errors from this canister or modifying the canister to handle exceptions. See documentation: http://internetcomputer.org/docs/current/references/execution-errors#trapped-explicitly\\\")', hugemap_index/src/helpers.rs:201:18.\\nConsider gracefully handling failures from this canister or modifying the canister to handle exceptions. See the documentation: http://internetcomputer.org/docs/current/references/execution-errors#trapped-explicitly\"
If I have to use the Bound::Bounded type to use the stable memory, I can always create new maps to store different sizes of values to not waste memory, but do I have to?
Here’s the the declaration of the corresponding struct:
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct ValStable(pub Vec<u8>);
impl Storable for ValStable {
const BOUND: ic_stable_structures::storable::Bound =
ic_stable_structures::storable::Bound::Unbounded;
fn to_bytes(&self) -> Cow<[u8]> {
Cow::Borrowed(&self.0)
}
fn from_bytes(bytes: Cow<[u8]>) -> Self {
ValStable(bytes.to_vec())
}
}
impl ValStable {
pub fn new(data: Vec<u8>) -> Self {
ValStable(data)
}
}
By the way, my canisters are deployed in the subnet: “shefu-t3kr5-t5q3w-mqmdq-jabyv-vyvtf-cyyey-3kmo4-toyln-emubw-4qe”. I added this detail in case the issue is related to the subnet where my canisters are deployed.