Skip to content

Make Versionize and serde_bincode compatible and split Versionize/Snapshot errors. #1720

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

Merged
merged 1 commit into from
Mar 31, 2020

Conversation

sandreim
Copy link
Contributor

Reason for This PR

Fixes #1718, #1707.

Description of Changes

Described in commit message.

  • This functionality can be added in rust-vmm.

License Acceptance

By submitting this pull request, I confirm that my contribution is made under
the terms of the Apache 2.0 license.

PR Checklist

[Author TODO: Meet these criteria.]
[Reviewer TODO: Verify that these criteria are met. Request changes if not]

  • All commits in this PR are signed (git commit -s).
  • The reason for this PR is clearly provided (issue no. or explanation).
  • The description of changes is clear and encompassing.
  • Any required documentation changes (code and docs) are included in this PR.
  • Any newly added unsafe code is properly documented.
  • Any API changes are reflected in firecracker/swagger.yaml.
  • Any user-facing changes are mentioned in CHANGELOG.md.


let restored_state: TestCompatibility =
bincode::deserialize_from(snapshot_mem.as_slice()).unwrap();
assert_eq!(test_struct._string, restored_state._string);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it possible to derive PartialEq for TestCompatibility so we can have a single statement like assert_eq!(test_struct, restored_state);?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Having an expanded assertion simplifies debugging by showing which primitive is broken.

Copy link

Choose a reason for hiding this comment

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

nit: I like the PartialEq solution better too; if something's broken, someone will look into it and figure it out eventually.

Copy link
Contributor Author

@sandreim sandreim Mar 30, 2020

Choose a reason for hiding this comment

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

After more thought on this I've also convinced myself:)

}

#[derive(Debug, serde_derive::Deserialize, serde_derive::Serialize, Versionize)]
struct TestCompatibility {
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess we can also at least add u128, i128, a tuple, and a tuple struct.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Those are not yet implemented. i128 does not seem to be needed right away. I will add an issue for tuple.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

let v: Vec<#array_type_token> = <Vec<#array_type_token> as Versionize>::deserialize(&mut reader, version_map, app_version)?;
vec_to_arr_func!(transform_vec, #array_type_token, #array_len);
transform_vec(v)
let mut array = [#array_type_token::default() ; #array_len];
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we should rely on the assumption that array members always implement Default even though the alternatives are more verbose/complex :( One option coming to mind is to rely on macros somewhere (i.e. the primitives file) to implement Versionize for [T; 0] to [T; 32] (which seems to be standard practice when adding trait implementation for arrays, since Rust doesn't accept generics in terms of numerical values). I think the same applies to tuples, up to a certain cardinality.

Copy link
Contributor Author

@sandreim sandreim Mar 27, 2020

Choose a reason for hiding this comment

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

I am fine with the current limitation (Default trait) and the simple implementation as it handles any array size without having to generate impls for Versionize for [T; 0] to [T; 32].

I'll try someting when I implement tuples.

Copy link
Contributor

Choose a reason for hiding this comment

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

Cool, maybe we can mention this in the issue you referenced before as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

alxiord
alxiord previously approved these changes Mar 30, 2020

let restored_state: TestCompatibility =
bincode::deserialize_from(snapshot_mem.as_slice()).unwrap();
assert_eq!(test_struct._string, restored_state._string);
Copy link

Choose a reason for hiding this comment

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

nit: I like the PartialEq solution better too; if something's broken, someone will look into it and figure it out eventually.

@sandreim
Copy link
Contributor Author

@aghecenco @alexandruag I've updated the PR please take a look.

alxiord
alxiord previously approved these changes Mar 30, 2020
- Implemented VersionizeResult.
- Split versionize::Error into snapshot::Error and versionize:Error
- Implement bincode compatible array serialization.
- Add test for bincode compatibility.

Signed-off-by: Andrei Sandu <[email protected]>
@sandreim sandreim merged commit ebc472c into firecracker-microvm:master Mar 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants