Skip to content

extend persistence api#7713

Merged
thrau merged 4 commits intomasterfrom
persistence-api
Feb 20, 2023
Merged

extend persistence api#7713
thrau merged 4 commits intomasterfrom
persistence-api

Conversation

@thrau
Copy link
Member

@thrau thrau commented Feb 19, 2023

This PR extends the persistence API to prepare localstack core for the persistence extension.

Most noteworthy, the PR adds a wrapper around pickle/dill, and exposes a similar API that is composable and extensible.

  • Visitors in the persistence extensions use Encoder and Decoder instances (they give more flexibility and decouple higher-level logic like visitors from pickle), but PickleEncoder and PickleDecoder by default
  • If you're lazy and you don't want to use encoders, you can also just use from localstack.state import pickle; pickle.dump(...)
  • Wraps the global reducer function dispatch table in dill (dill.Pickler.dispatch) with a mechanism that can also match subclasses (apply certain reducers for all subclasses rather than just the specific type)
  • A plugin interface for the snapshot-based persistence mechanism that allows one to plug in custom visitors for save and load operations

pickle.dumps can now be used in the store police, as it will be extended dynamically with custom serializers by the persistence plugin, and the underlying system is used for both pods and snapshot persistence.

@thrau thrau temporarily deployed to localstack-ext-tests February 19, 2023 06:37 — with GitHub Actions Inactive
@thrau thrau requested review from giograno and whummer February 19, 2023 06:37
@github-actions
Copy link

github-actions bot commented Feb 19, 2023

LocalStack integration with Pro

       3 files  ±0         3 suites  ±0   1h 34m 7s ⏱️ - 1m 51s
1 731 tests ±0  1 382 ✔️ ±0  349 💤 ±0  0 ±0 
2 449 runs  ±0  1 758 ✔️ ±0  691 💤 ±0  0 ±0 

Results for commit 0d34694. ± Comparison against base commit 35c267b.

♻️ This comment has been updated with latest results.

@coveralls
Copy link

coveralls commented Feb 19, 2023

Coverage Status

Coverage: 85.008% (-0.009%) from 85.017% when pulling 0d34694 on persistence-api into 35c267b on master.

@thrau thrau temporarily deployed to localstack-ext-tests February 19, 2023 15:44 — with GitHub Actions Inactive
@thrau thrau temporarily deployed to localstack-ext-tests February 19, 2023 15:50 — with GitHub Actions Inactive
@thrau thrau temporarily deployed to localstack-ext-tests February 19, 2023 18:51 — with GitHub Actions Inactive
Copy link
Member

@whummer whummer left a comment

Choose a reason for hiding this comment

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

Awesome set of changes @thrau ! 🚀 This gives us a nice flexibility to keep the generic API in this repo, and extend it elsewhere with plugins (via SnapshotPersistencePlugin, and the visitor pattern).

Was initially thinking whether introducing our own pickle module (with the same convenience functions pickle.loads, pickle.dumps etc) could cause some confusion if users are expecting to be interacting with the built-in pickle library. But then my second reaction was that it actually can be beneficial - this way we make it more explicit that our custom mechanism is being used. (It's also not uncommon to see things like import dill as pickle, which would be a similar drop-in replacement as we're defining here.) 👌 I guess we only need to ensure that we communicate to devs that raw pickle should never be used directly (which should not be the case anyway, as the core logic is encapsulated in the core runtime).

Love the direction this is taking - can't wait to see it in action! 🥳 🚀

@thrau thrau temporarily deployed to localstack-ext-tests February 20, 2023 10:23 — with GitHub Actions Inactive
@thrau thrau merged commit 9271474 into master Feb 20, 2023
@thrau thrau deleted the persistence-api branch February 20, 2023 15:16
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.

3 participants