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

Snapshots #2993

Merged
merged 660 commits into from
Oct 31, 2023
Merged

Snapshots #2993

merged 660 commits into from
Oct 31, 2023

Conversation

ricab
Copy link
Collaborator

@ricab ricab commented Mar 28, 2023

Fixes #208

@ricab ricab added the no-merge label Mar 28, 2023
@ricab
Copy link
Collaborator Author

ricab commented Mar 28, 2023

@sharder996 Opening this so that we get CI and packages to test, at least with the stuff we already merged.

I updated this branch to be on top of the daemon refactor (this needs to wait for that to be merged).

@codecov
Copy link

codecov bot commented Mar 28, 2023

Codecov Report

Merging #2993 (2f856e5) into main (9740dfd) will decrease coverage by 4.46%.
The diff coverage is 57.06%.

@@            Coverage Diff             @@
##             main    #2993      +/-   ##
==========================================
- Coverage   88.48%   84.03%   -4.46%     
==========================================
  Files         240      250      +10     
  Lines       12171    13464    +1293     
==========================================
+ Hits        10770    11315     +545     
- Misses       1401     2149     +748     
Files Coverage Δ
include/multipass/cli/format_utils.h 100.00% <100.00%> (ø)
.../multipass/exceptions/file_open_failed_exception.h 100.00% <100.00%> (ø)
include/multipass/snapshot.h 100.00% <100.00%> (ø)
include/multipass/virtual_machine_factory.h 100.00% <ø> (ø)
include/multipass/vm_image_vault.h 100.00% <ø> (ø)
src/client/cli/client.cpp 100.00% <100.00%> (ø)
src/client/cli/cmd/alias.cpp 100.00% <100.00%> (ø)
src/client/cli/cmd/delete.h 100.00% <ø> (ø)
src/client/cli/cmd/exec.cpp 100.00% <100.00%> (ø)
src/client/cli/cmd/list.cpp 97.50% <100.00%> (+0.35%) ⬆️
... and 53 more

@bors bors bot changed the base branch from daemon-refactor-instance-selection to main May 9, 2023 19:37
@ricab ricab force-pushed the snapshots branch 2 times, most recently from 1cf8855 to 8e55166 Compare May 30, 2023 13:19
@ricab ricab force-pushed the snapshots branch 2 times, most recently from a30ab9b to 9e749f9 Compare June 28, 2023 18:31
@townsend2010 townsend2010 linked an issue Oct 6, 2023 that may be closed by this pull request
@ricab ricab marked this pull request as ready for review October 17, 2023 17:46
@ricab ricab marked this pull request as draft October 17, 2023 18:03
Copy link
Contributor

@townsend2010 townsend2010 left a comment

Choose a reason for hiding this comment

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

Hey @ricab and @sharder996!

This is one BIG PR! Holy cow!!! Considering the absolute size of this, this is looking good overall. Although I spent the better part of Friday and today reviewing this, it is not complete. I have not reviewed the following files:

  • The bash completions
  • info.cpp
  • All the formatters
  • base_snapshot.*
  • base_virtual_machine.*
  • And some of the test changes.

I'm waiting on reviewing info and the formatters since I'd like to review in conjunction with the latest snap package which hasn't built as of this writing.

Also, even though I've spent a number of hours reviewing this, I would call what I've done so far a fairly complete review, but not a fined toothed comb type of review 💦

include/multipass/cli/format_utils.h Show resolved Hide resolved
include/multipass/cli/format_utils.h Show resolved Hide resolved
include/multipass/cli/format_utils.h Show resolved Hide resolved
include/multipass/exceptions/snapshot_exceptions.h Outdated Show resolved Hide resolved
include/multipass/exceptions/snapshot_exceptions.h Outdated Show resolved Hide resolved
src/daemon/daemon.cpp Outdated Show resolved Hide resolved
src/daemon/daemon.cpp Show resolved Hide resolved
src/daemon/daemon.cpp Outdated Show resolved Hide resolved
src/daemon/daemon.cpp Show resolved Hide resolved
src/daemon/daemon.cpp Show resolved Hide resolved
@ricab
Copy link
Collaborator Author

ricab commented Oct 24, 2023

I am going to reply to items individually, but I acknowledge this must be very difficult to go through and I just want to thank you for the review to begin with 🌟 👏

@ricab
Copy link
Collaborator Author

ricab commented Oct 24, 2023

@townsend2010, I think I have addressed all the items I said I would. Others I am waiting feedback on. Please let me know if I missed anything.

Comment on lines +138 to +149
bool cmd::Restore::confirm_destruction(const std::string& instance_name)
{
static constexpr auto prompt_text =
"Do you want to take a snapshot of {} before discarding its current state? (Yes/no)";
static constexpr auto invalid_input = "Please answer Yes/no";
mp::PlainPrompter prompter(term);

auto answer = prompter.prompt(fmt::format(prompt_text, instance_name));
while (!answer.empty() && !std::regex_match(answer, yes_answer) && !std::regex_match(answer, no_answer))
answer = prompter.prompt(invalid_input);

return std::regex_match(answer, no_answer);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Nothing needs to be done at this moment, but this is quite similar to the code in launch for it's prompt around asking for permission to create the bridge. I know @luis4a0 had done some refactoring in #3195, so we'll just need to consider how we may be able to refactor some of this once this PR is merged.

@ricab ricab force-pushed the snapshots branch 2 times, most recently from ef4a85e to 8b3c7a6 Compare October 25, 2023 18:20
Copy link
Contributor

@townsend2010 townsend2010 left a comment

Choose a reason for hiding this comment

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

We are getting really close 😅 Just a couple of inline things below.

Also, I'm still reviewing delete and restore, but wanted to go ahead and get this quick feedback out.

include/multipass/vm_specs.h Show resolved Hide resolved
src/platform/backends/shared/base_snapshot.cpp Outdated Show resolved Hide resolved
townsend2010
townsend2010 previously approved these changes Oct 26, 2023
Copy link
Contributor

@townsend2010 townsend2010 left a comment

Choose a reason for hiding this comment

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

Hey @ricab and @sharder996!

I'm good with in it's current state and approving! Let's wait for feedback from @andrei-toterman before merging.

Copy link
Contributor

@andrei-toterman andrei-toterman left a comment

Choose a reason for hiding this comment

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

Just a few small remarks :)

src/platform/backends/shared/base_virtual_machine.h Outdated Show resolved Hide resolved
Comment on lines 65 to 68
std::string trim(const std::string& s)
{
return std::regex_replace(s, std::regex{R"(^\s+|\s+$)"}, "");
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this would be useful as part of utils. Also, maybe declaring the regex as static inside this function would be a little more efficient, as it wouldn't have to parse and compile it from scratch on every invocation.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yup. Both improvements coming.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

For this one I ended up falling into a bit of a rabbit hole. I saw that there was already a trim_end that was able to trim in place. I thought I'd better be consistent, reuse it, and avoid copying strings (which is nice on full file contents...). So I dropped the regex approach entirely. From there, it bugged me that I could not use the new utils with rvalues and went on to generalize those trimmers with templates, but I wanted to be careful to avoid any dangling refs or other pitfalls (I wouldn't mind another pair of attentive eyes on that code, just to be sure). The templates also allowed me to easily drop the std::function wrappers. Please let me know if you're good with it.

Copy link
Contributor

Choose a reason for hiding this comment

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

First, one little mistake here

template <typename Str, typename Filter>
Str&& multipass::utils::trim(Str&& s, Filter&& filter)
{
    return trim_begin(trim_end(std::forward<Str>(s), std::forward<Filter>(filter)));
}

I think filter should be passed to both trim_begin and trim_end. Now it is passed only to trim_end and trim_begin will always use is_space.

Also, there is one minuscule detail about

inline constexpr auto is_space = static_cast<int (*)(int)>(std::isspace);

since the docs say that it's 'wrong' to use static_cast<int (*)(int)>(std::isspace) when using it on std::string and it should be instead used as [](unsigned char c){ return std::isspace(c); }. I'm not really sure if this matters much, but I'd like to hear your opinion as well.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ahh, I knew I needed you to have a look. Fixes coming.

src/platform/backends/shared/base_snapshot.h Outdated Show resolved Hide resolved
include/multipass/exceptions/file_not_found_exception.h Outdated Show resolved Hide resolved
@ricab ricab marked this pull request as ready for review October 27, 2023 23:07
ricab added 10 commits October 30, 2023 14:49
Store the (now immutable) ID string in a snapshot field and provide an
accessor to it, rather than deriving it each time it is needed. Adapt
client code accordingly.
Move throwing default implementation of `make_specific_snapshot`
overloads to the base VM class.
Generalize trim utilities to operate on both lvalues and rvalues. Take
the chance to drop the `std::function` wrapper for the filter predicate.
@townsend2010
Copy link
Contributor

Manual integration test is running at https://github.com/canonical/multipass/actions/runs/6697249710.

Copy link
Contributor

@townsend2010 townsend2010 left a comment

Choose a reason for hiding this comment

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

Ok, integration tests passed and I'm final approving this. Let's merge this ASAP!

🚀 🎉 🍾 🥳

@townsend2010
Copy link
Contributor

This will fail, but want to get the commit message...

bors merge

@bors
Copy link
Contributor

bors bot commented Oct 31, 2023

👎 Rejected by label

@townsend2010
Copy link
Contributor

Try again...

bors merge

bors bot added a commit that referenced this pull request Oct 31, 2023
2993: Snapshots r=townsend2010 a=ricab

Fixes #208

Co-authored-by: Ricardo Abreu <[email protected]>
Co-authored-by: ScottH <[email protected]>
@townsend2010 townsend2010 reopened this Oct 31, 2023
@townsend2010 townsend2010 merged commit 7e4dc40 into main Oct 31, 2023
28 of 30 checks passed
@bors bors bot deleted the snapshots branch October 31, 2023 07:34
@bors
Copy link
Contributor

bors bot commented Oct 31, 2023

This PR was included in a batch that successfully built, but then failed to merge into main (it was a non-fast-forward update). It will be automatically retried.

@ricab
Copy link
Collaborator Author

ricab commented Oct 31, 2023

bors cancel

@bors
Copy link
Contributor

bors bot commented Oct 31, 2023

Canceled.

luis4a0 pushed a commit that referenced this pull request Nov 7, 2023
2993: Snapshots r=townsend2010 a=ricab

Fixes #208

Co-authored-by: Ricardo Abreu <[email protected]>
Co-authored-by: ScottH <[email protected]>
luis4a0 pushed a commit that referenced this pull request Nov 7, 2023
2993: Snapshots r=townsend2010 a=ricab

Fixes #208

Co-authored-by: Ricardo Abreu <[email protected]>
Co-authored-by: ScottH <[email protected]>
luis4a0 pushed a commit that referenced this pull request Nov 8, 2023
2993: Snapshots r=townsend2010 a=ricab

Fixes #208

Co-authored-by: Ricardo Abreu <[email protected]>
Co-authored-by: ScottH <[email protected]>
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.

support for snapshots/backups
5 participants