-
Notifications
You must be signed in to change notification settings - Fork 135
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
Add storage migration to MemoryManager (v6 to v7) #1566
Conversation
src/internet_identity/src/storage.rs
Outdated
pub fn from_memory_v6_to_v7(memory: M) -> Option<Self> { | ||
let maybe_storage_v6 = Self::from_memory(memory.clone()); | ||
maybe_storage_v6.as_ref()?; | ||
let storage_v6 = maybe_storage_v6.unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nicer to return None
on empty rather than panicking, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will not panic, due to the check on the previous line.
But I noticed now that both lines can be combined, so I did that, and hopefully it is more clear now. Also, I added a test for the case when maybe_storage_v6
is None
.
@@ -311,7 +338,9 @@ impl<M: Memory + Clone> Storage<M> { | |||
header_memory, | |||
anchor_memory, | |||
maybe_memory_manager, | |||
} | |||
}; | |||
storage.flush(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this flush now necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So that a new, empty storage (without any anchors) is properly initialised.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So up to now, the storage
was initialized only half-way and then flush
ed later. Definitely a good change. 👍
.allocate_anchor() | ||
.expect("Failure allocating an anchor."); | ||
anchor | ||
.add_device(sample_device()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to make the devices different (i.e. depend on the index) because this would detect mix-ups in the data.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea, done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the review @frederikrothenberger, PTAL.
@@ -311,7 +338,9 @@ impl<M: Memory + Clone> Storage<M> { | |||
header_memory, | |||
anchor_memory, | |||
maybe_memory_manager, | |||
} | |||
}; | |||
storage.flush(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So that a new, empty storage (without any anchors) is properly initialised.
src/internet_identity/src/storage.rs
Outdated
pub fn from_memory_v6_to_v7(memory: M) -> Option<Self> { | ||
let maybe_storage_v6 = Self::from_memory(memory.clone()); | ||
maybe_storage_v6.as_ref()?; | ||
let storage_v6 = maybe_storage_v6.unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will not panic, due to the check on the previous line.
But I noticed now that both lines can be combined, so I did that, and hopefully it is more clear now. Also, I added a test for the case when maybe_storage_v6
is None
.
.allocate_anchor() | ||
.expect("Failure allocating an anchor."); | ||
anchor | ||
.add_device(sample_device()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea, done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
@@ -311,7 +338,9 @@ impl<M: Memory + Clone> Storage<M> { | |||
header_memory, | |||
anchor_memory, | |||
maybe_memory_manager, | |||
} | |||
}; | |||
storage.flush(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So up to now, the storage
was initialized only half-way and then flush
ed later. Definitely a good change. 👍
Add functionality to migrate storage from v6 to v7, where v7 uses
ic_stable_structures::MemoryManager
. The migration does not copy the entire data, but rather uses 2nd page of the memory (which was unused/reserved so far) forMemoryManager
's metadata. The anchor-memory starts in both versions from the 3rd page.The migration is not enabled yet, and will be controlled by a flag added in a subsequent MR.
(GIX-1423)