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

Change Layer interface from &self to &mut self #669

Merged
merged 4 commits into from
Jan 30, 2024

Conversation

schneems
Copy link
Contributor

@schneems schneems commented Sep 7, 2023

The primary driver for wanting to mutate a layer is a desire for stateful logging. I hit this in the consuming state-machine interface, and previously, Josh hit it in a logging interface designed to track indentation level.

Upside:

  • Developers are now allowed to do whatever they want within a layer
  • It's more technically correct to require a single reference for these functions. With the prior interface, it would be theoretically possible to execute the same Layer in parallel (though unlikely)
  • We can now change things between function calls.

Downside:

  • Mutable self means there's no guarantee something didn't change between function calls.

@schneems
Copy link
Contributor Author

Here's a working PoC of a theoretical get/set based layer API heroku/buildpacks-ruby#203

@schneems schneems closed this Nov 13, 2023
@schneems schneems reopened this Jan 26, 2024
@schneems schneems force-pushed the schneems/spike-mut-layer branch 2 times, most recently from 6a42587 to 18aeaaa Compare January 27, 2024 01:38
The primary driver for wanting to mutate a layer is a desire for stateful logging. I hit this in the consuming state-machine interface, and previously, Josh hit it in a logging interface designed to track indentation level.

Upside:

- Developers are now allowed to do whatever they want within a layer
- It's more technically correct to require a single reference for these functions. With the prior interface, it would be theoretically possible to execute the same Layer in parallel (though unlikely)
- We can now change things between function calls.

Downside:

- Mutable self means there's no guarantee something didn't change between function calls.
@schneems schneems marked this pull request as ready for review January 27, 2024 01:40
@schneems schneems requested a review from a team as a code owner January 27, 2024 01:40
Copy link
Member

@Malax Malax left a comment

Choose a reason for hiding this comment

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

Heya, thanks for re-suggesting this! Good to see that the change would just work without a more complex refactoring. Bottom line, I think we should make this change.

What I would like to see is a way to get the value passed to handle_layer back out, or allowing to pass a mutable reference to handle_layer. With the change in this PR, we can modify, but code outside of the layer will never be able to see what changed. When we think about the buildpack output, it would be cool to be able to get the current output state back out. This could be a separate PR or part of this one - I think the changes are closely related.

With the prior interface, it would be theoretically possible to execute the same Layer in parallel (though unlikely)

Since you needed to pass handle_layer an owned value, this would've not been possible. I also don't think that that would be a problem. The value implementing Layer is a description of a layer state and how to get there - it's not the layer itself. This is why the layer name is not part of the Layer trait. However, this is not really relevant to the change in this PR.

Mutable self means there's no guarantee something didn't change between function calls.

True, but all modifications would come from either the handle_layer implementation or the functions defined in Layer. This softens up the issue a lot for me. If you want to modify in your Layer implementation you have to work with that in the same layer - the issue is contained.

CHANGELOG.md Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
@edmorley edmorley enabled auto-merge (squash) January 30, 2024 07:42
@edmorley edmorley merged commit 7dfa3f3 into main Jan 30, 2024
4 checks passed
@edmorley edmorley deleted the schneems/spike-mut-layer branch January 30, 2024 07:44
schneems added a commit to heroku/buildpacks-ruby that referenced this pull request May 15, 2024
* Bump the libcnb group across 1 directory with 3 updates

Bumps the libcnb group with 3 updates in the / directory: [libcnb](https://github.com/heroku/libcnb.rs), [libherokubuildpack](https://github.com/heroku/libcnb.rs) and [libcnb-test](https://github.com/heroku/libcnb.rs).


Updates `libcnb` from 0.17.0 to 0.19.0
- [Release notes](https://github.com/heroku/libcnb.rs/releases)
- [Changelog](https://github.com/heroku/libcnb.rs/blob/main/CHANGELOG.md)
- [Commits](heroku/libcnb.rs@v0.17.0...v0.19.0)

Updates `libherokubuildpack` from 0.17.0 to 0.21.0
- [Release notes](https://github.com/heroku/libcnb.rs/releases)
- [Changelog](https://github.com/heroku/libcnb.rs/blob/main/CHANGELOG.md)
- [Commits](heroku/libcnb.rs@v0.17.0...v0.21.0)

Updates `libcnb-test` from 0.17.0 to 0.19.0
- [Release notes](https://github.com/heroku/libcnb.rs/releases)
- [Changelog](https://github.com/heroku/libcnb.rs/blob/main/CHANGELOG.md)
- [Commits](heroku/libcnb.rs@v0.17.0...v0.19.0)

---
updated-dependencies:
- dependency-name: libcnb
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: libcnb
- dependency-name: libherokubuildpack
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: libcnb
- dependency-name: libcnb-test
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: libcnb
...

Signed-off-by: dependabot[bot] <support@github.com>

* Change to mutable layers

The layer trait interface was changed to mutable in heroku/libcnb.rs#669

* Switch from stacks to targets AKA "Stay on target"

Buildpack API 0.10 removed the concept of stacks in favor of targets heroku/libcnb.rs#773.

This commit works to upgrade applications in place by migrating metadata to support the new serialization format. This is supported by implementing TryMigrate from the `magic_migrate` crate https://docs.rs/magic_migrate/latest/magic_migrate/macro.try_migrate_link.html.

https://www.youtube.com/watch?v=NnP5iDKwuwk

* Add explicit Distro/Architecture cache messages

* Use updated magic_migrate macros

* Apply suggestions from code review

Co-authored-by: Ed Morley <501702+edmorley@users.noreply.github.com>

* Document breaking changes

* Align warning messages and error names

* Update buildpack.toml

- Add explanation for when stacks can be removed
- Move "targets" closer to "stacks" as they're logically tied together.

* Integration test for metadata migration

* Support heroku-20 and heroku-22 (only)

This buildpack does not support heroku-24 (yet) remove this stack from the TargetId struct. It also supports heroku-20 which was previously not present.

* Fix changelog

* Standardize println in integration tests

* Consistent cache clear messages

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Ed Morley <501702+edmorley@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants