Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Disable annotations when using Legacy Encoding #1035

Merged
merged 4 commits into from
Jun 11, 2024

Conversation

dcookspi
Copy link
Collaborator

@dcookspi dcookspi commented Jun 6, 2024

This is an attempt to tighten up the legacy encoding and annotations interaction to make annotations only supported when using the flatbuffers setting. We hit a snag when trying to release a new spk build with annotations and the legacy setting. This is an attempt to make things safer and clearer while we transition.

This stops spk adding annotations when spfs is not using the flatbuffers. When flatfbuffers encoding is enabled, spk will still add an annotation to the spfs runtimes it makes.

It separates the digest and encoding usage of legacy_encode() methods on spfs graph objects by using two methods: legacy_encode() and digest_encode(). Other than their name and what calls them, the methods are virtually identical. The exception is the Layer object's legacy_encode(), which ignores any annotation data. The Layer's digest_encode() does write annotations data so it is counted in the hashing.

Questions:

  • I didn't change/rename the size_for_legacy_encode() methods. I wasn't sure of the ramifications. The duplication and rename above should make it easier to remove the legacy_* code in future. But what, if anything, to do with this one?

dcookspi added 2 commits June 6, 2024 09:31
…rs encoding format.

When flatfilebuffers encoding is enabled, spk will add an annotation to the spfs runtimes it make.

Signed-off-by: David Gilligan-Cook <dcook@imageworks.com>
…wo methods

Add digest_encoding method to spfs graph objects. Removed annotation writing from Layer's legacy_encoding, but not its digest_encoding.

size_for_legacy_encoding methods remain unchanged.

Signed-off-by: David Gilligan-Cook <dcook@imageworks.com>
@dcookspi dcookspi self-assigned this Jun 6, 2024
@dcookspi dcookspi requested review from rydrman and jrray June 6, 2024 21:34
@dcookspi dcookspi changed the title Disable annotations when not using FlatBuffers Disable annotations when using Legacy Encoding Jun 7, 2024
Copy link
Collaborator

@rydrman rydrman left a comment

Choose a reason for hiding this comment

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

I'm a little lost on this one, can you talk about the specific snag that you are running into. I might be over thinking things, but it feels there should never be a need to separate these, or if we do it will cause bugs. If the encoding used for digests is not the same as the encoding used for writing to disk, then something like a server interaction will create fail as the stored data might be saved on the other end using flatbuffers and end up with a different digest than what was expected by the hierachy that's being pushed.

crates/spfs/src/graph/layer.rs Outdated Show resolved Hide resolved
@jrray
Copy link
Collaborator

jrray commented Jun 8, 2024

FYI the current state of the main branch is completely broken when using legacy encoding. spk env adds an annotation-only layer to the runtime and the current legacy_encode writes an invalid object to disk1. legacy_decode does not know how to read this file, or it is impossible to correctly read this file because there's nothing in the format to say it doesn't have a manifest digest in it.

We would like to make changes to the code to work towards not having "legacy" in the names of methods that are still in common use. We think it is a poor design decision for the flatbuffers encoding to call "legacy" methods.

Also, any "legacy" methods should capture the behavior at the time of pre-flatbuffers so we can ensure that we continue to maintain compatibility with pre-flatbuffers going forward. In the current code design, if we put more fields into the flatbuffers schema we have to also add new code to the "legacy" methods to match.

It should be an error to attempt to serialize to disk an object when using legacy encoding that makes use of fields that were added in the post-flatbuffers world.

Footnotes

  1. the annotation data ends up in the part of the file that is expected to contain the manifest digest, making legacy_decode read it in as a layer with a bogus manifest digest and spk env fails with unknown object.

@dcookspi
Copy link
Collaborator Author

dcookspi commented Jun 10, 2024

I'll change the legecy_encode() method for Layer to error if there is annotation data, rather than just not writing it.

  • Change Layer::legacy_encode() to error if there is annotation data.

dcookspi and others added 2 commits June 10, 2024 10:27
Co-authored-by: Ryan Bottriell <ryan@bottriell.ca>

Signed-off-by: David Gilligan-Cook <dcook@imageworks.com>
…tion data

Signed-off-by: David Gilligan-Cook <dcook@imageworks.com>
@dcookspi dcookspi force-pushed the disable-annotations-when-not-using-ffb branch from 300a48a to c36eab4 Compare June 10, 2024 17:55
@dcookspi dcookspi requested a review from rydrman June 10, 2024 18:10
@dcookspi dcookspi added SPI AOI Area of interest for SPI SPI-0.41 bug Something isn't working labels Jun 10, 2024
@rydrman
Copy link
Collaborator

rydrman commented Jun 11, 2024

We would like to make changes to the code to work towards not having "legacy" in the names of methods that are still in common use. We think it is a poor design decision for the flatbuffers encoding to call "legacy" methods.

Also, any "legacy" methods should capture the behavior at the time of pre-flatbuffers so we can ensure that we continue to maintain compatibility with pre-flatbuffers going forward. In the current code design, if we put more fields into the flatbuffers schema we have to also add new code to the "legacy" methods to match.

I agree with this, and it was my intention, but things got a little muddled with the flatbuffer and extra data stuff all happening and going in at the same time. We should have caught this case of new logic going into legacy methods during the merge but it slipped through... In any case, this change feels like where we want things to be

@dcookspi dcookspi merged commit 9892a89 into main Jun 11, 2024
7 checks passed
@dcookspi dcookspi deleted the disable-annotations-when-not-using-ffb branch June 11, 2024 17:41
pub(super) fn legacy_encode(&self, writer: &mut impl std::io::Write) -> Result<()> {
// Legacy encoded layers do not support writing annotations
if !self.annotations().is_empty() {
return Err(Error::String(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Although we do want this to error in this situation, the test suite now fails on a number of tests if the default encoding is switched to legacy (as we have done in our internal build). For example: test_layer_encoding_annotation_only.

It would be best if we had tests that test both encoding formats but it isn't clear how we would accomplish this in the current code design, since it relies on one of the formats being marked as default.

Copy link
Collaborator

@jrray jrray Jun 17, 2024

Choose a reason for hiding this comment

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

Okay, I found HeaderBuilder and am doing some experiments...

Copy link
Collaborator

Choose a reason for hiding this comment

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

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working SPI AOI Area of interest for SPI SPI-0.41
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants