Skip to content
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

Merged
merged 6 commits into from
May 9, 2023
Merged

Conversation

przydatek
Copy link
Collaborator

@przydatek przydatek commented May 8, 2023

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) for MemoryManager'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)

@przydatek przydatek marked this pull request as ready for review May 8, 2023 13:03
@przydatek przydatek changed the title GIX-1423: Adding storage migration to MemoryManager (v6 to v7) Add storage migration to MemoryManager (v6 to v7) May 8, 2023
src/internet_identity/src/storage.rs Outdated Show resolved Hide resolved
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();

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?

Copy link
Collaborator Author

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.

src/internet_identity/src/storage.rs Outdated Show resolved Hide resolved
src/internet_identity/src/storage.rs Show resolved Hide resolved
@@ -311,7 +338,9 @@ impl<M: Memory + Clone> Storage<M> {
header_memory,
anchor_memory,
maybe_memory_manager,
}
};
storage.flush();

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?

Copy link
Collaborator Author

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.

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 flushed later. Definitely a good change. 👍

.allocate_anchor()
.expect("Failure allocating an anchor.");
anchor
.add_device(sample_device())

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, done.

src/internet_identity/src/storage/tests.rs Show resolved Hide resolved
Copy link
Collaborator Author

@przydatek przydatek left a 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();
Copy link
Collaborator Author

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 Show resolved Hide resolved
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();
Copy link
Collaborator Author

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.

src/internet_identity/src/storage.rs Show resolved Hide resolved
src/internet_identity/src/storage/tests.rs Show resolved Hide resolved
.allocate_anchor()
.expect("Failure allocating an anchor.");
anchor
.add_device(sample_device())
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, done.

Copy link
Member

@frederikrothenberger frederikrothenberger left a 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();

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 flushed later. Definitely a good change. 👍

@przydatek przydatek added this pull request to the merge queue May 9, 2023
Merged via the queue into main with commit e7581c4 May 9, 2023
@przydatek przydatek deleted the bartosz/GIX-1423 branch May 9, 2023 08:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants