Data corrupt when using stable-structures, how to fixed the corrupt data

I am using stable-structures’s btreemap to store my datas.

When i want to get object from the btreemap, i get an panic and said the magic number is not match, left is [66, 84, 82] and right is [66, 84 ,78]. I skim the source code and see that the BTR is the header magic of btreemap, and the BTN is the header magic of node, so i think there maybe a data corrupt happened.

This is the process I think that make this thing happened:

  1. I declared the max_value_size to be 1024, and insert some data.
  2. I change the max_value_size to 2048, but when i upgrade the canister, that is an error message say that the max_value_size can not exists 1024.
  3. I change the max_value_size back to 1024, upgrade the canister again. then the magic number not match problem come up.

I have try the following method to solve the problem:

  1. I pull the stable-structures source code, an wanna to add some debug message with ic_cdk::println!, but it fail to compile

2.I call the stable64_size(), and call stable64_read() to read the whole data from stable storage, but see nothing relative to stable-structures, i didn’t see any magic number like BTR, BTC…

So what should I do next

2 Likes

Hi @nickcen, I tried the steps you explained but could not reproduce the issue you’re having. I think we may need to look at your exact code changes to see what could’ve happened during the upgrade, along with the version of stable-structures that you’re using.

1 Like