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

Exploration: wasi-keyvalue #2486

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft

Conversation

itowlson
Copy link
Contributor

@itowlson itowlson commented May 3, 2024

An exploratory PR for exploring, apropos of #2447.

@itowlson
Copy link
Contributor Author

itowlson commented May 3, 2024

I had to add the wasi-keyvalue import to the old world to get the runtime test to compile. I assume in practice that's not what we'd aim to do though, we'd instead create a new world version and expose it only through that?

@itowlson
Copy link
Contributor Author

itowlson commented May 5, 2024

Do folks have any insights on how to move this forward? It seems to work but I am not quite sure what do about the worlds stuff:

  1. Should this create a rev of the Spin world?
  2. The runtime tests appear use an old world: is there plumbing to let them use a current world?

@itowlson itowlson linked an issue May 6, 2024 that may be closed by this pull request
@itowlson itowlson requested review from dicej and lann May 9, 2024 00:17
@itowlson
Copy link
Contributor Author

@dicej @lann There is a request to move this forward for the impending release or the one after. Are you the right folks to review, or should I pester someone else?

@dicej
Copy link
Contributor

dicej commented Jun 10, 2024

Yup, I can take a look tomorrow morning.

@dicej
Copy link
Contributor

dicej commented Jun 10, 2024

@kate-goldenring might also be interested, given her recent work on the specification.

async fn open(
&mut self,
identifier: String,
) -> anyhow::Result<Result<Resource<wasi_keyvalue::store::Bucket>, wasi_keyvalue::store::Error>>
Copy link
Collaborator

Choose a reason for hiding this comment

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

You can use the trappable_error_type option to make the signatures here a bit easier to work with. See the llm implementation for an example use.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @rylev. I gave this a try and am not sure how I feel about. I've left it in a separate commit and would value your thoughts...

) -> anyhow::Result<Result<wasi_keyvalue::store::KeyResponse, wasi_keyvalue::store::Error>>
{
if cursor.unwrap_or_default() != 0 {
anyhow::bail!("list_keys: cursor not supported");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is the plan to eventually support the cursor?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

"Plan" is a strong word but, yes, it would be desirable to do on back-ends that support it. For this initial implementation I stuck to using the existing KV implementation which unfortunately do not support cursors.

@@ -16,6 +16,7 @@ world http-trigger-rc20231018 {
world platform {
include wasi:cli/imports@0.2.0;
import wasi:http/outgoing-handler@0.2.0;
import wasi:keyvalue/store@0.2.0-draft;
Copy link
Collaborator

Choose a reason for hiding this comment

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

We definitely need to decide how we want to handle introducing new imports. This will break any Spin runtime that does not have wasi:keyvalue support.

Copy link
Collaborator

Choose a reason for hiding this comment

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

It seems like we should be bumping the WIT package version here right? This is still a little scary as we haven't even done it with WASI 0.2.1 yet...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, this was one of my questions: #2486 (comment). Do we need a separate conversation about how to do this?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we need a separate conversation about how to do this?

Probably? I'm not sure that anyone knows how best to handle this yet.

Copy link
Contributor

@dicej dicej left a comment

Choose a reason for hiding this comment

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

LGTM overall -- thanks for doing this!

I expect we'll need to implement cursors before we can really claim to support wasi:keyvalue/store, and that may be the most interesting part of this project given the variety of backends we now support (SQLite, Redis, and Azure).

@@ -30,6 +31,7 @@ world platform {
world platform-rc20231018 {
include wasi:cli/reactor@0.2.0-rc-2023-10-18;
import wasi:http/outgoing-handler@0.2.0-rc-2023-10-18;
import wasi:keyvalue/store@0.2.0-draft;
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd recommend not adding anything new to platform-rc20231018 -- it's only really here for backwards compatibility. In hindsight, I think we probably shouldn't have added mqtt either.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree! The trouble is that the tests all (currently) use this world, so if we want tests for wasi-keyvalue then we will need to rev the test world, and I'm not sure of the implications of that. #2486 (comment)

Copy link
Contributor

@kate-goldenring kate-goldenring left a comment

Choose a reason for hiding this comment

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

LGTM. @itowlson should we mark this as ready to review?

wit/deps/keyvalue-2024-05-03/world.wit Show resolved Hide resolved
@itowlson
Copy link
Contributor Author

@kate-goldenring I was planning to leave it as draft until we have a decision on WIT versioning. I can mark ready for review and label "do not merge" if that would be better?

@kate-goldenring
Copy link
Contributor

I was planning to leave it as draft until we have a decision on WIT versioning. I can mark ready for review and label "do not merge" if that would be better?

@itowlson leaving as is is fine. Thanks for clarifying the decision criteria.

Signed-off-by: itowlson <ivan.towlson@fermyon.com>
Signed-off-by: itowlson <ivan.towlson@fermyon.com>
Signed-off-by: itowlson <ivan.towlson@fermyon.com>
@radu-matei
Copy link
Member

Just to validate an assumption I had reading this PR: this PR adds support for the WASI KV proposal — specifically, it allows guests to use the proposal to interact with stores — and stores are still managed through the manifest key_value_stores field. Is that accurate?

Thanks!

@itowlson
Copy link
Contributor Author

@radu-matei Yes. The KV stores are the exact same KV stores as you would get if you used the Spin APIs, specified and configured in exactly the same way.

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 wasi-keyvalue
6 participants